If you&#39;re using Python, I&#39;d recommend checking out the shapely package ( <a href="http://pypi.python.org/pypi/Shapely">http://pypi.python.org/pypi/Shapely</a> ): <br><br>You can load your shapefile using ogr, and then import the geometry to shapely where you can do the geometry predicate calculations:<br>

<pre class="code-block python literal-block"><span class="o">&gt;&gt;&gt;</span> <span class="k">import</span> <span class="nn">ogr</span><br><span class="o">&gt;&gt;&gt;</span> <span class="k">from</span> <span class="nn">shapely.wkb</span> <span class="k">import</span> <span class="n">loads</span><br>

<span class="o">&gt;&gt;&gt;</span> <span class="n">source</span> <span class="o">=</span> <span class="n">ogr</span><span class="o">.</span><span class="n">Open</span><span class="p">(</span><span class="s">&quot;/tmp/world_borders.shp&quot;</span><span class="p">)</span><br>

<span class="o">&gt;&gt;&gt;</span> <span class="n">borders</span> <span class="o">=</span> <span class="n">source</span><span class="o">.</span><span class="n">GetLayerByName</span><span class="p">(</span><span class="s">&quot;world_borders&quot;</span><span class="p">)</span><br>

<span class="o">&gt;&gt;&gt;</span> <span class="n">feature</span> <span class="o">=</span> <span class="n">borders</span><span class="o">.</span><span class="n">GetNextFeature</span><span class="p">()</span><br><span class="o">&gt;&gt;&gt;</span> <span class="n">loads</span><span class="p">(</span><span class="n">feature</span><span class="o">.</span><span class="n">GetGeometryRef</span><span class="p">()</span><span class="o">.</span><span class="n">ExportToWkb</span><span class="p">())</span></pre>

<br>Good luck,<br><br>Francis<br><br><div class="gmail_quote">On 6 November 2010 06:08, 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 am trying to calculate intersection of two polygon layers with<br>
polygons.  I searched threads, found following thread, and what I got<br>
was that OGR/GEOS provide me to intersection of two features, but I<br>
have to write something in order to perform this operation for two<br>
layers with multiple features.<br>
<br>
Open source vector geoprocessing libraries?<br>
<a href="http://groups.google.com/group/gdal/browse_thread/thread/7b5a4f461a4db319/" target="_blank">http://groups.google.com/group/gdal/browse_thread/thread/7b5a4f461a4db319/</a><br>
<br>
Intersect of two shapefiles<br>
<a href="http://groups.google.com/group/gdal/browse_thread/thread/4b178c776aecf425/" target="_blank">http://groups.google.com/group/gdal/browse_thread/thread/4b178c776aecf425/</a><br>
<br>
My questions are:<br>
<br>
1. Did I miss something?  Is there development of library which takes<br>
two polygon layers to calculate intersection or other basic geometry<br>
operations that i find in OGR?<br>
<br>
2. Assuming no to above, I got started writing code using python<br>
binding.  Not having too much experience, I codes to go through all<br>
possible pair (complete bipartite), test with intersect, then run<br>
intersection if it returns true.  I am wondering there is faster way<br>
to do this.  I am thinking something like get envelope polygon of each<br>
feature first, and then test intersection of them and then perform<br>
intersect operation only when first test passes (i assume that it is<br>
easier to test intersect if there are only handful of vertices as<br>
oppose to hundreds of vertices in my case).<br>
<br>
Right now I am trying with layer of hundreds of thousands of polygons<br>
vs. thousands of polygon, and it seems to be taking 10s of hours to<br>
finish in my environment.<br>
<br>
Thank you,<br><font color="#888888">
<br>
Yosuke Kimura
</font><br>_______________________________________________<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></blockquote></div><br>