getShape() and PostGIS Layers

Geodata Analysis info at E-GEODATA.GR
Fri Sep 23 02:09:20 EDT 2005


Hi list,
I had some problems accessing features from a dynamic postgis layer.
After some research i discovered that php/mapscript function
$layer->getShape(tileindex, shapeindex); does not have the expected
behaviour, at least the one I was expecting :-) . This is not about the
issue that shapeindex must begin from 1.

Here is my map file :
    MAP
        NAME "country"
        STATUS ON
        EXTENT 744723.842 4108421.689 757400.350 4121357.515
        SIZE 400 300
        SHAPEPATH "../data"
        SYMBOLSET "../etc/symbols.sym"
        FONTSET "../etc/fonts.txt"
        IMAGECOLOR 255 255 255
        UNITS METERS
        TRANSPARENT FALSE
        DEBUG ON
       WEB
        METADATA
            "wms_title"                     "country"
            "wms_onlineresource"
"http://127.0.0.1/cgi-bin/mapserv.exe?map=c:\ms4w\Apache\htdocs\mapscript\htdocs\mapfile.map&"
            "wms_srs"                      "EPSG:4121"
            "wfs_title"                       "country"
            "wfs_onlineresource"
"http://127.0.0.1/cgi-bin/mapserv.exe?"
            "wfs_srs"                       "EPSG:4121"
        END
        IMAGEPATH "/ms4w/tmp/ms_tmp/"
        IMAGEURL "/ms_tmp/"
      END
      PROJECTION
        "init=epsg:4121"
      END
    END

Here's my script :

    if (!extension_loaded( "mapscript" ))
        dl ("php_mapscript_46.dll" );

    $map = ms_newMapObj("mapfile.map");

    $layer = ms_newLayerObj($map);
    $layer->set("debug",               MS_ON);
    $layer->set("name",                "postgis_cities_layer");
    $layer->set("connectiontype", MS_POSTGIS);
    $layer->set("connection",       "user=postgres password=qwe123
dbname=leros host=localhost port=5432");
    $layer->set("status",               MS_ON);
    $layer->set("type",                 MS_POLYGON);
    $layer->set("sizeunits",           MS_METERS);
    $layer->set("toleranceunits",   MS_METERS);
    $layer->set("tolerance",         300);
    $layer->set("template",          "blank.html");
    $layer->set("data",                "the_geom from (SELECT * FROM
cities WHERE gid IN(5,6)) as foo using unique gid using srid=4121)");

    $layer->open();
    $shp_1 = $layer->getShape(-1, 1);
    $shp_2 = $layer->getShape(-1, 5);
    $layer->close();

    echo "<pre>";
    print_r($shp_1);
    print_r($shp_2);
    echo "</pre>";

    $c = ms_newClassObj($layer);
    $s = ms_newStyleObj($c);
    $s->color->setRGB(255, 0, 0);
    $img = $map->draw();
    $url = $img->saveWebImage();

    echo "<img src=\"$url\" />";


The image is drawn perfectly.

print_r($shp_1)  outputs nothing!
print_r($shp_2) outputs a shape!

In other words shapeindex in function  $layer->getShape(tileindex,
shapeindex) corresponds to gid column in the postgis table cities.

Is this the expected behaviour ?
Is there a way to do a loop and get all the shapes from a layer using
straightforward code?

-- 
Stathis Stergou
GIS Programmer
GeoDATA Analysis
Greece
www.geodata-analysis.gr



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the mapserver-users mailing list