Introducción a Mapserver

Document Sample
Introducción a Mapserver Powered By Docstoc
					Universidad del Cauca
Maestría en Ingeniería, Área Telemática
Facultad de Ingeniería Electrónica y Telecomunicaciones



                  Sistemas de Información Geográfica
                                 2006


                    Introducción a Mapserver
Profesor: José Armando Ordóñez Córdoba

Objetivo

El objetivo de esta práctica es conocer el funcionamiento de Mapserver.

Prerrequisitos

Esta práctica fue realizada en Windows XP utilizando la distribución binaria de
MapServer para Windows,         La versión utilizada fue la 2.1 disponible en:
http://mapserver.gis.umn.edu/download/current/windows


1. Instalación de MapServer para Windows - MS4W

MS4W es un instalador de MapServer para Windows, que facilita las labores de
instalación, evitando tener que compilar las fuentes o instalar librerías o servidores a
mano. El paquete utilizado para esta practica trae soporte para

   •   Apache HTTP Server versión 2.0.58
   •   PHP versión 5.1.4 or 4.4.3-dev
   •   MapServer CGI 4.8.4
   •   MapScript 4.8.4 (CSharp, Java, PHP, Python)
   •   Incluye soporte para Oracle 10g, y SDE 9.1
   •   MrSID
   •   GDAL/OGR Utilities
   •   Utilidades MapServer
   •   Utilidades PROJ
   •   Utilidades Shapelib
   •   Utilidad Shp2tile
   •   OGR/PHP Extensión 1.0.0
   •   OWTChart 1.2.0

Existen diversos frameworks de trabajo para el desarrollo de aplicaciones Web
habilitadas para SIG, que funcionan sobre MS4W entre ellas: chameleon y MapLab.
Diseño

MS4W esta diseñado para realizar una instalación completa de Apache, PHP,
MapServer, CGI, MapScript (CSharp, Java, PHP, Python), y para proveer la
posibilidad de instalar aplicaciones adicionales fácilmente y rápidamente. Cuenta con
una estructura predeterminada lo que la hace fácil de trabajar

Estructura de directorios
   •   ms4w/
          o  directorio principal , normalmente en C:
   •   ms4w/Apache
          o instalación de apache
   •   ms4w/Apache/bin
          o binarios de apache
   •   ms4w/Apache/cgi-bin
          o localización de mapserv.exe y sus librerías de soporte, así mismo php.ini,
             php.exe.
   •   ms4w/Apache/cgi-bin/ignored-libmap
          o librerías de libmap dlls para Oracle y SDE
   •   ms4w/Apache/cgi-bin/mapscript
          o ubicación de los archivos MapScript de CSharp, Java, y Python
   •   ms4w/Apache/conf
          o archivos de configuración de Apache. No deben ser modificados las
             configuraciones especificas de la aplicación en /ms4w/httpd.d .
   •   ms4w/Apache/error
          o archivos de error para Apache
   •   ms4w/Apache/htdocs
          o directorio Web de Apache, no debería usarse salvo para pruebas.
   •   ms4w/Apache/icons
          o iconos usados por Apache
   •   ms4w/Apache/include
          o directorio include para compilación de Apache
   •   ms4w/Apache/lib
          o archivos lib para compilar con Apache
   •   ms4w/Apache/logs
          o archivos log para Apache.
   •   ms4w/Apache/manual
          o las paginas del manual de apache.
   •   ms4w/Apache/modules
          o módulos para apache
   •   ms4w/Apache/php
          o instalación de PHP
   •   ms4w/Apache/php/ext (MS4W 2.x)
          o ubicación de phpmapscript dll
   •   ms4w/Apache/php/extensions (MS4W 1.x)
          o ubicación de phpmapscript dll
   •   ms4w/Apache/proxy
          o configuraciones proxy de apache, MS4W no las usa
   •   ms4w/apps
          o todas las aplicaciones van aquí.
  •   ms4w/gdaldata
         o archivos de soporte para formatos GDAL
  •   ms4w/gdalplugins
         o guarda las dlls requeridas por los plugins gdal e.g. 'oci_OCI.dll'
  •   ms4w/httpd.d
         o contiene todos los archivos de configuración específicos y locales
            httpd.conf
  •   ms4w/proj
         o instalación de PROJ.4
         o el archivo epsg esta en /ms4w/proj/nad/epsg
  •   ms4w/python
         o asociado con archivos python, incluyendo enlaces gdal y un script
            simple de prueba.
  •   ms4w/tmp
         o archivos temporales. Debería ser limpiado periódicamente
  •   ms4w/tmp/ms_tmp
         o archivos temporales que necesitan ser accesibles a través de Web (i.e.
            imágenes creadas con mapserver). Esta carpeta se accede como
            /ms_tmp/ desde las páginas Web. Esto significa que los archivos MAP
            tendrían un atributo IMAGEPATH de /ms4w/tmp/ms_tmp/ y una
            IMAGEURL de /ms_tmp/
  •   ms4w/tools
         o herramientas como las utilidades gdal/ogr y utilidades de mapserv (antes
            de utilizarlas debe ejecutarse el script /ms4w/setenv.bat en la línea de
            comandos)

Instalación de MS4W

  1. Descomprima MS4W .zip file en C: debería aparecer un directorio llamado
     'ms4w' con la estructura vista en el punto anterior
2. arranque el servidor Web Apache con el script /ms4w/apache-install.bat. este
   archivo instala el servidor apache como servicio ("Apache Web Server") debería
   aparecer un mensaje:

The Apache MS4W Web Server service is starting.
The Apache MS4W Web Server service was started successfully.

3. para probar la instalación accede las siguientes URLs:

http://localhost/      o http://127.0.0.1/


   Debería aparecer la pagina principal de MS4W en el browser Web..

4. MS4W permite instalar aplicaciones Web como Chameleon para desarrollar
   fácilmente aplicaciones Web. Para instalar estas aplicaciones Web solo se deben
   copiar algunos archivos en /ms4w/apps/ y en /ms4w/httpd.d/.
5. En /ms4w/apps/ se copian los archivos de la aplicación Creamos una carpeta
   llamada “tutorial” dentro de “/ms4w/apps” y dentro de ella las carpetas: “map”,
   “data”, “htdocs”. Como se muestra en la siguiente figura.
   6. Dentro de data copiamos el contenido de la carpeta data que acompaña esta
      práctica, esta es toda la cartografía que se manejará en la práctica.
   7. En /ms4w/httpd.d se debe crear un archivo de configuración httpd_*.conf por
      cada nueva aplicación. (/httpd.d/ contiene los archivos de configuración de
      apache que define la ubicacion de los archivos utilizados por el servidor Web.)
   8. La definición de los directorios accesibles por Web se hace a través de Web
      Aliases. Por ejemplo si se define un alias tutorial debemos crear un archivo
      httpd_tutorial.conf que apunte a la instalcion de nuestra aplicación tutorial


          Alias /tutorial "/ms4w/apps/tutorial/htdocs"
          <Directory "/ms4w/apps/tutorial/htdocs">
              AllowOverride None
              Options Indexes MultiViews Includes FollowSymLinks
              Order allow,deny
              Allow from all
          </Directory>

En C:\ms4w\Apache\htdocs creamos un archivo tutorial.pkg.html
Con el siguiente contenido:

<h3>Tutorial Mapserver 4.6:</h3>
<blockquote>
  <p><a href="/tutorial/">Go to the tutorial.</a></p>
</blockquote>

2. Mapa con una sola capa

Mapserver es un programa CGI que resuelve peticiones Web de los clientes y retorna
datos Geográficos, que pueden ser imágenes o archivos XML. Para resolver estas
peticiones a menudo necesita información extra que puede obtener del archivo MAP de
configuración.

En la pagina principal de nuestra instalación de mapserver: http://localhost/ hay un
enlace al cgi de mapserver: “mapserv 4.8.4 en /cgi-bin/mapserv.exe”. Si accedemos al
enlace http://localhost/cgi-bin/mapserv.exe? encontraremos obtendremos el mensaje:

          No query information to decode. QUERY_STRING is set, but empty.

Porque no hemos dado información suficiente para resolver la consulta.

Para la primera parte de esta práctica utilizaremos la capacidad de mapserver de crear
una imagen y devolverla al browser. Para eso invocaremos el programa CGI de
mapserver con consultas de este tipo

http://localhost/cgi-bin/mapserv.exe? map=C:/ms4w/apps/tutorial/htdocs/ejemplo1-
1.map&layer=states&mode=map
la URL se puede divider en 3 partes: la primera parte, http://localhost/cgi-
bin/mapserv.exe?, llama al programa CGI de MapServer. Las siguientes partes
conforman la sentencia de consulta. La consulta contiene los parámetros CGI (variables
y sus valores) separados por &. El primer parámetro "map" tiene el valor de
"c:/ms4w/apps/tutorial/htdocs/ejemplo1-1.map" esto le dice al programa CGI de
MapServer que archivo MAP mapfile procesar. El siguiente parámetro dice que capa
activar "layer=states", el parametro, "mode=map", indica si se requiere una imagen o
una pagina Web.


                                                     CGI

                                                          Archivo de
   http://localhost/cgi-bin/mapserv.exe?
                                                          configuración
   map=C:/ms4w/apps/tutorial/htdocs/ejemplo1-1.map

   &layer=states&mode=map


                              Parámetros de despliegue


Copiemos el primer mapfile ejemplo1.1.map dentro de /ms4w/apps/tutorial/map

# The annotated map file (sort of)
# Created by Pericles S. Nacionales for the MapServer tutorial
# 20050408
#
# MapServer map file uses the pound sign (#) to denote the start of a
line
# comment--each line that needs to be commented has to be prepended
with a "#".
#
# Map files begin with MAP keyword to signify the start of the map
object.
# Well, the entire map file is THE map object. Enclosed between MAP
and END
# at the very bottom of this map file, are keyword/value pairs and
other
# objects.
MAP
  IMAGETYPE      PNG
  EXTENT         -97.238976 41.619778 -82.122902 49.385620
  SIZE           400 300
  SHAPEPATH      "c:/ms4w/apps/tutorial/data"
  IMAGECOLOR     255 255 255
  # Layer objects are defined beneath the map object. You need at
least one
  # layer defined in your map file before you can display a map...
You can
  # define as many layers as you'd like although a limit is typically
