[gdal-dev] Tests if the geometry is within the other geometry

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] Tests if the geometry is within the other geometry

Ian-2
I have a shape file consisting of thousands of features/polygons.
I have to extract only those polygons which are within the reference polygon.

I tried as follows:
    
refpoly = feat.GetGeometryRef()  

fi =  'data.shp'
ids = ogr.Open(fi,0)
inlay = ids.GetLayer(0)
for feat in inlay:    
    ctype = feat.GetField('Name')
    geomi = feat.GetGeometryRef()
       if geomi.Within(refpoly):
           write ods....

But it is running for weeks and not yet finished.
How to do it faster?

thanks
Ian 

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Tests if the geometry is within the other geometry

mikeucfl
Use a spatial filter using your refpoly before iterating the features:
http://gdal.org/python/osgeo.ogr.Layer-class.html#SetSpatialFilter



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Tests if the geometry is within the other geometry

Ian-2
inlay.SetSpatialFilter(refpoy) did not meet my requirement of  "if geomi.Within(refpoly)".

if I use both  inlay.SetSpatialFilter(refpoy) and  geomi.Within(refpoly), speed is same as before.
.SetSpatialFilter tested intersect of the envelopes, which i do not need.
any idea is appreciated

On Sat, Jun 23, 2018 at 2:01 PM, Ian <[hidden email]> wrote:
after spatial filter, should i use  if geomi.Within(refpoly)?

On Sat, Jun 23, 2018 at 4:49 AM, mikeucfl <[hidden email]> wrote:
Use a spatial filter using your refpoly before iterating the features:
http://gdal.org/python/osgeo.ogr.Layer-class.html#SetSpatialFilter



--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev



_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Tests if the geometry is within the other geometry

Even Rouault-2
In reply to this post by Ian-2
On samedi 23 juin 2018 04:21:38 CEST Ian wrote:

> I have a shape file consisting of thousands of features/polygons.
> I have to extract only those polygons which are within the reference
> polygon.
>
> I tried as follows:
>
> refpoly = feat.GetGeometryRef()
>
> fi =  'data.shp'
> ids = ogr.Open(fi,0)
> inlay = ids.GetLayer(0)
> for feat in inlay:
>     ctype = feat.GetField('Name')
>     geomi = feat.GetGeometryRef()
>        if geomi.Within(refpoly):
>            write ods....
>
> But it is running for weeks and not yet finished.
> How to do it faster?

geomi.Within(refpoly) is equivalent to refpoly.Contains(geomi)

If you use Shapely and prepared geometry, and that refpoly is a rather complex
geometry, then making it a prepared geometry could speed up the contains test.

http://toblerity.org/shapely/manual.html#prepared-geometry-operations

Even

--
Spatialys - Geospatial professional services
http://www.spatialys.com
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev