[Mapserver-users] QueryByPoint on PostGIS layer
Paul Ramsey
pramsey at refractions.net
Thu Apr 24 08:11:20 PDT 2003
There is a known problem with PgSQL 7.3 and mapserver querying. We have
a patch out with alpha testers. Dave will commit it to CVS when he gets
back from vacation in a couple weeks.
Sorry,
Paul
steff wrote:
> Hi all.
>
> My problem is :
>
> I've got a postgis layer
>
> LAYER
> CONNECTIONTYPE postgis
> NAME "Contour_Departements"
> CONNECTION "dbname=db port=5555 user=apache"
> DATA "the_geom from giscontourdepartement"
> TYPE POLYGON
> STATUS OFF
> GROUP "Contour"
> # FILTER "shapdpt_id LIKE '%value%%'"
> HEADER blank.html
> FOOTER blank.html
> CLASS
> NAME "Contour_Departements1"
> EXPRESSION ([dept_id] = 0)
> SYMBOL "star"
> SIZE 8
> OUTLINECOLOR 255 0 0
> COLOR 255 0 255
> OVERLAYSYMBOL "downwarddiagonalfill"
> OVERLAYSIZE 6
> OVERLAYCOLOR 0 0 0
> TEMPLATE "itemquery_template.html"
> END
> CLASS
> NAME "Contour_Departements2"
> EXPRESSION ([dept_id] = 1)
> SYMBOL "cross"
> SIZE 8
> OUTLINECOLOR 255 0 0
> COLOR 255 128 64
> TEMPLATE "itemquery_template.html"
> END
>
> METADATA
> LYRNAME "Contour de Départements"
> TABLE_NAME "giscontourdepartement"
> RESULT_FIELDS "area"
> WMS_SRS "EPSG:27582"
> WMS_ORDER "2"
> END
>
> END
>
>
> I want to query this layer with :
>
> $nClickGeoX = pix2Geo($_SESSION["map_x"], 0, $map->width,$dfMinX,
> $dfMaxX,
> 0);
> $nClickGeoY = pix2Geo($_SESSION["map_y"], 0, $map->height,$dfMinY,
> $dfMaxY,
> 1);
> $oClickGeo = ms_newPointObj();
> $oClickGeo->setXY($nClickGeoX, $nClickGeoY);
> $err = @$map->queryByPoint($oClickGeo, MS_SINGLE, -1);
> if($err == MS_SUCCESS)
> {
> $queryResults=TRUE;
> dumpQueryResults () ;
> print( "<script
> language=\"javascript\">parent.queryResult.window.location
> =\"legend/queryResult.php\";</script>" );
> }
>
>
> function dumpQueryResults()
> {
> GLOBAL $map;
> $numResultsTotal = 0;
> $fp = fopen("legend/queryResult.php", "w+");
> for($iLayer=0; $iLayer < $map->numlayers; $iLayer++)
> {
> $oLayer = $map->GetLayer($iLayer);
> $numResults = $oLayer->getNumResults();
> if ($numResults == 0)
> continue; // No results in this layer
> // Open layer's table... take the list of fields to display from
> // the "HEADERRESULT_FIELDS" metadata in the layer object.
> //$oLayer->open($map->shapepath);
> $oLayer->open("");
> $selFields = explode(" ",
> $oLayer->getMetaData("RESULT_FIELDS"));
> fwrite($fp,"<html>\n<body bgcolor=\"#ADCEED\">\n<TABLE BORDER=0
> CELLSPACING=1 CELLPADDING=2
> WIDTH=100%%>\n");
> fwrite($fp,"<TR>\n");
> fwrite($fp,"<TD COLSPAN=".sizeof($selFields)." BGCOLOR=#C1D8E3>");
> fwrite($fp,"<CENTER> ".$oLayer->getMetaData("LYRNAME")."
> </CENTER>" );
> fwrite($fp,"</TR>\n");
> //
> // Table header: attribute names...
> //
> fwrite($fp,"<TR>\n");
> for ($iField=0; $iField < sizeof($selFields); $iField++)
> {
> fwrite($fp,"<TD BGCOLOR=#E2EFF5>");
> fwrite($fp,"".$selFields[$iField]."");
> fwrite($fp,"</TD>");
> }
> fwrite($fp,"</TR>\n");
> //
> // One row in table for each selected record
> //
> for ($iRes=0; $iRes < $numResults; $iRes++)
> {
> $oRes = $oLayer->getResult($iRes);
> if($oRes != FALSE)
> {
> $oShape = $oLayer->getShape(-1,$oRes->shapeindex);
> fwrite($fp,"<TR>\n");
> //fwrite($fp,"<!--
> bounds(".$oShape->bounds->minx.",".$oShape->bounds->miny.")-
> (".$oShape->bounds->maxx.",."$oShape->bounds->maxy.")-->\n"
> );
> for($iField=0; $iField < sizeof($selFields); $iField++)
> {
> fwrite($fp,"<TD BGCOLOR=#FFFFFF>");
> fwrite($fp,"".$oShape->values[$selFields[$iField]]."");
> fwrite($fp,"</TD>");
> }
> fwrite($fp,"</TR>\n");
> $oShape->free();
> $numResultsTotal++;
> }
> }
> $oLayer->close();
> fwrite($fp,"</TABLE>\n</body>\n</html>\n");
> }
> if ($numResultsTotal == 0)
> fwrite($fp,"Nothing found at query location.");
> fclose($fp);
> }
>
>
> But i get always the same error :
> Fatal error: Assertion failed, Could not set shape values: 0, 0
>
> I already look in the users-list but there is no answer...
> The only answer is to use layer->open(""); but i already do this without
> result....
> I received a mail from Daniel Morissette who told me he think it's a bug
> with shape creation from postgis without attribute so numvalue and
> numitem are set to 0.
> but my table structure is :
>
> OID | GID | DEPT_ID | AREA | THE_GEOM |
>
> So why numvalue is set to 0 i don't know...
>
> -> i get this work few month ago with mapserver 3.6.4 and postgres 7.2
> now i'm using mapserver 3.6.5 and postgres 7.3
>
> If someone could help me. :)
>
--
__
/
| Paul Ramsey
| Refractions Research
| Email: pramsey at refractions.net
| Phone: (250) 885-0632
\_
More information about the MapServer-users
mailing list