Está en la página 1de 59

MapServer

TallerdeSistemasdeInformacinGeogrfica MapServer

Objetivos

Laideaesrepasarherramientasexitosasde productosopensourceorientadosaGIS, empleadosenmbitoscomerciales, gubernamentalesyacadmicos.

http://freegis.org http://opensourcegis.org http://maptools.org

Unadelasprincipalesventajasdeemplear estasherramientasopensourceesqueson compatiblesconlosprincipalesformatosde softwareGISpropietario.

RasteryVector

Ambostrminosserefierenatiposespecficos dedatos.

LosdatosRastersonorganizadoscomounamatrizo grillaquetienefilasycolumnas. Cadainterseccinentrefila/columnaesunaceldao pixel. Cadaceldatieneunvalor,porejemplo,unaelevacin. Tienenunnmerodeterminadodepixelsdeanchoy altoycadapixelrepresentaundeterminadotamao. Porejemplo,enimgenesLandsat,cadapixel representa30x30metros.

RasteryVector

LosVectoressonrepresentadoscomo coordenadas

definenpuntoso secombinanparaconformarlneasopolgonos. Estosdatosamenudoserelacionanconunatabla deinformacin,unaparacadacaracterstica(lnea, puntoopolgono)delconjunto

OpenEV

EsunpotentevisordeEscritorio.Permite explorarlosdatosdecualquiertipode imgenes(rasterovector)soportadasporla librera(GDAL/OGR). OpenEVprovieneconelpaqueteFWTools: http://fwtools.maptools.org http://openev.sourceforge.net/ Esunbuenejemplodecmopueden accedersealasfuncionesdeGDAL/OGR empleandootroslenguajesyaqueestescrito sobrePhyton

OpenEV

MapServer

Eslaprincipalherramientaqueemplearemos parapresentarnuestrosmapasenlaWeb. LapginaoficialdeMapServeres: http://mapserver.gis.umn.edu

MapServerVentajas

Ofrecelaposibilidaddepresentarlosdatosaotros usuariosempleandoInternet Esunodelospocosproductosqueofrecensoluciones alosproyectosquedisponendemapasenmltiples formatos.

GDAL/OGR GDAL/OGR PostGIS

AccesoadatosyPerformance

Portabilidad $0.00

GDAL

GeospatialDataAbstracionLibrary EspartedelpaqueteFWTools. AmenudollamadaGoodle Unalibreraparaformatosdedatos geoespacialesraster.Presentaunnico modelodedatosabstractoparalaaplicacin quellamaparatodoslosformatossoportados.

GDAL

Tienecuatrocaractersticasprincipales:

Variedad:Soportamasde40formatosraster Abstraccin:Cualquieraplicacinqueemplee GDALaccedeautomticamenteaesos40formatos Herramientas:Lasherramientasqueemplean GDALposiblementeahorrenesfuerzosde programacin. Funciones:Susfuncionespuedenserempleadas porprogramadoresdedistintoslenguajes:C,C++, Phyton.Paraotroslenguajes,puedeemplearse SWIG(Perl,Java,PHP,Ruby,etc.)

GDAL

Enresumen:Nohayquepreocuparsedel formatodeunaimagenparapoderanalizarlay emplearla.

GDALUtilidades

LasutilidadesGDALsobreWindowsque provienenconelpaqueteFWTools Seaccedealasmismasempleandoel intrpretedecomandosquevieneconel paquete. gdal_translate:Permitepasardeunformatoa otro.Proveefuncionespararedimensaionar, extraersubconjuntosdedatos,etc.

GDALUtilidades

gdalinfo:Nosbrindainformacinacercadel archivodelaimagenraster

#gdalinfovancouver.tif Driver:GTiff/GeoTIFF Sizeis1236,1028 CoordinateSystemis: PROJCS["NAD83/UTMzone10N", GEOGCS["NAD83", DATUM["North_American_Datum_1983", SPHEROID["GRS1980",6378137,298.2572221010042, AUTHORITY["EPSG","7019"]], AUTHORITY["EPSG","6269"]], PRIMEM["Greenwich",0], UNIT["degree(suppliertodefinerepresentation)",0.01745329251994328],

AUTHORITY["EPSG","4269"]], PROJECTION["Transverse_Mercator"] ........................

OGR

Esunalibreraopensourceparael procesamientodedatosvectoriales. GDALseempleaparavisualizardatosrastero imgenesyOGRparalosvectoriales.

OGRUtilidades

ogrinfo ogr2ogr

PostGIS

