I cannot find any solid info on this and its a pretty rudimentry GIS process.
I have 2 shapefiles. One shapefiles is a single large polygon. The other is a larger multipolygon.
I need to clip the multipolygon to the extents of the smaller polygon. None of the multipolygons are completely outside of the clipping polygon.
I can do this quite easily in Arc/QGIS/MsPaint/Whatever but this has to be done in python and using OGR.
import os, sys, csv from osgeo import ogr ## Input inDataSource = driver.Open('OAs_Temp.shp', 0) inLayer = inDataSource.GetLayer() ## Clip inClipSource = driver.Open('_convexhull.shp', 0) inClipLayer = inClipSource.GetLayer() ## Clipped Shapefile... Maybe??? outDataSource = driver.CreateDataSource('FINAL.shp') outLayer = outDataSource.CreateLayer('FINAL.shp', geom_type=ogr.wkbMultiPolygon) featureDefn = outLayer.GetLayerDefn() outFeature = ogr.Feature(featureDefn) ogr.Layer.Clip(inLayer, inClipLayer, outLayer) outFeature.SetGeometry(outLayer) outLayer.CreateFeature(outFeature)
Issue is with
TypeError: in method 'Feature_SetGeometry', argument 2 of type 'OGRGeometryShadow *'
The problem is that I just can't figure out how OGR is doing things and what it wants. I am finding that cookbook thing pretty lacklustre and incomplete and the documentation is not very clear on how any of this works. It is some of the most convoluted open source libraries I have ever worked with and I regret taking this project on.
This is my last option. As always.