Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
Thanks - that was helpful! I added the working example code to the original post. –  Kay Apr 30 '13 at 14:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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