You are on page 1of 6

Example 1.

1: Map with a Single Layer MapServer can create an image and dump it to a local directory or send it direct ly to the requesting web browser, as in this example. You can view it without th e need for an html page, just enter this URL: http://terrasip.gis.umn.edu/cgi-bi n/mapserv40?map=/data/projects/tutorial/example1-1.map&mode=map (Remember to rep lace "terrasip.gis.umn.edu" with your web server's name, i.e. "localhost"). This URL can be broken into three parts: the first part, http://terrasip.gis.umn.edu /cgi-bin/mapserv40?, calls the MapServer CGI program. If you invoke it as is you will get this familiar message: No query information to decode. QUERY_STRING is set, but empty. The next two parts are what make up the query string. The parameter "map=/data/p rojects/tutorial/example1-1.map" tells the MapServer CGI program (mapserv40) wha t mapfile to process/parse. The ampersand (&) character is used by CGI programs to separate the parameters being passed. So, the next parameter is "mode=map". T his tells "mapserv40" what to do with the output from the mapfile. In this case it tells "mapserv40" to dump the image directly to the web browser (the client), without first creating a temporary image on the server. The MapServer "mode" CG I variable takes values other than "map". For example if you use "mode=browse", MapServer will dump the image to a temporary directory on the server. The browse mode will not work now but we'll come back to it again later. This is what the mapfile looks like: MAP IMAGETYPE PNG EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 SIZE 400 300 SHAPEPATH "data" IMAGECOLOR 255 255 255 PROJECTION "proj=laea" "ellps=clrk66" "lat_0=45" "lon_0=-100" # # Alternatively, you can specify an EPSG code. # "init=epsg:2163" # END # Start of LAYER DEFINITIONS --------------------------------------------LAYER # States polygon layer begins here NAME states DATA states_ugl STATUS DEFAULT TYPE POLYGON PROJECTION "init=epsg:4269" END CLASS COLOR 232 232 232 OUTLINECOLOR 32 32 32 END END # States polygon layer ends here # End of LAYER DEFINITIONS ------------------------------END # end of map file/object According to the MapFile Reference page, the mapfile is MapServer's basic config

uration mechanism. The mapfile is made up of "objects" and each object can have keywords or other objects. It has a hierarchical structure such that some object s fall under other objects... on top of this hierarchy is the MAP object, all ot her objects belong to it. Then there are objects like the PROJECTION object whic h can belong to the MAP object or to the LAYER object (which in turn belongs to the MAP object). Each object begins with the object name and ends with "END". Let's break "example1-1.map" down by objects. Its structure looks like this: MAP | ----------------------| PROJECTION | LAYER | -------------

| | PROJECTION CLASS Let's look at the keywords (parameters) within the MAP object: IMAGETYPE The keyword IMAGETYPE is used to define which image format the MapServer CGI pro gram should use for output. In this case we are using indexed color PNG (similar to GIF). This could be GIF, if we compiled the GD library with GIF support, WBM P, or JPEG. We can also specify other output options (PDF, SWF, GeoTIFF) provide d that we compiled support for them and specify them with the OUTPUTFORMAT objec t. The OUTPUTFORMAT goes beyond the scope of this tutorial but you can find out more about by reading through documentations in the MapServer web site. EXTENT This parameter specifies the output extent of our map. This needs to be in the s ame units as the data or, if specifying a different output projection, in the sa me units as the output projection. In this case our output projection units are in meters. To get the values for the extent, you can use ArcView or other GIS so ftware. You can also use the utility "ogrinfo" which is part of the GDAL library . There are also other freely available GIS data viewers that might work. SIZE This is the size of the image (the map) that MapServer will generate, in pixels. So our map is 400 pixels wide by 300 pixels high. SHAPEPATH This is the path to your data layers. You can provide absolute paths (i.e. "/usr /projects/data" or "C:/projects/data") or paths relative to your mapfile's locat ion (as in the example). This path doesn't have to be web accessible. It has not hing directly to do with the web so don't even think of URLs here--just make sur e that the user running the web server (usually "nobody" in the *nix world) can READ the data in the SHAPEPATH. IMAGECOLOR This is the background color of your map. The values are RGB values so 255 Red, 255 Green, and 255B which results in a white background. Go ahead and play with this values. The PROJECTION object is required for this example but I will skip it until we c over enough of the basics. We will come back to it later in this section. Let's look at the LAYER object parameters: LAYER

