Thread: do you have an easy example of postgis and mapserver?

do you have an easy example of postgis and mapserver?

From
Ottavio Campana
Date:
Hi,

I'm sorry this mail is not very in topic, but I hope you can help me.

I'm trying to learn how postgis and mapserver work together, but I
cannot understand nearly anything. I mean, I read the documentation of
postgis and I think I understood it, but I cannot do anything useful
with it.

What I'd like to do is storing some polygons in a database and writing
some scripts in python which extract those polygons and draw an image,
given a zoom level and a position.

Do you know some good documentation? Or a working example would be great.

Thank you.


Attachment

Re: do you have an easy example of postgis and mapserver?

From
Bill Thoen
Date:
On Tue, Aug 21, 2007 at 12:44:49PM +0200, Ottavio Campana wrote:
> I'm sorry this mail is not very in topic, but I hope you can help me.

Just so you know, perhaps a better list to contact with this is the
MapServer mailing list at
http://lists.umn.edu/archives/mapserver-users.html, or maybe the PostGIS
list at http://www.postgis.org/mailman/listinfo/postgis-users.

> I'm trying to learn how postgis and mapserver work together, but I
> cannot understand nearly anything. I mean, I read the documentation of
> postgis and I think I understood it, but I cannot do anything useful
> with it.

I think before you try to do something customized with python you should
get familiar the mapserver MAP file which contains all the instructions to
map features from various sources like shape files, MapInfo TAB files,
PostGIS data sources, and so on. An example for mapping a layer from a
PostGIS source in a MAP file looks like this:

  LAYER
    NAME states
    TYPE POLYGON
    STATUS ON
    CONNECTION "user=gisuser password=******* dbname=us_data host=localhost
port=5432"
    CONNECTIONTYPE POSTGIS
    DATA "the_geom from states"
    CLASSITEM 'name'
    PROJECTION
      "+proj=latlong +datum=WGS84"
    END
    CLASS
      NAME "US States"
      OUTLINECOLOR 0 0 0
      COLOR 255 255 196
    END
  END

The key bits here related to PostGIS are the CONNECTION, where you specify
all the info needed to get access to your PostgreSQL database, the
CONNECTIONTYPE which you set to POSTGIS, and the DATA directive in which
you supply a string that contains the SQL expression that pulls out the
geometry features you want to map.

If you do this with python, then you would first need to create an instance
of a mapObj, and then create a layerObj and add it to the map object,
setting the properties for the connection. However, my knowledge of this
approach is still very sketchy.

Documentation is spread around, but the two sites you should peruse are
the MapServer docs at: http://mapserver.gis.umn.edu/docs and the PostGIS docs
at: http://postgis.refractions.net/docs/.

- Bill Thoen