Opened 21 years ago
Closed 21 years ago
#316 closed defect (fixed)
[PHP MapScript] Error with GetShape() on PostGIS layer
Reported by: | dmorissette | Owned by: | assefa |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | MapScript-PHP | Version: | 4.0 |
Severity: | normal | Keywords: | |
Cc: | jchiantera@… |
Description
There seems to be a problem when using the PHP MapScript getShape() method on PostGIS layers (could this happen with shapefiles too???). The function _phpms_build_shape_object() in php_mapscript.c isn't prepared to receive shapes with shape->numvalues==0 and that's quite likely what we're receiving. This will have to be investigated, here is the original report with all the details: ---------- Subject: [Mapserver-users] phpmapscript getShape ??? Date: Fri, 11 Apr 2003 14:33:25 +0200 From: "steff" <stephane.riff@cerene.fr> To: <mapserver-users@lists.gis.umn.edu> 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.... So help me please
Change History (5)
comment:2 by , 21 years ago
Cc: | added |
---|
comment:4 by , 21 years ago
The PostGIS connector doesnt actually pull un-used columns. In general, a: DATA "the_geom from roads using unique gid" will only pull the 'the_geom' and 'gid' from the database. This leaves the mapserver feature with only geometry, an id, but no attributes.
comment:5 by , 21 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
corrected php_mapscipt r1.71 pLayer->numitems is set to -1 when there are no attributes and pshape->numvalues is set to 0. Modufy the test to take this into account.
Note:
See TracTickets
for help on using tickets.