[FWTools] ogr2ogr merging a directory of shapefiles into one shapefile

Frank Warmerdam warmerdam at pobox.com
Fri Nov 3 12:25:41 EST 2006


David Fawcett wrote:
> I am sure that this is an obvious one, but I can't seem to figure out a 
> syntax (as usual!). 
> 
> Is there a way to use ogr2ogr to take a directory of shapefiles and 
> append their features into an existing shapefile? I have been playing 
> with using directory names, -update -append, etc. and can't seem to find 
> a solution. 
> 
> Let's say that:
> 
> d:/myInDir/    is the input directory
> file_merge.shp is the target shapefile and it is sitting in 
> d:/myInDir/output/  
> 
> 
> OR, do I get the opportunity to write a quick Python script to do it? 

David,

There is no way to do them all automatically, but you can do them one file
at a time with a command like:

  ogr2ogr -update -append myInDir\output\file_merge.shp  myInDir\abc.shp

You might need to add "-nln file_merge".

Of course, all the files have to have the same geometry type, and the same
attributes.

Let me know if this doesn't work.

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    | President OSGeo, http://osgeo.org



More information about the FWTools mailing list