[postgis-users] Create a Thematic grid map with postgresql

Brent Wood pcreso at pcreso.com
Thu Nov 18 15:37:42 PST 2004


--- Paul Ramsey <pramsey at refractions.net> wrote:

> Brent Wood wrote:
> 
> > I'm not sure exactly how you did this, but it would be nice to compare.
> (OGR
> > support for GMT vectors would be nice :-) How did you extract the PostGIS
> data
> > for use with GMT? I have a Perl script which sort of works, but if you have
> a
> > PostGIS function to do this I'd love to see it!
> 
> Interesting idea, the GMT documentation sure is silent about input file 
> formats. Foof. I could not find anything useful at all.

If you look at the man pages for commands like psxy or psxyz it does describe
it (they are online on the GMT docs page as http://gmt.soest.hawaii.edu if you
don't have GMT installed)

Basically:

X0 Y0 [Z] [...]
X1 Y1 ...
...

So each point (or vertex) is on a new line. Columns after the Z Y [Z] can be
used for setting display attributes. If you use the -M option, then the
sequence of points is split at the specified lines to create a multi segment
line when plotting

eg:

> this is the first line segment
X0 Y0 ...
Xn Yn ...
...
> and now the second
X0 Y0 ...
Xn Yn ...
...
> and so on...

There are a number of issues which make PostGIS <> GMT non-trivial. Mainly the
lack of topology or hole/island polygons support in GMT.

I resolved this in the perl script by having a Z value in the PostGIS export as
"ring no". So I can grep all the non #1 rings & plot in GMT as an overlay on
the #1 rings to "look" like holes in the #1 rings. (Hope this makes sense :-)

Each multipolygon becomes several distinct polygons, with any holes as #2+ in
the output GMT file.

It wasn't thought through as atidy or elegant approach, just a simple way of
turning a WKT output file into something I can plot with GMT, & use 

psql $DB -t -a -c "..."  | wktTogmt | grep "1$" | psxy ....
  to plot the main polygons, or
cat <file> | wktTogmt | grep -v "1$" | psxy
  to overlay the holes.... 


Works for me, but if a more embedded/elegant approach is available I'll buy the
beers !!!


Cheers,

  Brent



More information about the postgis-users mailing list