[Mapserver-users] Problem with Mascript ShapeObj.values array

Daniel Morissette morissette at dmsolutions.ca
Thu Oct 2 16:07:20 EDT 2003


I am no PostGIS expert, but I would expect that the values[] array would
return only the fields that are explicitly selected either via your DATA
string or via things like CLASSITEM, LABELITEM, etc.

In your case, your DATA statement selects only the geometry, and then
CLASSITEM and LABELITEM add "name" and "type".  "gid" may be pulled by
default by the postgis driver I'm not sure.  If you want "value" then
you'll probably have to add it to the DATA statement.

Daniel

Stefano Bonnin wrote:
> Hi,
> 
> I'm trying to get information from Postgis with PHPMapscript
> 
> This is my layer definition:
> 
> LAYER
> NAME "Percolato"
> METADATA
> "LYRNAME"       "Percolato"
> "DESCRIPTION" "P.O.I2"
> "TABLE" "edtlyr_percolato_1"
> "QUERY_FIELDS"  "gid,name,value,type"
> "RESULT_FIELDS" "Nome,ID,Tipo"
> END
> GROUP "P.O.I"
> STATUS ON
> DATA "the_geom from edtlyr_percolato_1"
> TYPE point
> CONNECTIONTYPE POSTGIS
> CONNECTION "user=user dbname=dbname"
> MAXSCALE 7000
> MINSCALE 0
> LABELITEM "name"
> LABELMAXSCALE 3500
> CLASSITEM "type"
> CLASS
> CLASS
>         NAME "a"
>         EXPRESSION 'a'
>         SYMBOL "prelievoperco"
>         COLOR 255 255 255
>         SIZE 15
>         TEMPLATE "blank.html"
>         LABEL
>                 BACKGROUNDCOLOR 0 0 0
>                 FONT "arial"
>                 TYPE TRUETYPE
>                 POSITION lc
>                 MINSIZE 10
>                 MAXSIZE 25
>                 COLOR 255 255 255
>                 BACKGROUNDSHADOWCOLOR 128 128 128
>                 ANTIALIAS true
>         END
> END
> END
> 
> And this is my PHPMapscript code (It can be wrong because I have extracted
> some line with cut and past):
> 
> .....
> .....
> $oLayer = $gpoMap->GetLayer($iLayer);
> $numResults = $oLayer->getNumResults();
> 
> $oLayer->open();
> $resultFields = explode(",", $oLayer->getMetaData("RESULT_FIELDS"));
> 
> for ($iRes=0; $iRes < $numResults; $iRes++) {
>         $oRes = $oLayer->getResult($iRes);
>         $oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);
> 
>         fwrite($fp, "<TR>\n");
>         for($iField=0; $iField < sizeof($queryFields); $iField++) {
> 
>                         if ($queryFields[$iField] == 'gid') {
>                                 $gid =
> $oShape->values[$queryFields[$iField]];
>                          }
>                         else if ($queryFields[$iField] == 'name') {
>                                 $pname =
> $oShape->values[$queryFields[$iField]];
>                         }
>                         else if ($queryFields[$iField] == 'type') {
>                                 $pname =
> $oShape->values[$queryFields[$iField]];
>                         }
>                         else if ($queryFields[$iField] == "value") {
>                                 $vl =
> $oShape->values[$queryFields[$iField]];
>                         }
> 
>     }
> }
> ......
> ......
> 
> 
> The tree first variables $gid, $pname and $vl has a correct value
> 
> BUT
> 
> the last one ($vl) has NO VALUE.
> 
> The $oShape->values length is 3.
> Why the array length is only 3?
> 
> My postgres table has the following attributes: "the_geom", "value","type",
> "name" and "gid".
> 
> Thanks in advance.
> 
> 







More information about the mapserver-users mailing list