PostgreSQL:unmotordebasededatos empresarialespotente,gratuitoyopensource. ExtiendePostgreSQL,permitiendoalmacenar ymanipulartiposdedatosgeogrficos,como cualquierdatotabular. LasfuncionesmasavanzadasdePostGISse basanenunconjuntodelibreras(GEOS), GeometryEngineOpenSource(refractions research)

PostGIS

Permitemanipularlosdatosdirectamenteenla BD,empleandoSQL Consulta:

SeleccionarlospaseslimtrofesaArgentina SQL:
SELECTnombre_de_pais frompaisa,paisb whereb.nombre='Argentina' anda.wkb_geometry&&b.wkb_geometry

MapServerFuncionamiento

Porlogeneral,MapServertrabajadetrsdeun WebServer.

ElServidorWebrecibelassolicitudesdemapasy lasderivaaMapserverparasucreacin. MapServergeneraelmapayseloretornaal servidorWebquienasuvezlotrasladaalusuario.

MapServer

LafuncinprincipaldeMapServerinvolucra leerdatosdedistintasfuentesycombinarestas capas(LAYERS)enunarchivogrfico,tambin conocidacomoimagendelmapa. Unacapapuedeserunaimagensatelital,otra unvectorconloslmitesdelospaises,otraslos puntosconlasprincipalesciudades. Cadacapasedibujayessuperpuestasobre lasotras.

MapServer

MapServer

Enlafiguraanteriorsemuestraunejemplode superposicindecapas. Cadaunodeloscheckboxseleccionados representaunacapaqueessolicitadaa MapServerparaqueseapresentadaenla imagendelaizquierda. Cadacapaestomadadesdeunorigen independiente(tambinpuedeserelmismo). Elprocesoderenderingserealizacadavez quesesolicitaunnuevomapaaMapServer.

MapServer

Ennuestrocaso,elredibujadoseproduce cuandoelusuariocambialascapasavisualizar obienrealizaunzoomin/outodesplazamiento

MapServer

Unodeloscomponentesprincipalesesel programaCGI,elcual,luegodecadasolicitud deunamapa,dibujalainformacindesdelos datasourcesyretornalaimagen correspondiente.

MapServer

ElprogramaCGIdeMapServer,actuacomo intermediarioentrequiensolicitalaimageny losmapasquelaconforman. Lassolicitudessepasandelaformade parmetrosdesdeelservidorWeba MapServer

MapServerMapfile

Bsicamenteesunarchivodeconfiguracinde textoqueenumeralaformadedibujare interactuarconelmapa. Incluyequecapasdebendibujarse,elsistema deproyeccin,elformatodeimagendesalida, siseempleanleyendas,barrasdeescala,etc. Cuandoserealizaunasolicitudauna aplicacinMapServer,debeespecificarseque archivodemappingdebeemplearseparaque aspuedaconstruirelmapa.

MapServerMapfile
MAP SIZE600300 EXTENT1809018090 LAYER NAMEcountries TYPEPOLYGON STATUSDEFAULT DATAcountries.shp CLASS OUTLINECOLOR100100100 END END END

MapServerDatasource

Representaranelcombustibledelmotor. Bsicamentedefinededondesetomanlos datos. Puedenprovenirdeunadiversidaddefuentes:

soportadosenformanativaporMapServer soportadospormediodelibrerasGDAL/OGR pormediodeunWebService.

MapServerInstalacin

Windows Linux

Repositorios Compilado

LinuxCompilado

Compilamostodaslalibreriasrequeridas.

Generalmente(dependedecadalibreria)

./configure make makeinstall

Unavezcompiladaslaslibrerias:

DirectoriosourcedeMapServer ./configure make

Segenerarelarchivoejecutablemapserv

LinuxCompilado
Algunasopcionesdecompilacin:
./configure \ --with-proj=/usr/local/proj-4.6.0 \ --with-geos=/usr/local/bin/geos-config \ --with-ogr=/usr/local/bin/gdal-config \ --with-gdal=/usr/local/bin/gdal-config \ --with-postgis=/usr/local/pgsql/bin/pg_config \ --with-curl-config=/usr/bin/curl-config \ --with-httpd=/usr/sbin/httpd \ --with-php=/usr/include/php \ --with-wfs \ --with-wfsclient \ --with-wmsclient \ --enable-debug \ --with-threads \ --with-wcs \ --with-wcsclient \ --with-sos \ --with-gd \ --with-freetype \ --with-jpeg \ --with-agg=/usr/local/

LinuxUbuntuRepositorio

