0

I have over 30 shp files which is named "street.shp" into the sub-folder. There is over 30 sub-folders. In the sub-folder, there is another shp files which may be named a building.shp...etc. I only want to merge the street.shp files. The structure of all street.shp is exactly same!

I tried this script -

for /R %f in (*.shp) do ogr2ogr -update -append merge.shp %f -f “esri shapefile” -nln merge 

How can the script find the shp file named "street.shp" only? Thanks a lot.

5
  • 1
    How can you have 30 shapefiles with the same name in a subfolder? Do you mean you have a lot of separate subfolders each of which may contain a street.shp? Perhaps you can edit the question to clarify the actual structure? Does for /R %f in (*\street.shp)... work in windows?
    – BradHards
    Commented Dec 10, 2013 at 4:24
  • Thanks BradHards, for /R %f in (*\street.shp) do ogr2ogr -update -append merge.shp %f -f “esri shapefile” -nln merge is not work! Commented Dec 10, 2013 at 5:50
  • 2
    You still haven't answered my question about the actual data structure. You also haven't told me what happens (other than the not-very-informative "not work"). Please edit your question.
    – BradHards
    Commented Dec 10, 2013 at 6:27
  • Updated! I tried "for /R %f in (*\street.shp) do ogr2ogr -update -append merge.shp %f -f “esri shapefile” -nln merge" (((No error message! The merge.shp is keep same!))) Commented Dec 10, 2013 at 6:54
  • OK, how about for /R %f in (*) do if exist(%f\street.shp) ogr2ogr -update -append merge.shp %f\street.shp -f “esri shapefile” -nln merge
    – BradHards
    Commented Dec 10, 2013 at 8:31

1 Answer 1

5

You should do it with:

for /R %f in (*street.shp) do ogr2ogr -update -append merge.shp %f -nln merge

Note: -f “esri shapefile” is useless here, because is default output format for ogr2ogr. So it can be avoided.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.