[mapserver-users] editing shp files

Frank Warmerdam warmerdam at pobox.com
Tue Jul 30 10:23:47 EDT 2002


Paul Spencer wrote:
> If you are adventurous, you could get openev 
> (http://openev.sourceforge.net) and write a simple python script to 
> process your shapefile
> 
> sample python script:
> 
> import gview
> 
> shapes_in = gview.GvShapes( shapefilename="/path/to/my/shapefile" )
> shapes_out = gview.GvShapes()
> 
> #assuming you want the same schema
> shapes_out.set_properties( shapes_in.get_properties() )
> 
> for shape in shapes_in:
>    props = shape.get_properties()
>    #this would test against the first character
>    if props['postalcode'][:1] == 'V':
>        shapes_out.append( shape.copy() )
> 
> shapes_out.save_as( "/path/to/new/shapefile" )
> 
> If you are interested but aren't a python programmer, I could probably 
> help you with this as long as you can get openev installed.

Seamus,

In fact, if all you want to do is select some of the records from a shapefile
based on attributes, you could try using the ogr2ogr utility from GDAL/OGR.
It includes the ability to select records to copy based on an SQL WHERE like
syntax.

eg.

ogr2ogr -select "post_address like '%British Columbia%'" bc.shp all.shp

Of course, Paul's OpenEV/python solution is even more flexible than ogr2ogr
on its own.  Ogr2ogr is part of the GDAL/OGR suite.

   http://www.remotesensing.org/gdal
   http://gdal.velocet.ca/projects/opengis

Best regards,

-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent





More information about the mapserver-users mailing list