hard-coded
  # in map.h in the MapServer source. The default limit is set at 100.
You'd
  # have to have a very specialized application to need more than 100
layers in
  # your application.

  # Start of LAYER DEFINITIONS ---------------------------------------
------
  LAYER # States polygon layer begins here
    NAME         states
    DATA         states_ugl
    STATUS       DEFAULT
    TYPE         POLYGON

    # The class object is defined within the layer object. You can
define as
    # many classes as you need (well, there are limits as with layers,
but it's
    # senseless to define more than ten on a "normal" layer. There
are
    # situations, however, where you might have to do it.)
    CLASS
      NAME       "The Upper Great Lakes States"

      # There are styles in a class, just like there are classes in a
layer,
      # just like there are layers in a map. You can define multiple
styles in
      # a class just as you can define multiple classes in a layer and
multiple
      # layers in a map.
      STYLE
        COLOR        232 232 232
        OUTLINECOLOR 32 32 32
      END
    END
  END # States polygon layer ends here
  # End of LAYER DEFINITIONS -------------------------------

END # All map files must come to an end just as all other things must
come to...

Ahora accedamos al primer ejemplo a través del browser.

http://localhost/cgi-
bin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo1.1.map&layer=states&mode
=map

Otro ejemplo: El código del mapfile ejemplo1.1b.map que colocaremos dentro de la
carpeta map es:

# The annotated map file (sort of)
# Created by Pericles S. Nacionales for the MapServer tutorial
# 20050408
#
# MapServer map file uses the pound sign (#) to denote the start of a
line
# comment--each line that needs to be commented has to be prepended
with a "#".
#
# Map files begin with MAP keyword to signify the start of the map
object.
# Well, the entire map file is THE map object. Enclosed between MAP
and END
# at the very bottom of this map file, are keyword/value pairs and
other
# objects.
MAP
  IMAGETYPE      PNG
  EXTENT         1063715.564873 739152.858942 1089478.534127
757634.989059
  SIZE           400 300
  SHAPEPATH      "c:/ms4w/apps/tutorial/data"
  IMAGECOLOR     255 255 255

  # Layer objects are defined beneath the map object. You need at
least one
  # layer defined in your map file before you can display a map...
You can
  # define as many layers as you'd like although a limit is typically
hard-coded
  # in map.h in the MapServer source. The default limit is set at 100.
You'd
  # have to have a very specialized application to need more than 100
layers in
  # your application.

  # Start of LAYER DEFINITIONS ---------------------------------------
------
  LAYER # States polygon layer begins here
    NAME         states
    DATA         Vcurvas
    STATUS       DEFAULT
    TYPE         LINE

    # The class object is defined within the layer object. You can
define as
    # many classes as you need (well, there are limits as with layers,
but it's
    # senseless to define more than ten on a "normal" layer. There
are
    # situations, however, where you might have to do it.)
    CLASS
      NAME       "The Upper Great Lakes States"

      # There are styles in a class, just like there are classes in a
layer,
      # just like there are layers in a map. You can define multiple
styles in
      # a class just as you can define multiple classes in a layer and
multiple
      # layers in a map.
      STYLE
        COLOR        0 0 255
        OUTLINECOLOR 32 32 32
      END
    END
  END # States polygon layer ends here
  # End of LAYER DEFINITIONS -------------------------------

END # All map files must come to an end just as all other things must
come to...

Revisamos el ejemplo 1b:

http://localhost/cgi-
bin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo1.1b.map&layer=states&mod
e=map




2. Modificando el extent


El mapfile se compone de objetos, que forman una estructura jerarquica que comienzan
con MAP. Un ejemplo de la estructura:

       MAP
        |-LAYER
          |-CLASS
            |-STYLE

Algunos parámetros del objeto MAP:

IMAGETYPE: define el tipo de formato generado por MapServer.
EXTENT: especifica la extensión de la salida de nuestro mapa, los limites del mapa
los valores se dan en el formato: <inferior izquierda X> < inferior izquierda Y>
<superior derecha X> < superior derecha Y>, con espacios separando cada valor. Esto
necesita estar en las mismas unidades que los datos o de la proyección de salida..
la herramienta orginfo (dentro de la instación de ms4w), sirve para calcular la extension
de un shapefile

ogrinfo -al -so states_ugl.shp

Se obtiene la salida:
INFO: Open of `states_ugl.shp'
using driver `ESRI Shapefile' successful.

Layer name: states_ugl
Geometry: Polygon
Feature Count: 204
Extent: (-97.238976, 41.619778) - (-82.122902, 49.385620)
Layer SRS WKT:
(unknown)
AREA: Real (12.3)
PERIMETER: Real (12.3)
STATESP020: Real (11.0)
STATE: String (20.0)
STATE_FIPS: String (2.0)
CLASS: String (5.0)


C:\ms4w\tools\gdal-ogr>ogrinfo -al -so c:/maps/vcurvas.shp
INFO: Open of `c:/maps/vcurvas.shp'
using driver `ESRI Shapefile' successful.

Layer name: vcurvas
Geometry: Line String
Feature Count: 630
Extent: (1065949.434500, 739992.955765) - (1087244.664500,
756794.892235)
Layer SRS WKT:
(unknown)
VALUE: Integer (4.0)

