Re: [gdal-dev] Problems with OGRGeometry Intersects
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.roua...@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 gabrielfu...@suremptec.com.ar http://www.suremptec.com/ ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Problems with OGRGeometry Intersects
Selon Gabriel Fusca gabrielfu...@suremptec.com.ar: 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. Good. pgeometry-Intersects(pquerypoly) Intersects perform a transformation to verify the intersection of the geometries? No. The geometries passed to Intersects (and all other methods that take 2 geometries as input) must be in the same SRS. So you have to transform one of them to the SRS of the other with TransformTo(). ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Problems with OGRGeometry Intersects
Hi, Thanks Even! This solves the problem! 2012/9/5 Even Rouault even.roua...@mines-paris.org Selon Gabriel Fusca gabrielfu...@suremptec.com.ar: 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. Good. pgeometry-Intersects(pquerypoly) Intersects perform a transformation to verify the intersection of the geometries? No. The geometries passed to Intersects (and all other methods that take 2 geometries as input) must be in the same SRS. So you have to transform one of them to the SRS of the other with TransformTo(). -- Gabriel Fusca SUR Emprendimientos Tecnológicos Perú 345 Piso 5to Oficina B (C1067AAG) Ciudad de Buenos Aires, Argentina Tel. +54 (11) 4342-2976/84 gabrielfu...@suremptec.com.ar http://www.suremptec.com/ ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
[gdal-dev] Problems with OGRGeometry Intersects
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? 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 gabrielfu...@suremptec.com.ar http://www.suremptec.com/ ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev
Re: [gdal-dev] Problems with OGRGeometry Intersects
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, ___ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev