Mapserver

From DreamsteepWiki

Jump to: navigation, search

CONFIGURATION AND RUNNING IT

install a module with fgs

fgs install mod_python-module:3.3.1 http://www.maptools.org/dl/fgs/modules

starting fgs apache on linux

cd /opt/fgs
. setenv.sh 
fgs start


TEST FOR POSTGRES


cd /opt/fgs
. setenv.sh 
 fgs version | grep postgresql-server


CONFIGURATION (FGS AND MS4W) MS4W C:\ms4w\Apache\conf\http.conf

DocumentRoot "C:/ms4w/Apache/htdocs"
ServerName localhost.local.domain
ServerAdmin admin@local.domain
ServerRoot "C:/ms4w/Apache"

#Listen 12.34.56.78:80
Listen 80

setting up a directory in http.conf

<Directory "C:/ms4w/Apache/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
</Directory>

C:\ms4w\Apache\cgi-bin\php.ini



FGS










ADDRESS OF AN APP

http://127.0.0.1/cgi-bin/mapserv.exe

QUERY STRING

?map=/ms4w/apps/tutorial/htdocs/example1-1.map&layer=states&mode=map









GET EXTENTS

ogrinfo -al -so all_bboxes.shp




EMBED IN HTML


#HTML 

<html>
<head> <title>MapServer First Map</title></head>
<body>
   <form method=POST action="cgi-bin/mapserv.exe">
      <input type="submit" value="mapserversuvbmit">
      <input type="hidden" name="map" value="/ms4w/Apache/htdocs/first.map">
      <input type="hidden" name="map_web_imagepath" value="">
   </form>
   <IMG SRC="[img]" width=600 height=600 border=0>
</body>
</html>

#MAPFILE 

# This is our first mapfile
NAME "First"
SIZE 800 600
IMAGECOLOR 255 255 255
IMAGETYPE PNG
SHAPEPATH "/ms4w/Apache/htdocs/mapdata/"
EXTENT -125.00 20.00 -65.00 50
WEB
    TEMPLATE '/ms4w/apache/htdocs/first.html'
    IMAGEPATH '/ms4w/Apache/htdocs/tmp/'
    IMAGEURL '/tmp/'
END


##

LAYER
    NAME "country_layer"					
    STATUS default
    TYPE polygon
    DATA "countries"
    LABELITEM "STATE"
    OPACITY 20
    CLASS
       STYLE
            COLOR 0 0 0
       END
       LABEL
            COLOR 0 0 0
            SIZE small
       END
    END
END

##

LAYER
    NAME "city_layer"					
    STATUS default
    TYPE point
    DATA "cities"
    LABELITEM "STATE"
    CLASS
       STYLE
            COLOR 0 0 0
       END
       LABEL
            COLOR 0 0 0
            SIZE small
       END
    END
END

##



END






EXAMPLE MAP SCRIPTS

SYMBOLS AND MULTI TYPE CLASSES IN A SHAPEFILE


MAP
  IMAGETYPE      PNG24
  IMAGECOLOR 100 110 110
  EXTENT       161.0 -488.0 1225518.0 1432254.0 # LAEA
  SIZE           800 600
  SHAPEPATH      "../data"
  SYMBOLSET      "../symbols/symbols35.sym"
  FONTSET        "../fonts/fonts.list"

  PROJECTION

      "proj=laea"
      "ellps=clrk66"
      "lat_0=45"
      "lon_0=-100"

  SYMBOL
  NAME "aaa"
  TYPE vector
  POINTS
    0 4
    2 0
    0 4
  END
  END

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

    PROJECTION
      "init=epsg:4326"
    END

    CLASSITEM    "CLASS"
    CLASS
      NAME 'States'
      EXPRESSION 'land'
      STYLE
        COLOR      0 232 0
      END

    END
    CLASS
      NAME 'waver'
      EXPRESSION 'water'
      STYLE
        COLOR      0 33 232
        OUTLINECOLOR 220 0 0
        WIDTH 220
       END
    END

    CLASS
      NAME 'triwavey'
      EXPRESSION 'aaa'
      STYLE
        COLOR      200 0 0
        OUTLINECOLOR 0 0 0
        SYMBOL 'triangle'
      END
    END

  END 

  ##

  SCALEBAR
    STATUS EMBED
    UNITS FEET
    INTERVALS 5
    TRANSPARENT TRUE
    OUTLINECOLOR 0 20 200
  END
