Can't really help you with the OGR part, however, I wrote utilities do solve this (really) fast for calculating grids based on this type of intersection. Speed is often a matter of using specific tools utilizing the characteristics of the problem, i.c. the fishnet regularities. Can you share the shapesfiles so I can try? Regards, Jan
On Mon, Sep 11, 2017 at 11:09 AM, Paul Meems <[email protected]> wrote: > I have a large shapefile with over 2.8 million shapes (fishnet) and I have > a border file with only 1 multipolygon. > > I'm trying to clip the fishnet with the border. > Using code is takes about 5 min. using command line it takes even longer. > > This is my command: > ogr2ogr fishnetClipped.shp fishnet.shp -clipsrc border.shp > > And this is my C# code: > using (var dsFishnet = Ogr.Open(fishnetFilename, 0)) > { > // Select first layer: > using (var layerFishnet = dsFishnet.GetLayerByIndex(0)) > { > // Open border: > using (var dsBorder = Ogr.Open(borderFilename, 0)) > { > // Select first layer: > using (var layerBorder = dsBorder.GetLayerByIndex(0)) > { > // Get ESRI driver: > using (var driver = Ogr.GetDriverByName("ESRI Shapefile")) > { > // Create new shapefile: > using (var dsClipped = > driver.CreateDataSource(outputFilename, > new string[] { })) > { > // Create new layer: > var layerName = Path.GetFileNameWithoutExtension( > outputFilename); > using (var layerClipped = > dsClipped.CreateLayer(layerName, > layerFishnet.GetSpatialRef(), layerFishnet.GetGeomType(), new string[] { })) > { > if (layerClipped == null) > { > throw new Exception("Layer creation > failed."); > } > > // Clip the layer: > layerFishnet.Clip(layerBorder, layerClipped, > null, null, null); > } > } > } > } > } > } > } > > I'm using GDAL 2.1.3 > > Can I somehow improve the speed? > I read something about putting one of the layers in memory or using a > spatial filter. > But I can't find an example of how to do this. > > Please advise. > > Thanks, > Paul > > _______________________________________________ > gdal-dev mailing list > [email protected] > https://lists.osgeo.org/mailman/listinfo/gdal-dev >
_______________________________________________ gdal-dev mailing list [email protected] https://lists.osgeo.org/mailman/listinfo/gdal-dev
