[Mapserver-users] QueryByPoint on PostGIS layer

steff stephane.riff at cerene.fr
Thu Apr 24 02:24:08 PDT 2003


This is a multi-part message in MIME format.

------=_NextPart_000_0011_01C30A54.057944B0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all.
=20
My problem is :
=20
  I've got a postgis layer
=20
LAYER
  CONNECTIONTYPE postgis
  NAME "Contour_Departements"
  CONNECTION "dbname=3Ddb port=3D5555 user=3Dapache"
  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] =3D 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] =3D 1)
    SYMBOL "cross"
    SIZE 8
    OUTLINECOLOR 255 0 0
    COLOR 255 128 64
    TEMPLATE "itemquery_template.html"
  END
=20
  METADATA
   LYRNAME "Contour de D=E9partements"
   TABLE_NAME "giscontourdepartement"
   RESULT_FIELDS "area"
   WMS_SRS  "EPSG:27582"
   WMS_ORDER "2"
  END
=20
END
=20
=20
I want to query this layer with :
=20
    $nClickGeoX =3D pix2Geo($_SESSION["map_x"], 0, $map->width,$dfMinX, =
$dfMaxX,=20
0);
    $nClickGeoY =3D pix2Geo($_SESSION["map_y"], 0, $map->height,$dfMinY, =
$dfMaxY,=20
1);
    $oClickGeo =3D ms_newPointObj();
    $oClickGeo->setXY($nClickGeoX, $nClickGeoY);
    $err =3D @$map->queryByPoint($oClickGeo, MS_SINGLE, -1);
    if($err =3D=3D MS_SUCCESS)
    {
      $queryResults=3DTRUE;
      dumpQueryResults () ;
      print( "<script =
language=3D\"javascript\">parent.queryResult.window.location=20
=3D\"legend/queryResult.php\";</script>" );
    }
