1

I am new to GIS and have been assigned a task to publish a map to the web. So I want to ask if anyone can give me a map file example that basically can:

  1. Load the OpenStreetMap and zoom to a area/country.
  2. Load layer with some lines from PostGIS.
  3. Able to click on the lines to display some line details and
  4. Able to filter the lines based on a selection box or option list.

I am using MapServer and read a lot of documentation, but it's still hard for me for the first time. I am sure it's easy for a lot of you here.

closed as too broad by Vince, Dan C, Hornbydd, nmtoken, xunilk Jul 6 at 21:57

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • MapServer is server software so 3 and 4 aren't really applicable ~ you can though get a WMS provided by MapServer to have an OpenLayers output but this is really more of a preview than a map client. MapServer does the publish a map to the web bit. – nmtoken Jul 5 at 15:38
  • what i need is the coding example so that i dont have to try an error which spent me a lot of time. – B Cheng Wong Jul 5 at 15:47
  • You're asking for more than one thing. Server/Service configuration (MapServer + PostGIS) though a map file (no coding there) and Client code to consume one or more services. – nmtoken Jul 5 at 15:52
  • I got MapServer and PostGIS with the database created. I am asking what/how should i code in the mapfile (something.map) to achieve what i want. – B Cheng Wong Jul 5 at 15:58
1

To achieve something like:

http://ogc2.bgs.ac.uk/cgi-bin/UGA_ARGID/ows?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&TRANSPARENT=false&LAYERS=DAD_ITEMS,DAD_MAPS&CRS=EPSG:4326&STYLES=&WIDTH=1068&HEIGHT=952&BBOX=-13.962890625%2C19.604736328125%2C6.955078125%2C43.071533203125&format=application/openlayers&

Which is a WMS provided by MapServer (on a Windows server) with data coming from PostgreSQL you need a map file like:

MAP
    CONFIG "MS_ERRORFILE" "C:/LOGS/mapserver/tst/argi/errord.log"
    CONFIG "PROJ_LIB" "C:/apps/gisinternals/bin/proj/SHARE"
    DEBUG 3
    # EXTENT: Extent wider than Uganda in EPSG:4326
    EXTENT 10 -20 42 6
    FONTSET "../DefaultMapIncludes/fontset.lst"
    IMAGEQUALITY 95
    INCLUDE "../DefaultMapIncludes/BGS-service-std-output.map"
    INCLUDE "dado.map"
    LEGEND
        IMAGECOLOR 255 255 255
        STATUS ON
        KEYSIZE 18 12
        LABEL
            TYPE BITMAP
            SIZE MEDIUM
            COLOR 0 0 89
        END
    END
    MAXSIZE 3072
    NAME "UGA_ARGID_PILOT"
    PROJECTION #Default SERVICE projection
        "init=epsg:4326"
    END
    SHAPEPATH "data"
    SIZE 600 800
    STATUS ON
    SYMBOLSET "../DefaultMapIncludes/symbols.sym"
#====================================================================#
# Start of web interface definition (including WMS enabling metadata)
#====================================================================#
    WEB
        HEADER "tmpl/query_header.htm"
        FOOTER "tmpl/query_footer.htm"
        IMAGEPATH "C:/WxS/ms/apps/test/ARGI_UPP/www/out/"
        IMAGEURL "/ms_tmp/"
        METADATA
            #MAX_EXTENTS: For ka-map
            "MAX_EXTENTS" "29 -2 37 4.5"
            #OWS applies to all services
            "OWS_ABSTRACT" "This is a test web service constructed to help demonstrate ways of sharing data for the ARGI Uganda pilot project. This service has data that is curated by BGS"
            "OWS_ACCESSCONSTRAINTS" "none"
            INCLUDE "../DefaultMapIncludes/BGS-service-contacts.map"
            "OWS_ENABLE_REQUEST" "*"
            "OWS_FEES" "none"
            "OWS_KEYWORDLIST" "Uganda,MD_LANG@ENG,MD_DATE@2019-02-27"
            "OWS_SERVICE_ONLINERESOURCE" "http://www.bgs.ac.uk/"
            "OWS_SLD_ENABLED" "TRUE"
            "OWS_TITLE" "Uganda ARGI pilot project data service for DAD data"
            "OWS_UPDATESEQUENCE" "20190228140000"
            "WCS_ABSTRACT" "There are currently no coverages assoicated with this test web service constructed to help demonstrate ways of sharing data for the ARGI Uganda pilot project"
            "WFS_GETFEATURE_FORMATLIST" "CSVSTREAM,JSON,MIDMIF,SHAPEZIP"
            "WFS_LANGUAGES" "eng"
            "WFS_SRS" "EPSG:4326 EPSG:21095 EPSG:21035 EPSG:21036 EPSG:32635 EPSG:32735 EPSG:32736 EPSG:3857 EPSG:4210"
            # WMS Specific (overwrite OWS metadata where applicable)
            # WMS_ATTRIBUTION_* In this metadata block is added to the root layer metadata ONLY
            INCLUDE "../DefaultMapIncludes/BGS-Attribution.map"
            "WMS_BBOX_EXTENDED" "TRUE"
            "WMS_FEATURE_INFO_MIME_TYPE" "text/html,application/vnd.ogc.gml,text/plain"
            "WMS_GETMAP_FORMATLIST" "image/png,image/jpeg,image/tiff,application/x-pdf,image/svg+xml,mvt"
            "WMS_SRS" "EPSG:4326 EPSG:21095 EPSG:21035 EPSG:21036 EPSG:32635 EPSG:32735 EPSG:32736 EPSG:3857 EPSG:4210 CRS:84"
            #=== INSPIRE extended capabilities ===#
            "OWS_INSPIRE_RESOURCELOCATOR" "http://ogc2.bgs.ac.uk/cgi-bin/UGA_ARGID/ows?"
            "OWS_INSPIRE_METADATADATE" "2018-09-03"
            "OWS_INSPIRE_TEMPORAL_REFERENCE" "2016-01-01"
            "WFS_INSPIRE_DSID_CODE" "ARGID_UPP"
            "WMS_INSPIRE_CAPABILITIES" "embed"
            "WMS_INSPIRE_KEYWORD" "infoMapAccessService"
            "WMS_INSPIRE_MPOC_EMAIL" "enquiries@bgs.ac.uk"
            "WMS_INSPIRE_MPOC_NAME" ""
            "WMS_KEYWORDLIST_GEMET_ITEMS" "Geology"
            "WMS_KEYWORDLIST_ISO_ITEMS" "infoMapAccessService"
            "WMS_KEYWORDLIST_VOCABULARY" "GEMET,ISO"
            "WMS_LANGUAGES" "eng"
            "WMS_ROOTLAYER_TITLE" "UGA_ARGID_PILOT data service"
        END
    END