Marks the beginning of a LAYER within the MAP object. You can specify as many la yers as you'd like although you are limited to 100, be default. To change this l imit, you will have to recompile MapServer. NAME This is the layer identifier. DATA The name of the data (shapefile in this case). MapServer supports vector data fo rmats other than ESRI's shapefile through the use of OGR library (part of the GD AL software package). Please visit the GDAL project web site at http://www.remot esensing.org/gdal/ and read http://www.remotesensing.org/gdal/ogr/index.html to know more about the different vector formats MapServer supports. TYPE What type of data is it? If it's a vector data, you can specify whether it is a POLYGON, LINE (you use LINE even if your data is technically a POLYLINE), or a P OINT. You can also specify RASTER or ANNOTATION data. Here we want to display PO LYGON. STATUS Layers are turned on or off based on their STATUS. DEFAULT is always on. ON or O FF works when the LAYER name is passed as part of the query string. Let's look at the CLASS object parameters: CLASS Marks the beginning of a CLASS object within the LAYER object. You can specify a s many classes within a layer although you are limited to 50 by default. You'll have to recompile MapServer to change this default value. COLOR This is the fill color of the polygon. In case the TYPE is LINE, this is the lin e color. The values are in RGB format. OUTLINECOLOR This is the outline color of the polygons. The values are in RGB format. This ends the first example in this tutorial. You are encouraged to change the v alues of the keywords in the mapfile. It will help you understand what these key words do.

Ejemplo 1.1: Mapa con una sola capa MapServer puede crear una imagen y lo descarga en un directorio local o enviarlo directamente al navegador solicitante, como en este ejemplo. Tambin se puede ver sin la necesidad de una pgina html, basta con introducir la siguiente URL: http: //terrasip.gis.umn.edu/cgi-bin/mapserv40?map=/data/projects/tutorial/example1-1. map&mode = mapa (Recuerda sustituir "terrasip.gis.umn.edu" con el nombre de su s ervidor web, es decir, "localhost"). Esta URL puede ser dividida en tres partes: la primera parte, http://terrasip.gis.umn.edu/cgi-bin/mapserv40, llama al progr ama CGI de MapServer. Si se invoca como es que usted recibe este mensaje familia r: No hay informacin de consulta para decodificar. QUERY_STRING est establecido, pero vaca.

Las siguientes dos partes son las que conforman la cadena de consulta. El parmetr o "map = / data/projects/tutorial/example1-1.map" le dice al programa CGI de Map Server (mapserv40) lo mapfile para procesar / analizar. El signo (&) se utiliza por los programas de CGI para separar los parmetros que se pasan. Por lo tanto, e l siguiente parmetro es el "modo = mapa". Esto le dice "mapserv40" qu hacer con la salida del archivo de asignaciones. En este caso se dice "mapserv40" para volca r la imagen directamente en el navegador (el cliente), sin crear primero una ima gen temporal en el servidor. El MapServer "modo" variable CGI toma valores disti ntos de "mapa". Por ejemplo, si se utiliza "mode = browse", MapServer se volcar l a imagen a un directorio temporal en el servidor. El modo de exploracin no va a f uncionar ahora, pero vamos a volver a ella ms tarde. Esto es lo que el archivo de asignaciones se ve as: MAPA ImageType PNG MEDIDA 201621.496941 1425518.020722 498254.511514 -294.488,285333 TAMAO 400 300 SHAPEPATH "datos" IMAGECOLOR 255 255 255 PROYECCIN "Proj = OIEA" "Ellps = clrk66" "Lat_0 = 45" "Lon_0 = -100" # # Tambin puede especificar un cdigo EPSG. # "Init = EPSG: 2163" # FIN # Inicio de definiciones de capas --------------------------------------------CAPA # capa de polgonos Estados comienza aqu Pronuncia el nombre DATOS states_ugl ESTADO DE DEFAULT Tipo de polgono PROYECCIN "Init = EPSG: 4269" FIN CLASE COLOR 232 232 232 OUTLINECOLOR 32 32 32 FIN END # capa de polgonos Estados termina aqu # Fin de definiciones de capas ------------------------------END # fin del archivo de mapa / object De acuerdo con la pgina de referencia Mapfile, el archivo de asignaciones es el m ecanismo de configuracin bsica MapServer. El archivo de mapa se compone de "objeto s" y cada objeto puede tener palabras clave u otros objetos. Tiene una estructur a jerrquica de tal manera que algunos de los objetos caen bajo otros objetos ... en la parte superior de esta jerarqua es el objeto del mapa, todos los dems objeto s pertenecen a la misma. Luego hay objetos como el objeto de proyeccin que puede pertenecer al objeto MAP o al objeto CAPA (que a su vez pertenece al objeto MAP) . Cada objeto se inicia con el nombre del objeto y termina con "END". Vamos a romper "ejemplo1-1.map" por los objetos. Su estructura se parece a esto: MAPA | -----------------------