END


MAPSERVER QUERY EXAMPLE (UNTESTED)


MAP
  IMAGETYPE      PNG
  EXTENT         633527.743437 2517184.387950 669562.958005 2556945.272294
  SIZE           400 300
  SHAPEPATH      "/ms4w/Apache/htdocs/my_shape_files/shape_ams"
  IMAGECOLOR     255 255 255
  LAYER
    NAME         EXP_SEGMENT_FONCTIONNEL
    DATA         EXP_SEGMENT_FONCTIONNEL
        STATUS       OFF
        TYPE         LINE
    STATUS       DEFAULT
    CLASS
      NAME       "AMS Example"
      STYLE
        COLOR        0 0 0
        OUTLINECOLOR 32 32 32
      END
    END
  END
END



<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>MapServer Layer: AMS Example</title>
    <script src="../../lib/OpenLayers.js"></script>
    <script type="text/javascript">
        var map, layer, mybounds;

        function init(){
            map = new OpenLayers.Map("map");
            layer = new OpenLayers.Layer.MapServer( "Exemple AMS", "http://localhost:8081/cgi-bin/mapserv.exe?map=/ms4w/Apache/htdocs/my_examples_MS/ams_exp.map", {layers: "EXP_SEGMENT_FONCTIONNEL", format: 'image/png', isBaseLayer: false, opacity: 1});
            map.addLayer(layer);
                        mybounds = new OpenLayers.Bounds(633527.743437,2517184.387950,669562.958005,2556945.272294);
                        map.zoomToExtent(mybounds);
            map.addControl( new OpenLayers.Control.LayerSwitcher() );
        }
       
    </script>
  </head>
  <body onload="init()">
    <div id="title">MapServer Layer: AMS Example</div>
    <div id="map"></div>
  </body>
</html>



MAP
  IMAGETYPE      PNG24
  EXTENT         -97.238976 41.619778 -82.122902 49.385620
  SIZE           600 400
  SHAPEPATH      "/ms4w/apps/foo/data"
  IMAGECOLOR     50 50 85

  # Start of LAYER DEFINITIONS ---------------------------------------------
  LAYER # MODIS raster layer begins here
   DATA "raster/shdrlfi020g_ugl.tif"
   STATUS DEFAULT
   TYPE RASTER
   OFFSITE 255 74 66
  END # MODIS raster layer ends here

  LAYER # States polygon layer begins here
    NAME         states
    DATA         states_ugl
    STATUS       OFF
    TYPE         POLYGON
    OPACITY      50

    CLASS
      NAME       "The Upper Great Lakes States"

      STYLE
        COLOR        0 0 45
        OUTLINECOLOR 32 32 32
      END
    END
  END # States polygon layer ends here
  
  ##
  LAYER # States polygon layer begins here
    NAME         states
    DATA         states_ugl
    STATUS       OFF
    TYPE         POINT

    CLASS
      NAME       "The Upper Great Lakes States"

      STYLE
        COLOR        232 232 232
        OUTLINECOLOR 32 32 32
      END
    END
  END # States polygon layer ends here

  ##
  
  # End of LAYER DEFINITIONS -------------------------------

END #


MULTIPLE CLASSES IN ONE SHAPEFILE


