ogr2ogr merging a directory of shapefiles into one shapefile

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ogr2ogr merging a directory of shapefiles into one shapefile

David Fawcett
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? 

Thanks,

David.

_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/
Reply | Threaded
Open this post in threaded view
|

Re: ogr2ogr merging a directory of shapefiles into one shapefile

Frank Warmerdam-2
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, [hidden email]
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org

_______________________________________________
FWTools mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/fwtools
http://fwtools.maptools.org/