[gdal-dev] Problems with OGRGeometry Intersects

Gabriel Fusca gabrielfusca at suremptec.com.ar
Wed Sep 5 05:56:30 PDT 2012


Hi,

Thanks for the answer.

> OGRPoint querypoint = OGRPoint(Point.x_, Point.y_);
> querypoint.assignSpatialReference(new OGRSpatialReference(SrWkt.c_str()));

It is not necessary to transform the query point because the Point is at
the same spatial reference system.

> pgeometry->Intersects(pquerypoly)

Intersects perform a transformation to verify the intersection of the
geometries? The two geometries (the one that came from the point and the
other that want to intersect) have two different spatial reference systems.

point -> EPSG 4326 (GEO)
other geometry -> (WGS 84 / > UTM zone 21S) (PROJ)

Thanks,
Regards,


2012/9/4 Even Rouault <even.rouault at mines-paris.org>

> Le mardi 04 septembre 2012 23:04:16, Gabriel Fusca a écrit :
> > Hi,
> >
> > I'm using Gdal 1.9.
> >
> > I have a function that has to perform a intersection of a geometry based
> on
> > the click that is made on the screen.
> >
> > The raster file (Geotiff) that has a projected reference system (WGS 84 /
> > UTM zone 21S)  and the geometry a georeferenced system (EPSG - 4326
> WGS84).
> >
> > The click that comes from the screen (spatial reference of the image)
> > create a geometry from calling point.Buffer (radius).
> >
> > When i want to verify that the geometries intersect the intersects method
> > from OGRGeometry fails, even if the querypoint is transformed into the
> > spatial reference system of the geometry.
> >
> > Envelopes from the 2 geometries.
> > QueryPoint
> > env.
> > if i generates the querypoint from the spatial reference of the geometry
> > that i want to intersect)
> > minx -61.66, maxx -53.66;
> > miny -41.97, maxy -33.97
> > else
> > minx 443322.50, maxx 443330.50
> > miny 5798153.59, maxy 5798161.59
> >
> > Geometry env.
> > minx -57.79, maxx -57.59;
> > miny -38.08, maxy-37.92
> >
> >
> > The code is something like this:
> >
> > // spatialfilterwindow image subset transformed into
> > // the spatial reference of the vector to intersect
> > Extent spatialfilter(spatialfilterwindow);
> > player->SetSpatialFilterRect(spatialfilter.min_.x_,
> >                             spatialfilter.min_.y_,
> >                             spatialfilter.max_.x_,
> >                             spatialfilter.max_.y_);
> > OGRLayer* player = ...;
> > OGRFeature *pfeature = player->GetNextFeature();
> > OGRPoint querypoint = OGRPoint(Point.x_, Point.y_);
> > querypoint.assignSpatialReference(new
> OGRSpatialReference(SrWkt.c_str()));
> > OGRGeometry* pquerypoly = querypoint.Buffer(radius);
> >  *while *(pfeature) {
> >     OGRGeometry *pgeometry = pfeature->GetGeometryRef();
> >     *if *((pgeometry && pgeometry->Intersects(pquerypoly) == TRUE)
> >
> >         || (pquerypoly && pquerypoly->Intersects(pgeometry) == TRUE)) {
> >
> >         // do something...
> >     } *else *{
> >         // handle the intersection fail
> >     }
> >     pfeature = player->GetNextFeature();
> > }
> >
> > Any idea why it fails?
>
> I suspect that you assumed assignSpatialReference() would do the
> reprojection,
> which isn't the case (it just blindly assigns the specified SRS, but
> doesn't
> alter the geometry coordinates). You must use the TransformTo() method
> instead.
>
> Incidental comment : you don't need to test ( A->Insersects(B) || B-
> >Insersects(A)). Intersects() is a symetrical operation, so just one test
> will
> be enough.
>
> >
> > Thanks,
> > Regards,
>



-- 
Gabriel Fusca
SUR Emprendimientos Tecnológicos

Perú 345  Piso 5to Oficina "B" (C1067AAG)
Ciudad de Buenos Aires, Argentina
Tel. +54 (11) 4342-2976/84
gabrielfusca at suremptec.com.ar
http://www.suremptec.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120905/bc72baf3/attachment-0001.html>


More information about the gdal-dev mailing list