Hi Yosuke,<br><br>  If you use MultiPolygon geometries (with your polygons as the parts), geos (via ogr or shapely) should be able to do the job in one go, which should speed things up considerably...<br><br>  Cheers,<br>   Simon<br>
 <br><br><div class="gmail_quote">On Sat, Nov 6, 2010 at 5:04 AM, yosuke kimura <span dir="ltr">&lt;<a href="mailto:yosukesabai@gmail.com">yosukesabai@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
All,<br>
<br>
I think I found what I should have been using.  pick a feature from<br>
one layer, use its geometry as an argument of SetSpatialFilter method<br>
of the other layer.  Seems to be yielding same answer quicker...<br>
<br>
Francis,<br>
<br>
Thank you for suggestion.  I looked at the Shapely documentation<br>
<a href="http://gispython.org/shapely/docs/1.0/manual.html" target="_blank">http://gispython.org/shapely/docs/1.0/manual.html</a> . It wasn&#39;t obvious<br>
to me advantage of the library over ogr, except that it looks more<br>
pythonic.  I even didn&#39;t find mention of layer vs. feature, and to<br>
solve my problem it is a step back to me?<br>
<div class="im"><br>
<br>
<br>
On Nov 5, 4:54 pm, Francis Markham &lt;<a href="mailto:u2546...@anu.edu.au">u2546...@anu.edu.au</a>&gt; wrote:<br>
&gt; If you&#39;re using Python, I&#39;d recommend checking out the shapely package (<a href="http://pypi.python.org/pypi/Shapely" target="_blank">http://pypi.python.org/pypi/Shapely</a>):<br>
&gt;<br>
&gt; You can load your shapefile using ogr, and then import the geometry to<br>
&gt; shapely where you can do the geometry predicate calculations:<br>
&gt;<br>
&gt; &gt;&gt;&gt; import ogr<br>
&gt; &gt;&gt;&gt; from shapely.wkb import loads<br>
&gt; &gt;&gt;&gt; source = ogr.Open(&quot;/tmp/world_borders.shp&quot;)<br>
&gt; &gt;&gt;&gt; borders = source.GetLayerByName(&quot;world_borders&quot;)<br>
&gt; &gt;&gt;&gt; feature = borders.GetNextFeature()<br>
&gt; &gt;&gt;&gt; loads(feature.GetGeometryRef().ExportToWkb())<br>
&gt;<br>
&gt; Good luck,<br>
&gt;<br>
&gt; Francis<br>
&gt;<br>
</div><div class="im">&gt; On 6 November 2010 06:08, yosuke kimura &lt;<a href="mailto:yosukesa...@gmail.com">yosukesa...@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; All,<br>
&gt;<br>
&gt; &gt; I am trying to calculate intersection of two polygon layers with<br>
&gt; &gt; polygons.  I searched threads, found following thread, and what I got<br>
&gt; &gt; was that OGR/GEOS provide me to intersection of two features, but I<br>
&gt; &gt; have to write something in order to perform this operation for two<br>
&gt; &gt; layers with multiple features.<br>
&gt;<br>
&gt; &gt; Open source vector geoprocessing libraries?<br>
</div>&gt; &gt;<a href="http://groups.google.com/group/gdal/browse_thread/thread/7b5a4f461a4d." target="_blank">http://groups.google.com/group/gdal/browse_thread/thread/7b5a4f461a4d.</a>..<br>
&gt;<br>
&gt; &gt; Intersect of two shapefiles<br>
&gt; &gt;<a href="http://groups.google.com/group/gdal/browse_thread/thread/4b178c776aec." target="_blank">http://groups.google.com/group/gdal/browse_thread/thread/4b178c776aec.</a>..<br>
<div class="im">&gt;<br>
&gt; &gt; My questions are:<br>
&gt;<br>
&gt; &gt; 1. Did I miss something?  Is there development of library which takes<br>
&gt; &gt; two polygon layers to calculate intersection or other basic geometry<br>
&gt; &gt; operations that i find in OGR?<br>
&gt;<br>
&gt; &gt; 2. Assuming no to above, I got started writing code using python<br>
&gt; &gt; binding.  Not having too much experience, I codes to go through all<br>
&gt; &gt; possible pair (complete bipartite), test with intersect, then run<br>
&gt; &gt; intersection if it returns true.  I am wondering there is faster way<br>
&gt; &gt; to do this.  I am thinking something like get envelope polygon of each<br>
&gt; &gt; feature first, and then test intersection of them and then perform<br>
&gt; &gt; intersect operation only when first test passes (i assume that it is<br>
&gt; &gt; easier to test intersect if there are only handful of vertices as<br>
&gt; &gt; oppose to hundreds of vertices in my case).<br>
&gt;<br>
&gt; &gt; Right now I am trying with layer of hundreds of thousands of polygons<br>
&gt; &gt; vs. thousands of polygon, and it seems to be taking 10s of hours to<br>
&gt; &gt; finish in my environment.<br>
&gt;<br>
&gt; &gt; Thank you,<br>
&gt;<br>
&gt; &gt; Yosuke Kimura<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; gdal-dev mailing list<br>
</div>&gt; &gt; <a href="mailto:gdal-...@lists.osgeo.org">gdal-...@lists.osgeo.org</a><br>
<div class="im">&gt; &gt;<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
</div>&gt; _______________________________________________<br>
&gt; gdal-dev mailing list<br>
&gt; gdal-...@lists.osgeo.orghttp://<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
<div><div></div><div class="h5">_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</div></div></blockquote></div><br>