Para el siguiente ejemplo analizaremos el parametro extent, este parámetro recibe las
coordenadas de mapa a mostrar como se muestra en la figura, primero el punto inferior
izquierdo y luego el superior derecho.
SIZE: tamaño de la imagen que se genera

SHAPEPATH: ruta de las capas de datos

IMAGECOLOR: RGB del color de fondo

LAYER: capa del objeto MAP

NAME: identificador de la capa

DATA: nombre de los datos (shapefile en este caso).

TYPE: que tipo de dato es: POLYGON, LINE, POINT, RASTER, ANNOTATION.

STATUS: si las capas esten activas.

CLASS: objeto CLASS

NAME: identificador para el CLASS, este nombre se utiliza en las leyendas

STYLE: estilo de la clase

COLOR: color de relleno del polígono o la linea.

OUTLINECOLOR: RGB del color de borde de los poligonos.

Agregue esto al ejemplo 1.1 entre las dos líneas:

END # States polygon layer ends here
PEGUE AQUI…..
# End of LAYER DEFINITIONS -------------------------------

Y guardelo como ejemplo1.2.map.:

 LAYER # States polygon layer begins here
  NAME    states_poly
  DATA   states_ugl
  STATUS   OFF
  TYPE   POLYGON

  # The class object is defined within the layer object. You can define as
  # many classes as you need (well, there are limits as with layers, but it's
  # senseless to define more than ten on a "normal" layer. There are
  # situations, however, where you might have to do it.)
  CLASS
   NAME         "States"

   # There are styles in a class, just like there are classes in a layer,
   # just like there are layers in a map. You can define multiple styles in
   # a class just as you can define multiple classes in a layer and multiple
   # layers in a map.
   STYLE
    COLOR 232 232 232
   END
  END
 END # States polygon layer ends here

 LAYER # States line layer begins here
  NAME      states_line
  DATA      states_ugl
  STATUS     OFF
  TYPE     LINE

  CLASS
   NAME       "State Boundary"
   STYLE
    COLOR 32 32 32
   END
  END
 END # States line layer ends here
 # End of LAYER DEFINITIONS -------------------------------

Miramos el resultado con:

http://localhost/cgi-
bin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo1.2.map&layer=states_poly&
mode=map
Y agregando algunas capas:

http://localhost/cgi-
bin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo1.2.map&layer=states_line&
mode=map




3. Mostrando clases en una capa

La estructura del mapfile, por objetos es:

                                   MAP
       (states_poly) LAYER----------|---------LAYER (states_line)
                       |                      |
        (land) CLASS---|---CLASS (water)      |-CLASS
                   |       |                    |
             STYLE-|       |-STYLE              |-STYLE

Los parámetros adicionales son:

CLASSITEM: esta palabra clave se usa para especificar que atributo usar en en la
escogencia de objetos de clases

EXPRESSION: para cada clase, especificamos una expresión de consulta en el DBF.
A continaución el codigo del archivo ejemplo1.4.map:

# The annotated map file (sort of)
# Created by Pericles S. Nacionales for the MapServer tutorial
# 20050408
#
# MapServer map file uses the pound sign (#) to denote the start of a
line
# comment--each line that needs to be commented has to be prepended
with a "#".
#
# Map files begin with MAP keyword to signify the start of the map
object.
# Well, the entire map file is THE map object. Enclosed between MAP
and END
# at the very bottom of this map file, are keyword/value pairs and
other
# objects.
MAP
  IMAGETYPE      PNG
  EXTENT         -97.238976 41.619778 -82.122902 49.385620
  SIZE           400 300
  SHAPEPATH      "../data"
  IMAGECOLOR     255 255 255
  FONTSET        "../fonts/fonts.list"

  # Layer objects are defined beneath the map object. You need at
least one
  # layer defined in your map file before you can display a map...
You can
  # define as many layers as you'd like although a limit is typically
hard-coded
  # in map.h in the MapServer source. The default limit is set at 100.
You'd
  # have to have a very specialized application to need more than 100
layers in
  # your application.

  # Start of LAYER DEFINITIONS ---------------------------------------
------
  LAYER # States polygon layer begins here
    NAME         states_poly
    DATA         states_ugl
    STATUS       OFF
    TYPE         POLYGON

    # CLASSITEM defines the non-spatial attribute that you will be
using to
    # separate a layer into classes. This attribute will be in the
DBF file
    # of your shapefile (it will be different for each data format).
In this
    # example the shapefile states_ugl has an associated database
    # (states_ugl.dbf) that contains an attribute called "CLASS". You
will be
    # using two values in the CLASS attribute to separate the classes
