<div dir="ltr">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.<div>Speed is often a matter of using specific tools utilizing the characteristics of the problem, i.c. the fishnet regularities.<br><div>Can you share the shapesfiles so I can try?</div></div><div>Regards,</div><div>Jan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 11, 2017 at 11:09 AM, Paul Meems <span dir="ltr"><<a href="mailto:bontepaarden@gmail.com" target="_blank">bontepaarden@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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="m_-540461886953267944gmail_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(<wbr>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.<wbr>GetFileNameWithoutExtension(<wbr>outputFilename);</font></div><div><font face="monospace, monospace"> using (var layerClipped = dsClipped.CreateLayer(<wbr>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>
<br>______________________________<wbr>_________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/gdal-dev</a><br></blockquote></div><br></div>