Actualizamoslasfuentes

Esposiblequetengamosqueeditar/etc/apt/sources.list aptgetupdate

Buscamoslospaquetesdemapserver

aptcachesearchmapserver Nosdevuelveunalistaconlospaquetesquecontienenel texto:mapserver

InstalamoslospaquetesdeMapServer

aptgetinstallcgimapservermapserverbinphp5 mapscript
Pordefectoseinstalaen/usr/lib/cgibin

LinuxCompilacinvs Repositorio

Repositorios

Enlosrepositoriosnormalmentenoseencuentran disponibleslasltimasversionesdelos componentes. Puestaenmarchadeservidorrpida. Prestacionesnotanelevadas. Disponiblesltimasversiones. Lacompilacines+compleja,y+lenta. Mayorproductividadyprestaciones.

Compilacin

MS4WWindows

PaqueteMS4W,disponibleen:

http://www.maptools.org MapServerFor(4)Windows
ApacheHTTPServerversion2.2.10 PHPversion5.2.6 MapServerCGI5.2.1 MapScript5.2.1(CSharp,Java,PHP,Python) GDAL/OGR1.6.0RC2andUtilities MapServerUtilities PROJUtilities OGR/PHPExtension1.0.0

Contiene

MS4W

UnavezdescargadoelarchivodeMS4W

Descomprimirelcontenidoeneldirectorioraiz,por ejemploc:\.Pasaremosatenerc:\ms4wconel contenidocompleto IniciarMS4WApacheWebServermediante

/ms4w/apacheinstall.bat SeinstalaApachecomounserviciodeWindowsllamado "ApacheWebServer" SiseejecutaenunaconsolaDOSseobtieneelsiguiente mensaje:


InstallingtheApacheMS4WWebServerservice TheApacheMS4WWebServerserviceissuccessfullyinstalled. Testinghttpd.conf.... Errorsreportedheremustbecorrectedbeforetheservice canbestarted. TheApacheMS4WWebServerserviceisstarting. TheApacheMS4WWebServerservicewasstartedsuccessfully.

MS4W

http://localhost/

MS4W

http://localhost/cgibin/mapserv.exe

MS4WHerramientas

Ejecutardesdelneadecomando

c:\ms4w\setenv.bat

MS4WAplicaciones

TrabajandolosMapas Ejemplo:Carpetaconarchivos.SHPdeESRI Herramientas:

OGR

ogrinfo ogr2ogr

MS4WAplicaciones

c:\ms4w\apps\lapampa

mapas\*.shp ogrinfosomapaspob0003a_Project

MS4WAplicaciones
INFO:Openof`mapas'usingdriver`ESRIShapefile'successful. Layername:pob0003a_Project Geometry:Point FeatureCount:7155 Extent:(3232375.578346,5570103.035091)(3772862.020105, 6127358.845214) LayerSRSWKT: PROJCS["Argentina_Zone_3", GEOGCS["GCS_Campo_Inchauspe", DATUM["Campo_Inchauspe", SPHEROID["International_1924",6378388.0,297.0]], PRIMEM["Greenwich",0.0], UNIT["Degree",0.0174532925199433]], PROJECTION["Transverse_Mercator"], PARAMETER["False_Easting",3500000.0], UNIT["Meter",1.0]] UNION:Real(11.0) NOMBRE:String(45.0) TIPO:String(50.0) PROVINCIA:String(60.0) DEPARTAMEN:String(40.0) HABITANTES:Real(11.0) PAIS:String(15.0) OBSERVACIO:String(50.0) HOJA:String(10.0)

MS4WAplicaciones

ogr2ogr:Lasprimerasconversiones

ogr2ogr

f"ESRIShapefile"mydata.shp PG:"host=myhostuser=myloginname dbname=mydbnamepassword=mypassword" "mytable" f"PostgreSQL"PG:"host=localhostuser=someuser dbname=somedbpassword=somepasswordport=5432" mydata.shp

ogr2ogr

MapServerPrimeraAplicacin

HolaMundo!!!!!

Si,noeslaexcepcin Pasosaseguir:

CrearelMapfile CrearelArchivodeInicializacinyelTemplateHTML robarlaaplicacion!

MapServerMapfile
NAMEHelloWorld SIZE400300 IMAGECOLOR249245186 IMAGETYPEPNG EXTENT1.001.001.001.00 WEB
TEMPLATE/var/www/htdocs/hello.html IMAGEPATH/var/www/htdocs/tmp/

IMAGEURL/tmp/

END