(also
    # called themes) used in this layer--land and water. CLASSITEM is
used in
    # association with the EXPRESSION parameter in the CLASS object.
See below.
   CLASSITEM    "CLASS"

    # Just like CLASSITEM, LABELITEM defines the database attribute
that you
    # will be using to draw labels. In this case, the values of the
attribute
    # "STATE" will be used to label the states polygons.
    LABELITEM    "STATE"

    # The class object is defined within the layer object. You can
define as
    # many classes as you need (well, there are limits as with layers,
but it's
    # senseless to define more than ten on a "normal" layer. There
are
    # situations, however, where you might have to do it.)
    CLASS
      NAME 'States'
      EXPRESSION 'land'

      # There are styles in a class, just like there are classes in a
layer,
      # just like there are layers in a map. You can define multiple
styles in
      # a class just as you can define multiple classes in a layer and
multiple
      # layers in a map.
      STYLE
        COLOR      232 232 232
      END

      # There can be labels in a class, just like there are classes in
a layer,
      # just like there are layers in a map. You can define multiple
labels in
      # a class just as you can define multiple classes in a layer and
multiple
      # layers in a map.
      # MapServer has a very flexible labeling system. With that
flexibility
      # comes complexity, specially when using truetype fonts. Please
read
      # through the LABEL section of the MapServer map file
documentation at
      # http://ms.gis.umn.edu/docs/reference/mapfile for more
information.
      LABEL
        COLOR 132 31 31
        SHADOWCOLOR 218 218 218
        SHADOWSIZE 2 2
        TYPE TRUETYPE
        FONT arial-bold
        SIZE 12
        ANTIALIAS TRUE
        POSITION CL
        PARTIALS FALSE
        MINDISTANCE 300
        BUFFER 4

     END # end of label
   END
    CLASS
      NAME 'Water'
      EXPRESSION 'water'

      STYLE
        COLOR      198 198 255
      END
    END
  END # States polygon layer ends here

  LAYER # States   line layer begins here
    NAME           states_line
    DATA           states_ugl
    STATUS         OFF
    TYPE           LINE

    CLASSITEM    "CLASS"
    CLASS
      NAME 'State Boundary'
      EXPRESSION 'land'
      STYLE
        COLOR      64 64 64
      END
    END
  END # States line layer ends here
  # End of LAYER DEFINITIONS -------------------------------

END # All map files must come to an end just as all other things must
come to..

Miramos el resultado con:http://localhost/cgi-
bin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo1.3.map&layer=states_poly&
layer=states_line&mode=map
4. Etiquetas

Copiamos fonts en la carpeta de aplicaciones




La estructura de objetos es la siguiente:

                                   MAP
       (states_poly) LAYER----------|---------LAYER (states_line)
      (land) CLASS-----|-CLASS (water)        |-CLASS
         STYLE-|-LABEL   |-STYLE                |-STYLE



Los parametros de LABEL son:

FONTSET: nombre de las fuentes.

LABELITEM: atributo de datos usado para las etiquetas

LABEL: indica el comienzo de un objeto etiqueta. El objeto etiqueta puede ser usado
bajo otros objetos.

COLOR: color del texto de la etiqueta.

TYPE: Tipo de fuente a usar TRUETYPE or BITMAP

A continaución el codigo del archivo ejemplo1.4.map:

# The annotated map file (sort of)
# Created by Pericles S. Nacionales for the MapServer tutorial
# 20050408
#
# MapServer map file uses the pound sign (#) to denote the start of a
line
# comment--each line that needs to be commented has to be prepended
with a "#".
#
# Map files begin with MAP keyword to signify the start of the map
object.
# Well, the entire map file is THE map object. Enclosed between MAP
and END
# at the very bottom of this map file, are keyword/value pairs and
other
# objects.
MAP
  IMAGETYPE      PNG
  EXTENT         -97.238976 41.619778 -82.122902 49.385620
  SIZE           400 300
  SHAPEPATH      "../data"
  IMAGECOLOR     255 255 255
  FONTSET        "../fonts/fonts.list"

  # Layer objects are defined beneath the map object. You need at
least one
  # layer defined in your map file before you can display a map...
You can
  # define as many layers as you'd like although a limit is typically
hard-coded
  # in map.h in the MapServer source. The default limit is set at 100.
You'd
  # have to have a very specialized application to need more than 100
layers in
  # your application.

  # Start of LAYER DEFINITIONS ---------------------------------------
------
  LAYER # States polygon layer begins here
    NAME         states_poly
    DATA         states_ugl
    STATUS       OFF
    TYPE         POLYGON

    # CLASSITEM defines the non-spatial attribute that you will be
using to
    # separate a layer into classes. This attribute will be in the
DBF file
    # of your shapefile (it will be different for each data format).
In this
    # example the shapefile states_ugl has an associated database
    # (states_ugl.dbf) that contains an attribute called "CLASS". You
will be
    # using two values in the CLASS attribute to separate the classes
(also
    # called themes) used in this layer--land and water. CLASSITEM is
used in
    # association with the EXPRESSION parameter in the CLASS object.
See below.
    CLASSITEM    "CLASS"

    # Just like CLASSITEM, LABELITEM defines the database attribute
that you
    # will be using to draw labels. In this case, the values of the
attribute
   # "STATE" will be used to label the states polygons.
   LABELITEM    "STATE"

    # The class object is defined within the layer object. You can
define as
    # many classes as you need (well, there are limits as with layers,
but it's
    # senseless to define more than ten on a "normal" layer. There
are
    # situations, however, where you might have to do it.)
    CLASS
      NAME 'States'
      EXPRESSION 'land'

      # There are styles in a class, just like there are classes in a
layer,
      # just like there are layers in a map. You can define multiple
styles in
      # a class just as you can define multiple classes in a layer and
multiple
      # layers in a map.
      STYLE
        COLOR      232 232 232
      END

      # There can be labels in a class, just like there are classes in
a layer,
      # just like there are layers in a map. You can define multiple
labels in
      # a class just as you can define multiple classes in a layer and
multiple
      # layers in a map.
      # MapServer has a very flexible labeling system. With that
flexibility
      # comes complexity, specially when using truetype fonts. Please
read
      # through the LABEL section of the MapServer map file
documentation at
      # http://ms.gis.umn.edu/docs/reference/mapfile for more
information.
      LABEL
        COLOR 132 31 31
        SHADOWCOLOR 218 218 218
        SHADOWSIZE 2 2
        TYPE TRUETYPE
        FONT arial-bold
        SIZE 12
        ANTIALIAS TRUE
        POSITION CL
        PARTIALS FALSE
        MINDISTANCE 300
        BUFFER 4

     END # end of label
   END

   CLASS
     NAME 'Water'
     EXPRESSION 'water'

     STYLE
        COLOR      198 198 255
      END
    END
  END # States polygon layer ends here

  LAYER # States      line layer begins here
    NAME              states_line
    DATA              states_ugl
    STATUS            OFF
    TYPE              LINE

    CLASSITEM    "CLASS"
    CLASS
      NAME 'State Boundary'
      EXPRESSION 'land'
      STYLE
        COLOR      64 64 64
      END
    END
  END # States line layer ends here
  # End of LAYER DEFINITIONS -------------------------------

END # All map files must come to an end just as all other things must
come to..



http://localhost/cgi-
bin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo1.4.map&layer=states_poly&
layer=states_line&mode=map




5. Una capa raster

La estructura de objetos es la siguiente:
Para esta parte necesitamos la carpeta symbols




El codigo del archivo ejemplo1.5.map es el siguiente:

# The annotated map file (sort of)
# Created by Pericles S. Nacionales for the MapServer tutorial
# 20050408
#
# MapServer map file uses the pound sign (#) to denote the start of a
line
# comment--each line that needs to be commented has to be prepended
with a "#".
#
# Map files begin with MAP keyword to signify the start of the map
object.
# Well, the entire map file is THE map object. Enclosed between MAP
and END
# at the very bottom of this map file, are keyword/value pairs and
other
# objects.
MAP
  IMAGETYPE      PNG24
  EXTENT         -97.238976 41.619778 -82.122902 49.385620
  SIZE           400 300
  SHAPEPATH      "../data"
  IMAGECOLOR     255 255 255
  FONTSET        "../fonts/fonts.list"
  SYMBOLSET      "../symbols/symbols35.sym"

  # Layer objects are defined beneath the map object. You need at
least one
  # layer defined in your map file before you can display a map...
You can
  # define as many layers as you'd like although a limit is typically
hard-coded
  # in map.h in the MapServer source. The default limit is set at 100.
You'd
  # have to have a very specialized application to need more than 100
layers in
  # your application.
  #
  # Start of LAYER DEFINITIONS ---------------------------------------
------
  LAYER # States polygon layer begins here
    NAME         states
    DATA         states_ugl
    STATUS       OFF
    TYPE         POLYGON

    # CLASSITEM defines the non-spatial attribute that you will be
using to
    # separate a layer into classes. This attribute will be in the
DBF file
    # of your shapefile (it will be different for each data format).
In this
    # example the shapefile states_ugl has an associated database
    # (states_ugl.dbf) that contains an attribute called "CLASS". You
will be
    # using two values in the CLASS attribute to separate the classes
(also
    # called themes) used in this layer--land and water. CLASSITEM is
used in
    # association with the EXPRESSION parameter in the CLASS object.
See below.
    CLASSITEM    "CLASS"

    # The class object is defined within the layer object. You can
define as
    # many classes as you need (well, there are limits as with layers,
but it's
    # senseless to define more than ten on a "normal" layer. There
are
    # situations, however, where you might have to do it.)
    CLASS
      NAME 'States'
      EXPRESSION 'land'

      # There are styles in a class, just like there are classes in a
layer,
      # just like there are layers in a map. You can define multiple
styles in
      # a class just as you can define multiple classes in a layer and
multiple
      # layers in a map.
      STYLE
        COLOR      232 232 232
      END
    END
  END # States polygon layer ends here

  # In addition to vector data (shapefiles are vector data), MapServer
supports
  # a host of raster formats. In GIS world, one of the most common
raster
  # formats is GeoTIFF, a TIFF image with geospatial headers.
MapServer also
  # supports JPEG, PNG, GIF, and other common formats. Other raster
formats
  # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS,
NetCDF,
  # Generic raster binaries, OGC Web Map Service (WMS) layers, etc.
Pretty much
  # any raster format you can think of is probably supported, thanks
to the
  # impressive Geospatial Data Abstraction Library (GDAL, pronounced
"GOODALL"
  # or GOODLE?). More information on GDAL is available at
http://www.gdal.org.
  #
  # MapServer 4.x can read and display bitmapped (like GIFs), RGB/A
(true
  # color), and multispectral (images with more than 3 bands, like raw
LandSat
  # images) rasters.
  LAYER # MODIS raster layer begins here
    NAME         modis
    DATA         raster/mod09a12003161_ugl_ll_8bit.tif
    STATUS       OFF
    TYPE         RASTER
    PROCESSING   "BANDS=1,2,3"
    OFFSITE      71 74 65
  END # MODIS raster layer ends here

 LAYER # States   line layer begins here
   NAME           states_line
   DATA           states_ugl
   STATUS         OFF
   TYPE           LINE

   CLASSITEM    "CLASS"
   CLASS
     NAME       'State Boundary'
     EXPRESSION 'land'
     STYLE
       SYMBOL     'line5'
       COLOR      64 64 64
       SIZE       1
     END
   END
 END # States line layer ends here

  # Labels can be defined in its own layer. This is useful if, say,
you want
  # to label a polygon layer that's covered by another layer. By
keeping the
  # label separate from the polygon and placing it near the bottom of
the map
  # file (so its drawn on, or near the, top), you can still see the
label even
  # though you might not be able to see the polygon. It is also a
good
  # alternate to point symbols.
  #
  # A label layer is actually defined with ANNOTATION type (This is
derived from
  # points, Node     IDs for lines, or polygon IDs).
  LAYER # States     label layer begins here
    NAME             states_label
    DATA             states_ugl
    STATUS           OFF
    TYPE             ANNOTATION

    CLASSITEM        "CLASS"

    # Just like CLASSITEM, LABELITEM defines the database attribute
that you
    # will be using to draw labels. In this case, the values of the
attribute
    # "STATE" will be used to label the states polygons.
    LABELITEM    "STATE"

    CLASS
      EXPRESSION 'land'
      STYLE
        COLOR      -1 -1 -1
      END

      # There can be labels in a class, just like there are classes in
a layer,
      # just like there are layers in a map. You can define multiple
labels in
      # a class just as you can define multiple classes in a layer and
multiple
      # layers in a map.
      # MapServer has a very flexible labeling system. With that
flexibility
      # comes complexity, specially when using truetype fonts. Please
read
      # through the LABEL section of the MapServer map file
documentation at
      # http://ms.gis.umn.edu/docs/reference/mapfile for more
information.
      LABEL
        COLOR 132 31 31
        SHADOWCOLOR 218 218 218
        SHADOWSIZE 2 2
        TYPE TRUETYPE
        FONT arial-bold
        SIZE 12
        ANTIALIAS TRUE
        POSITION CL
        PARTIALS FALSE
        MINDISTANCE 300
        BUFFER 4
      END # end of label
    END # end of class
  END # States label layer ends here
  # End of LAYER DEFINITIONS -------------------------------

END # All map files must come to an end just as all other things must
come to...



Y el resultado se puede ver con:
http://localhost/cgi-
bin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo1.5.map&layer=modis&layer
=states_line&layer=states_label&mode=map




6. Proyecciones y extensiones


La extensión se especifica en las unidades de la proyección del mapa, la proyección se
especifica en el objeto PROJECTION

El codigo del archivo ejemplo1.6.map es el siguiente:


# The annotated map file (sort of)
# Created by Pericles S. Nacionales for the MapServer tutorial
# 20050408
#
# MapServer map file uses the pound sign (#) to denote the start of a
line
# comment--each line that needs to be commented has to be prepended
with a "#".
#
# Map files begin with MAP keyword to signify the start of the map
object.
# Well, the entire map file is THE map object. Enclosed between MAP
and END
# at the very bottom of this map file, are keyword/value pairs and
other
# objects.
MAP
  IMAGETYPE      PNG24
  # EXTENT 199949.651166 -371954.772084 1472121.6862 632767.19157
  EXTENT       201621.496941 -294488.285333 1425518.020722
498254.511514 # LAEA
  #EXTENT         -97.5 41.619778 -82.122902 49.38562 # Geographic
  SIZE           400 300
  SHAPEPATH      "../data"
  SYMBOLSET      "../symbols/symbols35.sym"
  FONTSET        "../fonts/fonts.list"
  # The projection object is typically used within the map and the
layer
  # objects. You only define it once within the map object and this
definition
  # becomes your output projection--MapServer will render your maps in
this
  # projection. You also use the projection object within the layer
object to
  # define your input projection. Your layers can be in different
  # projections--MapServer will reproject them into your output
projection.
  # If no projection is defined within the layer object, MapServer
assumes
  # your input projection is the same as your output projection. This
is not
  # a required object unless you're creating a map file that supports
one of
  # the OGC interoperability web services specifications
(WMS/WFS/WCS).
  #
  # This is the output PROJECTION definition ------
  PROJECTION
    # Projection parameters can be defined in two ways...
    # This is the traditional Proj.4 definition of Lambert Azimuthal
Equal-Area
    # projection for the Continental U.S.
      "proj=laea"
      "ellps=clrk66"
      "lat_0=45"
      "lon_0=-100"

   #   Alternatively, you can specify an EPSG code.
   #   This is the EPSG code for Lambert Azimuthal Equal-Area
   #   projection for the U.S.
   #
   #   "init=epsg:2163"
 END   # End of the output Projection definition ---

  # Layer objects are defined beneath the map object. You need at
least one
  # layer defined in your map file before you can display a map...
You can
  # define as many layers as you'd like although a limit is typically
hard-coded
  # in map.h in the MapServer source. The default limit is set at
100. You'd
  # have to have a very specialized application to need more than 100
layers in
  # your application.
  #
  # Start of LAYER DEFINITIONS ---------------------------------------
------
  LAYER # States polygon layer begins here
    NAME         states
    DATA         states_ugl
    STATUS       DEFAULT
    TYPE         POLYGON

   # Here's an example of the input projection definition.
   # EPSG:4326 is code for geographic (latlong) projection
   # using the WGS84 datum.
   #
   # PROJECTION objects within the LAYER object define the input
   # projection--this is the native projection of your data.
   PROJECTION
     "init=epsg:4326"
   END

    # CLASSITEM defines the non-spatial attribute that you will be
using to
    # separate a layer into classes. This attribute will be in the
DBF file
    # of your shapefile (it will be different for each data format).
In this
    # example the shapefile states_ugl has an associated database
    # (states_ugl.dbf) that contains an attribute called "CLASS". You
will be
    # using two values in the CLASS attribute to separate the classes
(also
    # called themes) used in this layer--land and water. CLASSITEM is
used in
    # association with the EXPRESSION parameter in the CLASS object.
See below.
    CLASSITEM    "CLASS"

    # The class object is defined within the layer object. You can
define as
    # many classes as you need (well, there are limits as with layers,
but it's
    # senseless to define more than ten on a "normal" layer. There
are
    # situations, however, where you might have to do it.)
    CLASS
      NAME 'States'
      EXPRESSION 'land'

      # There are styles in a class, just like there are classes in a
layer,
      # just like there are layers in a map. You can define multiple
styles in
      # a class just as you can define multiple classes in a layer and
multiple
      # layers in a map.
      STYLE
        COLOR      232 232 232
      END
    END
  END # States polygon layer ends here

  # In addition to vector data (shapefiles are vector data), MapServer
supports
  # a host of raster formats. In GIS world, one of the most common
raster
  # formats is GeoTIFF, a TIFF image with geospatial headers.
MapServer also
  # supports JPEG, PNG, GIF, and other common formats. Other raster
formats
  # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-
EOS, NetCDF,
  # Generic raster binaries, OGC Web Map Service (WMS) layers, etc.
Pretty much
  # any raster format you can think of is probably supported, thanks
to the
  # impressive Geospatial Data Abstraction Library (GDAL, pronounced
"GOODALL"
  # or GOODLE?). More information on GDAL is available at
http://www.gdal.org.
  #
  # MapServer 4.x can read and display bitmapped (like GIFs), RGB/A
(true
  # color), and multispectral (images with more than 3 bands, like raw
LandSat
  # images) rasters.
  LAYER # MODIS raster layer begins here
    NAME         modis
    DATA         "raster/mod09a12003161_ugl_ll_8bit.tif"
    STATUS       DEFAULT
    TYPE         RASTER
    PROCESSING   "BANDS=1,2,3"
    OFFSITE      71 74 65

   PROJECTION
     "init=epsg:4326"
   END
 END # MODIS raster layer ends here

 LAYER # States   line layer begins here
   NAME           states
   DATA           states_ugl
   STATUS         DEFAULT
   TYPE           LINE

   PROJECTION
     "init=epsg:4326"
   END

   CLASSITEM    "CLASS"
   CLASS
     NAME       'State Boundary'
     EXPRESSION 'land'
     STYLE
       SYMBOL     'line5'
       COLOR      64 64 64
       SIZE       1
     END
   END
 END # States line layer ends here

 LAYER # States   label layer begins here
   NAME           states_label
   DATA           states_ugl
   STATUS         DEFAULT
   TYPE           ANNOTATION

   PROJECTION
     "init=epsg:4326"
   END

   CLASSITEM      "CLASS"

    # Just like CLASSITEM, LABELITEM defines the database attribute
that you
    # will be using to draw labels. In this case, the values of the
attribute
    # "STATE" will be used to label the states polygons.
    LABELITEM    "STATE"
    CLASS
      EXPRESSION 'land'
      STYLE
        COLOR      -1 -1 -1
      END

      # There can be labels in a class, just like there are classes in
a layer,
      # just like there are layers in a map. You can define multiple
labels in
      # a class just as you can define multiple classes in a layer and
multiple
      # layers in a map.
      # MapServer has a very flexible labeling system. With that
flexibility
      # comes complexity, specially when using truetype fonts. Please
read
      # through the LABEL section of the MapServer map file
documentation at
      # http://ms.gis.umn.edu/docs/reference/mapfile for more
information.
      LABEL
        COLOR 132 31 31
        SHADOWCOLOR 218 218 218
        SHADOWSIZE 2 2
        TYPE TRUETYPE
        FONT arial-bold
        SIZE 12
        ANTIALIAS TRUE
        POSITION CL
        PARTIALS FALSE
        MINDISTANCE 300
        BUFFER 4
      END # end of label
    END # end of class
  END # States label layer ends here
  # End of LAYER DEFINITIONS -------------------------------

END # All map files must come to an end just as all other things must
come to...


Y el resultado se puede ver en
http://localhost/cgi-
bin/mapserv.exe?map=c:/ms4w/apps/tutorial/map/ejemplo1.6.map&layer=states_line&
mode=map

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:28
posted:9/1/2011
language:Spanish
pages:31