2

I'm looking for a way to get the intersection area between my shapefiles. Basically, I got three shapefiles from my .tif files like this:

gdaltindex a.shp a.tif
gdaltindex b.shp b.tif
gdaltindex c.shp c.tif

This way I got the area of my .tif files. Now I would like to get a new shapefile via intersection. I thought about using gdalwarp, for example like this:

gdalwarp -cutline intersection.shp a.tif a_intersection.tif
gdalwarp -cutline intersection.shp b.tif b_intersection.tif
gdalwarp -cutline intersection.shp c.tif c_intersection.tif

but i can't figure out how to get the intersection.shp file I can do it via QGIS, but would like to do it directly from GDAL. How can I do this?

1 Answer 1

0

I don't think you can do this with GDAL, but you can create the intersection shapefile with mapshaper's -mosaic.

With the following, you

  • read in all shapefiles
  • mosaic them together, so all overlaps are converted into their own feature
  • calculate the number of overlaps for each feature
  • sort the features, and get the one with the most overlaps
mapshaper -i *.shp combine-files -merge-layers -mosaic calc='OVERLAPS=count()' -sort 'OVERLAPS' descending -filter 'this.id==0' -o intersection.shp

To simplify things, you could use

gdaltindex footprints.shp *.tif
mapshaper footprints.shp -mosaic calc='OVERLAPS=count()' -sort 'OVERLAPS' descending -filter 'this.id==0' -o intersection.shp

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.