MAP
  IMAGETYPE      PNG24
  # EXTENT 199949.651166 -371954.772084 1472121.6862 632767.19157
  #EXTENT       201621.496941 -4488.285333 1425518.020722 498254.511514 # LAEA
  EXTENT       161.0 -488.0 1225518.0 1432254.0 # LAEA
  #EXTENT         -92.103 45.099 -83.89 48.19 # Geographic
  SIZE           400 300
  SHAPEPATH      "../data"
  SYMBOLSET      "../symbols/symbols35.sym"
  FONTSET        "../fonts/fonts.list"

  PROJECTION

  END # End of the output Projection definition ---

  # Start of LAYER DEFINITIONS ---------------------------------------------
  LAYER 
    NAME         states
    DATA         states_ugl
    STATUS       OFF
    TYPE         POLYGON

    PROJECTION
      "init=epsg:4326"
    END

    CLASSITEM    "CLASS"
    CLASS
      NAME 'States'
      EXPRESSION 'land'
      STYLE
        COLOR      0 232 0
      END

    END
    CLASS
      NAME 'wwwa'
      EXPRESSION 'water'
      STYLE
        COLOR      0 232 232
      END
    END

    CLASS
      NAME 'wwwa'
      EXPRESSION 'foil'
      STYLE
        COLOR      200 0 0
      END
    END
    
  END # 
END



OPENLAYERS MAPS

<html xmlns="http://www.w3.org/1999/xhtml">
 	  <head>
 	    <style type="text/css">
 	        #map {
 	            width: 800px;
 	            height: 475px;
 	            border: 1px solid black;
 	        }
 	    </style>
 	    <script src="http://openlayers.org/dev/lib/OpenLayers.js"></script>
 	    <script type="text/javascript">
 	        <!--
 	        var map, layer;
 	
 	        function init(){
 	            map = new OpenLayers.Map( 'map' );
 	            layer = new OpenLayers.Layer.MapServer( "OpenLayers WMS",
 	                    "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
 	            map.addLayer(layer);
 	            map.zoomToMaxExtent();
 	        }
 	        // -->
 	    </script>
 	  </head>
 	  <body onload="init()">
 	    <div id="map"></div>
 	  </body>
 	</html>


MY FIRST OPEN LAYERS MAP

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>MapServer Home Photo</title>
    <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
    <link rel="stylesheet" href="style.css" type="text/css" />
	 <style type="text/css">
        #map {
            width: 100%;
            height: 90%;
            border: 1px solid red;
        }
    </style>
    <script src="http://openlayers.org/dev/lib/OpenLayers.js"></script>
    <script type="text/javascript">

        var lon = 1325150;
        var lat = 11225500;
        var zoom = 0;
        var map, photo, taxlot, roads, taxpoly;

	
        function init()
        {
         map = new OpenLayers.Map({div: 'map', allOverlays: true,
  			 maxExtent: new OpenLayers.Bounds(-97.238976, 41.619778 ,-82.122902, 49.385620),maxResolution: "auto", units:'feet'});
				
         //###########

			   taxlot = new OpenLayers.Layer.MapServer( 'TAX_LINES', "http://localhost/cgi-bin/mapserv.exe",
					{map: '/ms4w/apps/bar/htdocs/foo.map',layers: "taxlots"},
                    {'isBaseLayer': false, alpha: true},{singleTile: true});


        //###########
			  //map.addLayers([roads]);
			  map.addLayer(taxlot);
			  
			  map.zoomToExtent( new OpenLayers.Bounds (-97.238976, 41.619778 ,-82.122902, 49.385620));
  			map.addControl( new OpenLayers.Control.MousePosition() );
        map.addControl( new OpenLayers.Control.LayerSwitcher() );
        //map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
        }

    </script>
  </head>
  <body onload="init()">
    <div id="title">MY FIRST OPEN LAYERS MAP </div>
    <div id="tags"></div>
    <div id="map" class="smallmap"></div>
  </body>
</html>

