[mapserver-users] MapScript ShapFileObj

Steve Lime Steve.Lime at dnr.state.mn.us
Thu Jul 16 16:47:59 EDT 2009


Most scripting languages have nice DBF interface modules already so we elected to leverage those
instead of writing one.  So, you'd need to find your favorite for PHP and use that to initialize a table
and add records. It's probably just a few additional lines of code as you've done most of the hard
work already.

Also, any one willing to help with documentation would be most welcome! (Should take that offer
to mapserver-dev...)

Steve

>>> On 7/16/2009 at 3:35 PM, in message <4A5F8F2E.1010707 at rogers.com>, Josh Hevenor
<jhevenor at rogers.com> wrote:
> I have a quick question about the ShapeFileObj class in PHP mapscript
> then I'd like to throw out an offer and see who wants to take me up on it.
> 
> First my question. I'm trying to write a quick data exporter. The
> general process is, query a spatial database, loop through the results
> and build a shapefile, export the shapefile. I'm not having any run-time
> failures but my result has only .SHP, .SHX files.  When I look at the
> shapefile in ogrinfo I see my points but no projection,  and when I use
> ogr2ogr to add a projection I see that there's no attribute
> information...only the points.
> 
> My code looks similar to this:
> 
> // Open map object
> $map = ms_newmapobj($mapPath);
> $layer = $map->getLayerByName($layerName);
> 
> // Create shapefileobj with random name
> $rnd = time();
> $filePath = "C:\\Inetpub\\wwwroot\\tmp\\Extract\\$rnd";
> $fileName = $filePath . "somename"; // no extension
> 
> $oShapeFile = ms_newShapefileObj($fileName, $layerType); // assume
> MS_SHP_POINT for this example
> 
> $status = $layer->open();
> $status = $layer->whichShapes($map->extent);
> while ($shape = $layer->nextShape())
> {  
>     $id = $shape->values[$idField];
>     echo "Adding shape with ID = $id\n";
>     $oShapeFile->addShape($shape);  
>     $shape->free();
> }
> $layer->close();
> $oShapeFile->free();
> 
> // zip up and return to browser
> 
> Any suggestions would be appreciated.
> 
> Now my offer.  I usually get by with the available documentation and a
> decent archive of old projects to compare from. The documentation for
> this object is pretty sparse:
> http://mapserver.org/mapscript/php/index.html#shapefileobj-class  The
> SWIG api doc looks about the same. I'd like to put together an example
> for each class function to flesh out the doc. If there are a lot of
> interested participants we could do all the classes,  but for now I'll
> start with ShapeFileObj.  If there's something like this on the go
> already, let me know how I can help.
> 
> Thanks,
> 
> Josh Hevenor



More information about the mapserver-users mailing list