2

I'm batch extracting features from shp-files in a directory with this bash script: Is there a way to avoid the loop? I somewhere read that you can process folders but I was not able to get the right syntax..

# Author: Kay Cichini
# Date: 30-04-2013
# Purpose: Extract features by input extent for all shp-files in current dir 
#          and save to new file
# Extent Tirol in EPSG:3035 - ETRS89 / ETRS-LAEA
# from D:\GIS_DataBase\GIS_Tirol\Tirol_Extent_LEAE-ETRS.shp
# xMin,yMin 4328054.73,2617730.23 : xMax,yMax 4547691.32,2739524.35

ext='4328054.73 2617730.23 4547691.32 2739524.35'
mydir=D:/GIS_DataBase/CorineLC/Vector_Data

cd $mydir

for x in *.shp
  do 
  echo trying to write new_$x to $mydir 
  echo extent of input file is 
  ogrinfo -al $x | grep Extent
  echo new file is extracted by extent $ext
  echo ..........
  ogr2ogr new_$x -spat $ext $x
done

Here's the working example:

thanks to the links shared by @DMCI

# Author: Kay Cichini
# Date: 30-04-2013
# Purpose: Extract shp-file features in {infolder} by input extent 
#          and save new shp-files to {outfolder} that is created on the fly
# Extent Tirol in EPSG:3035 - ETRS89 / ETRS-LAEA
# from D:\GIS_DataBase\GIS_Tirol\Tirol_Extent_LEAE-ETRS.shp
# xMin,yMin 4328054.73,2617730.23 : xMax,yMax 4547691.32,2739524.35

infolder=D:/GIS_DataBase/CorineLC/Single_Zips
outfolder=C:/Users/Kay/Desktop/Test_GIS/new

ext='4328054.73 2617730.23 4547691.32 2739524.35'

ogr2ogr -overwrite $outfolder -spat $ext $infolder
Kay
  • 1,856
  • 17
  • 28

1 Answers1

1

This link seems to address your question. It should be possible to do as follows ogr2ogr -spat $ext output source as described here.

dmci
  • 4,882
  • 2
  • 19
  • 31
  • Thanks - that was helpful! I added the working example code to the original post. – Kay Apr 30 '13 at 14:19