[postgis-users] Help with query

Mark mark.balman at gmail.com
Thu Nov 27 11:01:22 PST 2008


Hi All

I am currently trying to create a query to pass through to mapserver but 
am having a problem. Here is my scenario:

Two tables in postgresql

A quarter degree grid with 273600 records (spatial geometry) with GiST index on
the geometry and a btree index on FID

A species table with 10 million records (btree index on FID1) contains species ids with related
grid cell ids (essentially an intersect)

In mapserver I have defined the layer thus

LAYER
 CONNECTIONTYPE postgis
 NAME "SpcDensity"
 CONNECTION "user="" password="" dbname="" host=localhost"
 DATA "the_geom FROM (select spcdensity.fid_1, spcdensity.the_geom AS
the_geom, gid AS gid, spcgrid.spcid
from spcdensity, spcgrid
where spcdensity.fid_1 = spcgrid.fid) as myquery using SRID=4326 using
unique gid"
 STATUS OFF
 TYPE POLYGON
 TEMPLATE "templates/spc_header.html"
 CLASS
 NAME "density"
  OUTLINECOLOR 128 128 128
 END
 JOIN
    NAME "species"
    CONNECTION "host=localhost port=5432 user="" password="" dbname="""
    CONNECTIONTYPE ogr
    TABLE "spcgrid"
    FROM "fid_1"
    TO "fid"
    TYPE ONE-TO-ONE
  END
END

When I run this it works fine, click in a quarter degree grid cell and 
it returns a species ID using the one-to-one join but I need to get it 
to return the many species ids. Changing the join type to ONE-TO-MANY 
results in the error:

loadJoin(): Premature End-of-File. One-to-many joins must define template and name properties

If anyone has any suggestions as to how I can get this to work I would 
be most grateful.

Thanks in advance

Mark




More information about the postgis-users mailing list