CRESS'S OPENLAYERS JASPER MAP

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>MapServer Home Photo</title>
    <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
    <link rel="stylesheet" href="style.css" type="text/css" />
	<style type="text/css">
        #map {
            width: 100%;
            height: 90%;
            border: 1px solid red;
        }
    </style>
    <script src="http://openlayers.org/dev/lib/OpenLayers.js"></script>
    <script type="text/javascript">

        var lon = 1325150;
        var lat = 11225500;
        var zoom = 0;
        var map, photo, taxlot, roads, taxpoly;

// avoid pink tiles
        OpenLayers.IMAGE_RELOAD_ATTEMPTS = 1;
//        OpenLayers.Util.onImageLoadErrorColor = "transparent";
		
        function init(){
            map = new OpenLayers.Map({div: 'map', allOverlays: true,
				maxExtent: new OpenLayers.Bounds(1319300, 11219900, 1330800, 11231000),maxResolution: "auto", units:'feet'});

				photo = new OpenLayers.Layer.MapServer( "PHOTO", 
                    "http://localhost/cgi-bin/mapserv.exe",
					{map: '/ms4w/apache/htdocs/jasperphoto.map',layers: "photo", map_imagetype: 'agg'},
                    {singleTile: true});
					
				taxlot = new OpenLayers.Layer.MapServer( 'TAX_LINES', 
                   "http://localhost/cgi-bin/mapserv.exe",
					{map: '/ms4w/apache/htdocs/jaspertaxlot.map',layers: "taxlots"},
                    {'isBaseLayer': false, alpha: true},{singleTile: true});
					
				roads = new OpenLayers.Layer.MapServer.Untiled( "ROAD", 
                   "http://localhost/cgi-bin/mapserv.exe",
					{map: '/ms4w/apache/htdocs/jasperroads.map',layers: "roads"},
                    {'isBaseLayer': false, alpha: true},{singleTile: true});

				taxpoly = new OpenLayers.Layer.MapServer.Untiled( "TAX_POLYS", 
                   "http://localhost/cgi-bin/mapserv.exe",
					{map: '/ms4w/apache/htdocs/jaspertaxpoly.map',layers: "taxpolys"},
                    {'isBaseLayer': false, alpha: true},{singleTile: true});	
					
//					{isBaselayer: false});

                var control = new OpenLayers.Control();
                OpenLayers.Util.extend(control, {
                    draw: function () {
                        // this Handler.Box will intercept the shift-mousedown
                        // before Control.MouseDefault gets to see it
                        this.box = new OpenLayers.Handler.Box( control,
                            {"done": this.notice},
                            {keyMask: OpenLayers.Handler.MOD_SHIFT});
                        this.box.activate();
                    },

                    notice: function (bounds) {
                        var ll = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.left, bounds.bottom)); 
                        var ur = map.getLonLatFromPixel(new OpenLayers.Pixel(bounds.right, bounds.top)); 
                        alert(ll.lon.toFixed(4) + ", " + 
                              ll.lat.toFixed(4) + ", " + 
                              ur.lon.toFixed(4) + ", " + 
                              ur.lat.toFixed(4));
                    }
                });

            map.addLayers([photo]);
			map.addLayers([taxpoly]);
			map.addLayers([taxlot]);
			map.addLayers([roads]);
	
			map.zoomToExtent( new OpenLayers.Bounds (1319300, 11219900, 1330800, 11231000));
//			map.addControl( new OpenLayers.Control.MousePosition() );
            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);

            map.addControl( new OpenLayers.Control.LayerSwitcher() );
        }
// # http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apache/htdocs/home.map&layer=photo&mode=map
       
    </script>
  </head>
  <body onload="init()">
    <div id="title">Four Photo Area in Jasper, TX ------------ use + sign at right to toggle layers</div>
    <div id="tags"></div>
    <div id="map" class="smallmap"></div>
  </body>
</html>









LINKS

Personal tools