[gdal-dev] How to identify a point is belong to a polygon ?

Chaitanya kumar CH chaitanya.ch at gmail.com
Thu Jul 19 23:11:51 PDT 2012


Tai,

You can use the spatial filter of the ogr layer to filter the point
features to speed things up. You will still have to test if the point is
within the polygon but it will be faster.

Also, make sure the test is like point->Within(polygon) and not
polygon->Within(point)

OGRLayer::SetSpatialFilter()
http://www.gdal.org/ogr/classOGRLayer.html#a0b4ab45cf97cbc470f0d60474d3e4169

On Fri, Jul 20, 2012 at 9:29 AM, Bui Chi Tai <taibc_coltech at yahoo.com>wrote:

> Chaitanya,
>
> I am checking my code. Maybe it is not successful because I used two
> different layers (of one file).
>
> As you know, one .dgn files only has one layer, that include many
> features, and Texts (Point Geometry), Polygons are treated as features.
> My idea is:
> First, I will read each feature to identify whether this feature is a
> polygon. Then, I need to use a loop to read and check all features of layer
> to identify whether a Text (point) is belong to that polygon. But, this
> will affect to the first reading times, and give unexpected result.
>
> Do you have any ideas ?
>
> Thanks and regards,
>
> Tai
>   ------------------------------
> *From:* Chaitanya kumar CH <chaitanya.ch at gmail.com>
> *To:* Bui Chi Tai <taibc_coltech at yahoo.com>
> *Sent:* Friday, July 20, 2012 10:39 AM
>
> *Subject:* Re: [gdal-dev] How to identify a point is belong to a polygon ?
>
> Tai,
>
> I don't understand why it would happen. Can you provide some more details?
> Code, data?
>
> On Fri, Jul 20, 2012 at 9:05 AM, Bui Chi Tai <taibc_coltech at yahoo.com>wrote:
>
> Thanks Chaitanya,
>
> I am trying to use this method. But, it is not successful.
>
> For example: One file .dgn includes Text (treated as a point geometry) and
> Shapes (Polygon).
>
> I used the method OGRGeometry::Within(OGRGeometry * other) to identify
> whether the Text is belong to the polygon. But it doesn't return an
> expected result (Actually, there are some texts that belong to each
> polygon).
>
> Kind regards,
>
> Tai
>
>    ------------------------------
> *From:* Chaitanya kumar CH <chaitanya.ch at gmail.com>
> *To:* taibc <taibc_coltech at yahoo.com>
> *Cc:* gdal-dev at lists.osgeo.org
> *Sent:* Friday, July 20, 2012 10:11 AM
> *Subject:* Re: [gdal-dev] How to identify a point is belong to a polygon ?
>
> Tai,
>
> You can use OGR_G_Within()
> OGR_G_WIthin(point,polygon) will return true if the point is within the
> polygon.
>
> You can access various other geometry functions from the OGRGeometry class.
>
> http://www.gdal.org/ogr/ogr__api_8h.html#a80ba9e516ccae381ae7240cc9684eb72
>
> On Fri, Jul 20, 2012 at 7:04 AM, taibc <taibc_coltech at yahoo.com> wrote:
>
> Hi everyone,
>
> Do you know how to identify whether a point (OGRPoint) is belong to a
> polygon (OGRPolygon) ? (the polygon covers the point)
>
> Thanks and regards,
>
> Tai
>
> --
> View this message in context:
> http://osgeo-org.1560.n6.nabble.com/How-to-identify-a-point-is-belong-to-a-polygon-tp4989501.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com<http://nabble.com/>
> .
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
>
>
>
> --
> Best regards,
> Chaitanya kumar CH.
>
> +91-9494447584
> 17.2416N 80.1426E
>
>
>
>
>
> --
> Best regards,
> Chaitanya kumar CH.
>
> +91-9494447584
> 17.2416N 80.1426E
>
>
>


-- 
Best regards,
Chaitanya kumar CH.

+91-9494447584
17.2416N 80.1426E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120720/de92c05d/attachment.html>


More information about the gdal-dev mailing list