<div dir="ltr">I have a large shapefile with over 2.8 million shapes (fishnet) and I have a border file with only 1 multipolygon.<div><br></div><div>I'm trying to clip the fishnet with the border.</div><div>Using code is takes about 5 min. using command line it takes even longer.<br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><div>This is my command:</div><div><font face="monospace, monospace">ogr2ogr fishnetClipped.shp fishnet.shp -clipsrc border.shp</font><br></div><div><br></div><div>And this is my C# code:</div><div><div><font face="monospace, monospace">using (var dsFishnet = Ogr.Open(fishnetFilename, 0))</font></div><div><font face="monospace, monospace">{</font></div><div><font face="monospace, monospace"> // Select first layer:</font></div><div><font face="monospace, monospace"> using (var layerFishnet = dsFishnet.GetLayerByIndex(0))</font></div><div><font face="monospace, monospace"> {</font></div><div><font face="monospace, monospace"> // Open border:</font></div><div><font face="monospace, monospace"> using (var dsBorder = Ogr.Open(borderFilename, 0))</font></div><div><font face="monospace, monospace"> {</font></div><div><font face="monospace, monospace"> // Select first layer:</font></div><div><font face="monospace, monospace"> using (var layerBorder = dsBorder.GetLayerByIndex(0))</font></div><div><font face="monospace, monospace"> {</font></div><div><font face="monospace, monospace"> // Get ESRI driver:</font></div><div><font face="monospace, monospace"> using (var driver = Ogr.GetDriverByName("ESRI Shapefile"))</font></div><div><font face="monospace, monospace"> {</font></div><div><font face="monospace, monospace"> // Create new shapefile:</font></div><div><font face="monospace, monospace"> using (var dsClipped = driver.CreateDataSource(outputFilename, new string[] { }))</font></div><div><font face="monospace, monospace"> {</font></div><div><font face="monospace, monospace"> // Create new layer:</font></div><div><font face="monospace, monospace"> var layerName = Path.GetFileNameWithoutExtension(outputFilename);</font></div><div><font face="monospace, monospace"> using (var layerClipped = dsClipped.CreateLayer(layerName, layerFishnet.GetSpatialRef(), layerFishnet.GetGeomType(), new string[] { }))</font></div><div><font face="monospace, monospace"> {</font></div><div><font face="monospace, monospace"> if (layerClipped == null)</font></div><div><font face="monospace, monospace"> {</font></div><div><font face="monospace, monospace"> throw new Exception("Layer creation failed.");</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> // Clip the layer:</font></div><div><font face="monospace, monospace"> layerFishnet.Clip(layerBorder, layerClipped, null, null, null);</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace"> }</font></div><div><font face="monospace, monospace">}</font></div></div><div><br></div><div>I'm using GDAL 2.1.3</div><div dir="ltr"><br></div><div dir="ltr">Can I somehow improve the speed?</div><div dir="ltr">I read something about putting one of the layers in memory or using a spatial filter.</div><div dir="ltr">But I can't find an example of how to do this.</div><div dir="ltr"><br></div><div dir="ltr">Please advise.</div><div dir="ltr"><br>Thanks,<br>Paul<br>
</div></div></div></div></div></div>
</div></div>