MapServerMapfile
LAYER STATUSdefault TYPEpoint FEATURE POINTS0,00,0END TEXTHelloWorld END CLASS STYLE COLOR25500 END LABEL TYPE bitmap END END END END

MapServerhello.html
<html> <head><title>HelloWorlddesdeMapServer</title></head> <body> <formmethod=POSTaction=/cgibin/mapserv.exe> <inputtype=submitvalue=Click/> <inputtype=hiddenname=map value=/var/www/htdocs/hello.map/> </form> <imgsrc=[img]width=400height=300border=0/> </body> </html>

MapServer

MapServer

ArchivosCreados(similares):

"/var/www/htdocs/tmp/Hello_World1100850527563 8.png" <imgsrc="/tmp/Hello_World11008505275638.png" width=400height=300border=0>

MapServerPrimerMapa

MapServerPrimerMapa

ArchivosSHPdeESRI

c:\ms4w\Apache\htdocs\mapdata\mapas c:\ms4w\Apache\htdocs\lapampa.html c:\ms4w\Apache\htdocs\mapdata\lapampa.map c:\ms4w\Apache\htdocs\map.html

HTML

Mapfile

Template

MapServerPrimerMapa
lapampa.html
<formname="formulario_mapa"method="get"action="mapa.html"> <inputtype="submit"value="Okparacomenzar"> <inputtype="hidden"name="program"value="/cgibin/mapserv.exe"> <inputtype="hidden"name="map" value="/ms4w/Apache/htdocs/mapdata/lapampa.map"> <inputtype="hidden"name="zoomsize"value="2"> <inputtype="hidden"name="layers"value="caminos"> <inputtype="hidden"name="layers"value="contorno"> <inputtype="hidden"name="layers"value="canales"> <inputtype="hidden"name="layers"value="alternativos"> <inputtype="hidden"name="root"value="/"> </form>

MapServerMapfile
NAME"lapampa" SIZE550413 TRANSPARENTon IMAGETYPEGIF SHAPEPATH"/ms4w/Apache/htdocs/mapdata/mapas" EXTENT3294313.8407065644021.9955383738758.5157166127290.490093

WEB TEMPLATE"../mapa.html" IMAGEPATH"/ms4w/apache/htdocs/tmp/" IMAGEURL"/tmp/" END

MapServerMapfile
SCALEBAR IMAGECOLOR255255255 LABEL COLOR000 SIZEsmall END POSITIONlr INTERVALS4 STATUSembed SIZE1504 STYLE0 UNITSkilometers TRANSPARENTon END LEGEND STATUSon IMAGECOLOR255255255 TRANSPARENTTRUE END

MapServerMapfile
REFERENCE IMAGE"../referencia.gif" SIZE200150 EXTENT3294313.8407065644021.9955383738758.5157166127290.490093 STATUSON COLOR111 OUTLINECOLOR25500 MINBOXSIZE5 MAXBOXSIZE100 MARKERSIZE8 MARKER'star' END

MapServerMapfile
LAYER NAME"contorno" DATA"lim0003a_Project" # CONNECTIONTYPEPOSTGIS # CONNECTION"dbname=pampauser=postgreshost=127.0.0.1port=5432" # DATA"the_geomfromcontorno" STATUSon TYPEline CLASS NAME"Contorno" STYLE COLOR1205020 END END END

MapServerInteraccin
ImagendeReferenciacon muestradeubicacin

Refrescoenla imagennode pgina

CapasSeleccionables concheckbox

MapServerScripting

CGIesunaalternativa

Permitelaelaboracinrpidadeaplicaciones Norequiereconocimientosdeprogramacindeun lenguajedeterminado MapScript

ExistenAlternativas

MapServerMapScript
Phyton
#custommapfile.py importmapscript map=mapscript.mapObj() map.name="CustomMap" map.setSize(600,300) map.setExtent(180.0,90.0,180.0,90.0) map.imagecolor.setRGB(180,180,250) map.units=mapscript.MS_DD #Setthewebobjectimageproperties map.web.imagepath="/srv/www/htdocs/tmp/" map.web.imageurl="/tmp/"

MapServerMapScript
Php
<?php $image_name="phpmshello",rand(0,999999)).".png"; $map=ms_newMapObj("/ms4w/Apache/htdocs/mapdata/hello.map"); $image=$map>draw(); $image>saveImage(""/ms4w/Apache/htdocs/tmp/".$image_name); ?>

FIN

ConceptosdeMapServer

Arquitectura Ventajas Herramientas Formatos Alternativas Ejemplos

También podría gustarte