| | PROYECCIN DE LA CAPA | ------------| | PROYECCIN DE LA CLASE Echemos un vistazo a las palabras clave (parmetros) en el objeto MAP: ImageType El ImageType palabra clave se utiliza para definir el formato de la imagen del p rograma CGI de MapServer debe utilizar para la salida. En este caso estamos usan do color indexado PNG (similar al GIF). Esto podra ser GIF, si hemos compilado la librera GD, con el apoyo del GIF, WBMP, o JPEG. Tambin puede especificar otras op ciones de salida (PDF, SWF, GeoTIFF), siempre que se compil el apoyo para ellos y especificar con el objeto OUTPUTFORMAT. El OUTPUTFORMAT va ms all del alcance de este tutorial, pero usted puede encontrar ms informacin acerca de la lectura a tra vs de documentacin en el sitio web de MapServer. MEDIDA Este parmetro especifica el grado de salida de nuestro mapa. Esto necesita estar en las mismas unidades que los datos o, si especificando una proyeccin de salida diferente, en las mismas unidades que la proyeccin de salida. En este caso, nuest ras unidades de proyeccin de salida estn en metros. Para obtener los valores de la medida, puede utilizar el software ArcView GIS o de otra ndole. Tambin puede util izar la utilidad "ogrinfo", que es parte de la biblioteca GDAL. Tambin hay otros visualizadores de SIG libre disponibilidad de datos que podran funcionar. TAMAO Este es el tamao de la imagen (el mapa) que MapServer generar, en pxeles. As que nue stro mapa es de 400 pxeles de ancho por 300 pxeles de alto. SHAPEPATH Este es el camino a las capas de datos. Usted puede proporcionar rutas de acceso absolutas (es decir, "/ usr / proyectos / datos" o "proyectos de C :/ / datos") o rutas de acceso en relacin con la ubicacin de su archivo de asignaciones (como en el ejemplo). Este camino no tiene que ser accesible en el sitio. No tiene nad a que ver directamente con la web as que ni siquiera pensar en las URL aqu - slo as egrese de que el usuario que ejecuta el servidor web (por lo general "nadie" en e l mundo * nix) puede leer los datos en el SHAPEPATH. IMAGECOLOR Este es el color de fondo del mapa. Los valores son valores RGB para 255 color r ojo, verde 255, y 255B que se traduce en un fondo blanco. Vaya por delante y jug ar con estos valores. El objeto de proyeccin se requiere para este ejemplo, pero lo voy a saltar hasta que cubra lo suficiente de los fundamentos. Vamos a volver a ella ms adelante en esta seccin. Echemos un vistazo a los parmetros de la capa de objetos: CAPA Marca el comienzo de una capa dentro del objeto MAP. Puede especificar tantas ca pas como desee, aunque est limitado a 100, ser por defecto. Para cambiar este lmite , usted tendr que volver a compilar MapServer. NOMBRE Este es el identificador de capa. DATOS

El nombre de los datos (shapefile en este caso). MapServer soporta los formatos de vectores de datos que no sean shapefile de ESRI a travs del uso de la bibliote ca OGR (parte del paquete de software GDAL). Por favor visite el sitio Web del p royecto GDAL en http://www.remotesensing.org/gdal/ y leer http://www.remotesensi ng.org/gdal/ogr/index.html saber ms acerca de los formatos vectoriales diferentes MapServer soporta. TIPO Qu tipo de datos que es? Si se trata de un conjunto de datos vectoriales, puede es pecificar si se trata de un polgono, lnea (se utiliza lnea, incluso si los datos es tcnicamente una polilnea), o un punto. Tambin puede especificar trama o la anotacin de datos. Aqu queremos mostrar POLGONO. ESTADO Las capas se activa o desactiva en funcin de su Estado. DEFAULT siempre est encend ido. Encendido o apagado funciona cuando el nombre de la capa se hace pasar como parte de la cadena de consulta. Echemos un vistazo a los parmetros de clase de objeto: CLASE Marca el comienzo de un objeto de clase dentro del objeto Layer. Puede especific ar tantas clases dentro de una capa a pesar de que se limitan a 50 por defecto. Vas a tener que volver a compilar MapServer para cambiar este valor por defecto. COLOR Este es el color de relleno del polgono. En caso de que el TIPO es la lnea, este e s el color de la lnea. Los valores se encuentran en formato RGB. OUTLINECOLOR Este es el color del contorno de los polgonos. Los valores se encuentran en forma to RGB. Con esto termina el primer ejemplo en este tutorial. Se le anima a cambiar los v alores de las palabras clave en el archivo de asignaciones. Le ayudar a entender lo que estas palabras clave hacerlo.

You might also like