2008年10月15日 星期三

Error executing POSTGIS DECLARE (the actual query) statement

What is this?
-----8<-------8<-------
msDrawMap(): Image handling error. Failed to draw layer named 'bc_voting_areas'. prepare_database(): Query error. Error executing POSTGIS DECLARE (the actual query) statement: 'DECLARE mycursor BINARY CURSOR FOR SELECT asbinary(force_collection(force_2d(the_geom)),'NDR'),OID::text from bc_voting_areas WHERE the_geom && setSRID('BOX3D(1421927.909699 176424,2103636.090301 687278)'::BOX3D, find_srid('','bc_voting_areas','the_geom') )' Postgresql reports the error as 'ERROR: column "oid" does not exist LINE 1: ...inary(force_collection(force_2d(the_geom)),'NDR'),OID::text ... ^ ' More Help: Error with POSTGIS data variable. You specified 'check your .map file'. Standard ways of specifiying are : (1) 'geometry_column from geometry_table' (2) 'geometry_column from (sub query) as foo using unique column name using SRID=srid#' Make sure you put in the 'using unique column name' and 'using SRID=#' clauses in. For more help, please see http://postgis.refractions.net/documentation/ Mappostgis.c - version of Jan 23/2004. msPOSTGISLayerRetrievePGVersion(): Query error. Error executing POSTGIS statement (msPOSTGISLayerRetrievePGVersion():select substring(version() from 12 for (position('on' in version()) - 13))
-----8<-------8<-------

I try to connect PostGIS using Mapserver with sample database from PostGIS. My map file is as follows:

# Start of LAYER DEFINITIONS ---------------------------------------------
LAYER
CONNECTIONTYPE postgis
NAME "bc_voting_areas"
CONNECTION "user=postgres password=postgres dbname=tester host=localhost port=5432"
DATA "the_geom FROM bc_voting_areas"
STATUS ON
TYPE POLYGON
CLASS
COLOR 255 255 200
END
END
# End of LAYER DEFINITIONS -------------------------------

I have verified the above layer definition thousand times and don't know what happen.
Then, I have to read the error message again and again to see what can I do. Just spot a strange message "ERROR: column "oid" does not exist LINE 1:" meaning the system is looking for "oid" but it does not exist. I go to check the table. Bingo, no "oid". It seems this is the cause, but why there is no "oid" populated?

Finally, thank to the Internet, I've found the following message:

> New version of Postgresql (8.1) does not create OID column by default
> when creating a table (oid is globally unique identifiers used by
> Postgresql and also used by Mapserver to uniquely identify a row of
> result).
>
> My solution was to enable oid-generation in postgresql, by editing the
> postgresql.conf (in the postgresql/8.1/data folder)
> Search for "default_with_oids", uncomment the line and set the
> variable value to "on".
> Then, regenerate your postgis tables.


Then I check the postgis documentation again and find a section called "Using Mapserver". I think I should have read it before starting the test.

The cause is that there is missing oid and I need to create it for mapserver as it requires oid to work properly. Then I run the following two commands to create and index oid in the bc_voting_areas table.

1. alter table bc_voting_areas add column oid serial;
This command adds a new serial column called oid in the table.

2. create index bc_voting_areas_oidx on bc_voting_areas (oid);
This simply creates a new index.

I can output a map with the following link finally.

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/postgis/postgis.map&layer=bc_voting_areas&mode=map

Cheers... Keep exploring postgis, postgres and mapserver.

沒有留言: