[postgis-users] questions about shape file

Gilles Bassière gilles.bassiere at makina-corpus.com
Thu Oct 18 02:22:13 PDT 2007


Ludovico Bianchini wrote:
> Hi,
> these are not strictly linked with postgis, but regard shape file, 
> maybe here I can find help.
>  
> 1) Is there a tool to build an union of shape files? Not an index 
> file, but a new shape file containing all the features of the shapes 
> used as sources.
> 2) Is there a tool to extract features from a shape file using an 
> attribute of .dbf table as filter? and saving these extracted features 
> in a new shape file?
> ------------------------------------------------------------------------
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>   

I guess ogr2ogr should fulfil your requirements. It's a powerful command 
line interface to the OGR library.

In order to merge 2 shapefiles a.shp and b.shp you could do something like:
ogr2ogr -f "ESRI Shapefile" new.shp a.shp
ogr2ogr -f "ESRI Shapefile" -append new.shp b.shp
(The above assumes your shapefiles format are equivalent, see below if 
it's not the case)

You can also do some complex transformation using a SQL-like syntax with 
the '-where' and '-select'. For example, if your input dataset has 2 
fields 'columnA' and 'columnB' and you want only 'columnB' in output, 
you could do:
ogr2ogr -f "ESRI Shapefile" -select "columnB" new.shp input.shp

Just issue a 'man ogr2ogr' command to check syntax and available option 
(also available online: http://www.gdal.org/ogr/ogr2ogr.html)

Cheers,

-- 
Gilles Bassiere
MAKINA CORPUS
30 rue des Jeuneurs
FR-75011 PARIS
http://www.makina-corpus.com




More information about the postgis-users mailing list