#========================================================================#
# Units of the map coordinates. Used for scale bar and scale computations.
#========================================================================#
    UNITS dd
END

where "dado.map" is like:

LAYER
    CLASSITEM "gaz_feature_name"
    DATA "geom FROM public.ql_acd_item_ply_4326 using unique feature_id"
    EXTENT 11.3548173872124 -4.98713486430294 35.0002746604481 4.23446608014632
    GROUP "DAD"
    INCLUDE "ARGID-layer-config.map"
    LABELITEM "gaz_feature_name"
    METADATA
        "GML_FEATUREID" "feature_id"
        "OWS_ABSTRACT" "DAD ITEMS"
        "OWS_DATAURL_HREF" ""
        "OWS_EXTENT" "11.3548173872124 -4.98713486430294 35.0002746604481 4.23446608014632"
        "OWS_KEYWORDLIST" "continent@Africa,subcontinent@Eastern Africa,geographicarea@Uganda,serviceprovider@British Geological Survey,DS_TOPIC@geoscientificinformation"
        "OWS_TITLE" "DAD ITEMS"
        INCLUDE "commonLayerMD.map"
        "WFS_SRS" "EPSG:4326"
        "WMS_GROUP_ABSTRACT" "DAD DATA"
        "WMS_GROUP_TITLE" "DAD DATA"
    END
    NAME "DAD_ITEMS"
    TEMPLATE "tmpl/DAD_item_tpl.html"
    TYPE POLYGON
    INCLUDE "style/dad_item.map"
END
...

and ARGID-layer-config.map is like:

    # LAYER PROPERTIES COMMON TO MOST LAYERS
    CONNECTION "user='your-user' password='your-password' dbname='your-database' host='your-host' port='5432'"
    CONNECTIONTYPE postgis
    FOOTER "tmpl/ARGID_UPP_footer.html"
    # This header overides other headers
    HEADER "tmpl/ARGID_UPP_header.html"
    COMPOSITE
        OPACITY 100
    END
    PROCESSING "CLOSE_CONNECTION=DEFER"
    PROJECTION
        "init=epsg:4326"
    END
    SIZEUNITS PIXELS
    STATUS ON
    TOLERANCE 10
    TOLERANCEUNITS pixels
    TRANSFORM TRUE

There's quite a bit of config missing there, but it should be enough to show what you need for a WMS connecting to PostgreSQL.

I've created the map file as a set of includes as it's easier to manage if you have multiple services/layers that share the same details, but you could write it as one file if required.

Note we don't show the location of the map file in the service URL, that's handled by Apache

For more details on the map file options see the MapServer documentation:

https://mapserver.org/documentation.html#mapfile

For more details of the Apache/MapServer configuration see the OneGeology documentation:

http://www.onegeology.org/service_provision/server_setup/mapserver.html#general-configuration

  • Thanks for your answer. – B Cheng Wong Jul 6 at 3:00
  • Just want to know, is it anyway to PM you? I got some questions on your example need to ask. – B Cheng Wong Jul 6 at 3:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.