7

I am trying to map data by querying a table called xyz. I need to show the the_geom data on the map.

I have below query in my MapServer .map file:

DATA "the_geom from xyz using unique id using SRID=xxxx"

I need to generate a shapefile in order to get the data. I have

SHAPEPATH "../data" defined in my .map file.

But I am not sure command I should write for generating shapefile for above query, I tried doing

/usr/local/pgsql/bin/pgsql2shp -f /home/name/public_html/proj/data/xyz -h xxx.xxx.xx.xx -u username -P passwrd dbname "select the_geom from xyz"

This generated some files which I have it in by data folder. But I see blank page on my webpage.

Please correct me!

  • 3
    You can validate the shapefile with other tools, like QGIS. But why not directly serve the data from postgis? – Mike T Oct 6 '14 at 20:59
  • Also try shp2img to try and generate output for MapServer. – Mike T Oct 7 '14 at 1:41
  • or if you really need a Shapefile than you should also consider ogr2ogr, more examples here – dmci Jan 12 '16 at 18:57
4
  1. You can render your data from PostgreSQL directly. Documentation here.

PostgreSQL layer example:

LAYER
  NAME "province"
  STATUS ON
  TYPE POLYGON
  CONNECTIONTYPE POSTGIS
  CONNECTION "host=127.0.0.1 port=5432 dbname=xyz user=postgres password=postgres"
  DATA "the_geom from xyz"
  CLASS
    STYLE
      COLOR 128 128 128
      ANTIALIAS true
    END
  END
END
  1. You can export data from PostgreSql to shapefile or other format use psql2shp

Convert from postgres like this:

$ pgsql2shp -f <path to output shapefile> -h <hostname> -u <username> -P <password> databasename "<query>"

For example (creates xyz.shp in current directory):

$ pgsql2shp -f xyz -h 127.0.0.1 -u postgres -P password postgres "SELECT name, the_geom FROM xyz"

Initializing... 
Done (postgis major version: 2).
Output shape: Polygon
Dumping: XXXXXXXXXXXXXXXXXXXX [23 rows]. 

And create Mapserver layer (documentation here) Note what you must change map EXTENT value, use the ogrinfo utility ogrinfo -al -so xyz.shp read more here.

Example mapfile:

MAP
  IMAGETYPE      GIF
  EXTENT         23.49 59.3 23.60 59.68
  SIZE           400 400
  SHAPEPATH      "/home/name/public_html/proj/data/"
  IMAGECOLOR     255 255 255

  LAYER
    NAME         veget
    DATA         Poltava10_Vegetation_region
    STATUS       ON
    TYPE         POLYGON
    CLASS
      STYLE
        COLOR    25 210 12
      END
    END
  END
END

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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