=20
=20
function dumpQueryResults()
{
    GLOBAL $map;
    $numResultsTotal =3D 0;
    $fp =3D fopen("legend/queryResult.php", "w+");
    for($iLayer=3D0; $iLayer < $map->numlayers; $iLayer++)
    {
        $oLayer =3D $map->GetLayer($iLayer);
        $numResults =3D $oLayer->getNumResults();
        if ($numResults =3D=3D 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 =3D explode(" ", =
$oLayer->getMetaData("RESULT_FIELDS"));    =20
        fwrite($fp,"<html>\n<body bgcolor=3D\"#ADCEED\">\n<TABLE =
BORDER=3D0=20
CELLSPACING=3D1 CELLPADDING=3D2
WIDTH=3D100%%>\n");
        fwrite($fp,"<TR>\n");
        fwrite($fp,"<TD COLSPAN=3D".sizeof($selFields)." =
BGCOLOR=3D#C1D8E3>");
        fwrite($fp,"<CENTER> ".$oLayer->getMetaData("LYRNAME")." =
</CENTER>" );
        fwrite($fp,"</TR>\n");=20
        //
        // Table header: attribute names...
        //
        fwrite($fp,"<TR>\n");=20
        for ($iField=3D0; $iField < sizeof($selFields); $iField++)
        {
            fwrite($fp,"<TD BGCOLOR=3D#E2EFF5>");
            fwrite($fp,"".$selFields[$iField]."");
            fwrite($fp,"</TD>");
        }
        fwrite($fp,"</TR>\n");
        //
        // One row in table for each selected record
        //
        for ($iRes=3D0; $iRes < $numResults; $iRes++)
        {
            $oRes =3D $oLayer->getResult($iRes);
            if($oRes !=3D FALSE)
            {
              $oShape =3D $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=3D0; $iField < sizeof($selFields); $iField++)
              {
                fwrite($fp,"<TD BGCOLOR=3D#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 =3D=3D 0)
        fwrite($fp,"Nothing found at query location.");
  fclose($fp);
}
=20
=20
But i get always the same error :
   Fatal error: Assertion failed, Could not set shape values: 0, 0
=20
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=20
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 |
=20
 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.  :)

------=_NextPart_000_0011_01C30A54.057944B0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial>Hi all.<BR> <BR>My problem is :<BR> <BR>  =
I've got a=20
postgis layer<BR> <BR>LAYER<BR>  CONNECTIONTYPE postgis<BR>  =
NAME=20
"Contour_Departements"<BR>  CONNECTION "dbname=3Ddb port=3D5555=20
user=3Dapache"<BR>  DATA "the_geom from =
giscontourdepartement"<BR>  TYPE=20
POLYGON<BR>  STATUS OFF<BR>  GROUP "Contour"<BR>#  FILTER =

"shapdpt_id LIKE '%value%%'"<BR>  HEADER blank.html<BR>  =
FOOTER=20
blank.html<BR>  CLASS<BR>    NAME=20
"Contour_Departements1"<BR>    EXPRESSION ([dept_id] =3D=20
0)<BR>    SYMBOL "star"<BR>    SIZE=20
8<BR>    OUTLINECOLOR 255 0 0<BR>    COLOR =
255 0=20
255<BR>    OVERLAYSYMBOL=20
"downwarddiagonalfill"<BR>    OVERLAYSIZE =
6<BR>   =20
OVERLAYCOLOR 0 0 0<BR>    TEMPLATE=20
"itemquery_template.html"<BR>  END<BR>  =
CLASS<BR>   =20
NAME "Contour_Departements2"<BR>    EXPRESSION ([dept_id] =
=3D=20
1)<BR>    SYMBOL "cross"<BR>    SIZE=20
8<BR>    OUTLINECOLOR 255 0 0<BR>    COLOR =
255 128=20
64<BR>    TEMPLATE "itemquery_template.html"<BR>  =
END<BR>=20
<BR>  METADATA<BR>   LYRNAME "Contour de=20
D=E9partements"<BR>   TABLE_NAME =
"giscontourdepartement"<BR>  =20
RESULT_FIELDS "area"<BR>   WMS_SRS  =
"EPSG:27582"<BR>  =20
WMS_ORDER "2"<BR>  END<BR> <BR>END<BR> <BR> <BR>I want to query =
this layer=20
with :<BR> <BR>    $nClickGeoX =3D =
pix2Geo($_SESSION["map_x"], 0,=20
$map->width,$dfMinX, $dfMaxX, <BR>0);<BR>    =
$nClickGeoY =3D=20
pix2Geo($_SESSION["map_y"], 0, $map->height,$dfMinY, $dfMaxY,=20
<BR>1);<BR>    $oClickGeo =3D=20
ms_newPointObj();<BR>    =
$oClickGeo->setXY($nClickGeoX,=20
$nClickGeoY);<BR>    $err =3D =
@$map->queryByPoint($oClickGeo,=20
MS_SINGLE, -1);<BR>    if($err =3D=3D=20
MS_SUCCESS)<BR>    {<BR>     =20
$queryResults=3DTRUE;<BR>      dumpQueryResults =
()=20
;<BR>      print( "<script=20
language=3D\"javascript\">parent.queryResult.window.location=20
<BR>=3D\"legend/queryResult.php\";</script>" =
);<BR>    }<BR>=20
<BR> <BR>function dumpQueryResults()<BR>{<BR>    GLOBAL=20
$map;<BR>    $numResultsTotal =3D =
0;<BR>    $fp =3D=20
fopen("legend/queryResult.php", "w+");<BR>    =
for($iLayer=3D0;=20
$iLayer < $map->numlayers; $iLayer++)<BR>   =20
{<BR>        $oLayer =3D=20
$map->GetLayer($iLayer);<BR>       =
=20
$numResults =3D=20
$oLayer->getNumResults();<BR>      &nbsp=
; if=20
($numResults =3D=3D=20
0)<BR>            =

continue;  // No results in this=20
layer<BR>        // Open layer's =
table...=20
take the list of fields to display from=20
<BR>        // the =
"HEADERRESULT_FIELDS"=20
metadata in the layer =
object.<BR>       =20
//$oLayer->open($map->shapepath);<BR>     =
  =20
$oLayer->open("");<BR>        =
$selFields =3D=20
explode(" ", =
$oLayer->getMetaData("RESULT_FIELDS"));    =20
<BR>       =20
fwrite($fp,"<html>\n<body bgcolor=3D\"#ADCEED\">\n<TABLE =
BORDER=3D0=20
<BR>CELLSPACING=3D1=20
CELLPADDING=3D2<BR>WIDTH=3D100%%>\n");<BR>    &nbs=
p;  =20
fwrite($fp,"<TR>\n");<BR>       =
=20
fwrite($fp,"<TD COLSPAN=3D".sizeof($selFields)."=20
BGCOLOR=3D#C1D8E3>");<BR>       =20
fwrite($fp,"<CENTER> ".$oLayer->getMetaData("LYRNAME")."=20
</CENTER>" );<BR>       =20
fwrite($fp,"</TR>\n"); =
<BR>       =20
//<BR>        // Table header: =
attribute=20
names...<BR>       =20
//<BR>        =
fwrite($fp,"<TR>\n");=20
<BR>        for ($iField=3D0; $iField =
<=20
sizeof($selFields); =
$iField++)<BR>       =20
{<BR>           =20
fwrite($fp,"<TD=20
BGCOLOR=3D#E2EFF5>");<BR>       &nb=
sp;   =20
fwrite($fp,"".$selFields[$iField]."");<BR>     &=
nbsp;     =20
fwrite($fp,"</TD>");<BR>        =

}<BR>       =20
fwrite($fp,"</TR>\n");<BR>      &nbsp=
;=20
//<BR>        // One row in table for =
each=20
selected record<BR>       =20
//<BR>        for ($iRes=3D0; $iRes =
<=20
$numResults; $iRes++)<BR>       =20
{<BR>            =
$oRes =3D=20
$oLayer->getResult($iRes);<BR>      &nbs=
p;    =20
if($oRes !=3D=20
FALSE)<BR>          &nb=
sp;=20
{<BR>           &n=
bsp; =20
$oShape =3D=20
$oLayer->getShape(-1,$oRes->shapeindex);<BR>   &nbsp=
;         =20
fwrite($fp,"<TR>\n");<BR>       =
      =20
//fwrite($fp,"<!--<BR>bounds(".$oShape->bounds->minx.",".$oShape=
->bounds->miny.")-<BR>(".$oShape->bounds->maxx.",."$oShape-&g=
t;bounds->maxy.")-->\n"<BR>);<BR>     &nbs=
p;       =20
for($iField=3D0; $iField < sizeof($selFields);=20
$iField++)<BR>         &nbsp=
;   =20
{<BR>           &n=
bsp;   =20
fwrite($fp,"<TD=20
BGCOLOR=3D#FFFFFF>");<BR>       &nb=
sp;       =20
fwrite($fp,"".$oShape->values[$selFields[$iField]]."");<BR> &nbsp=
;            =
 =20
fwrite($fp,"</TD>");<BR>       &=
nbsp;     =20
}<BR>           &n=
bsp; =20
fwrite($fp,"</TR>\n");<BR>      &nbsp=
;      =20
$oShape->free();<BR>        &n=
bsp;    =20
$numResultsTotal++;<BR>        &n=
bsp; =20
}<BR>       =20
}<BR>       =20
$oLayer->close();<BR>       =20
fwrite($fp,"</TABLE>\n</body>\n</html>\n");<BR> &n=
bsp; =20
}<BR>    if ($numResultsTotal =3D=3D=20
0)<BR>        fwrite($fp,"Nothing =
found at=20
query location.");<BR>  fclose($fp);<BR>}<BR> <BR> <BR>But i get =
always the=20
same error :<BR>   Fatal error: Assertion failed, Could not =
set shape=20
values: 0, 0<BR> <BR>I already look in the users-list but there is no=20
answer...<BR>The only answer is to use  layer->open(""); but i =
already=20
do this without <BR>result....<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I received a mail from <FONT =
face=3D"Times New Roman"=20
size=3D3>Daniel Morissette who told me he think it's a bug with shape =
creation=20
from postgis without attribute so numvalue and numitem are set to=20
0.</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman" =
size=3D3>but my table=20
structure is :</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3DArial =
size=3D2></FONT></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman" =
size=3D3> OID | GID=20
| DEPT_ID | AREA | THE_GEOM |<BR> <BR> So why numvalue is set to 0 =
i don't=20
know...</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman"=20
size=3D3></FONT></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman" =
size=3D3>-> i get=20
this work few month ago with mapserver 3.6.4 and postgres 7.2 now i'm =
using=20
mapserver 3.6.5 and postgres 7.3</FONT></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman" =
size=3D3>If someone=20
could help me.  :)</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><FONT face=3D"Times New Roman"=20
size=3D3></FONT> </DIV></FONT></BODY></HTML>

------=_NextPart_000_0011_01C30A54.057944B0--




More information about the MapServer-users mailing list