[gdal-dev] Geometry overlap test
Sorokine, Alexandre
sorokina at ornl.gov
Fri Apr 23 15:29:02 EDT 2010
Hi!
I noticed that Geometry.Overlaps in ogr sometimes returns "no overlap" while intersection is not empty. For example:
Geometry 1:POLYGON ((-1 -1,-1 1,1 1,1 -1,-1 -1))
boundaryLINESTRING (-1 -1,-1 1,1 1,1 -1,-1 -1)
Geometry 2:POLYGON ((-2 -2,-2 2,2 2,2 -2,-2 -2))
boundaryLINESTRING (-2 -2,-2 2,2 2,2 -2,-2 -2)
Overlaps? NO
Intrsects? YES
Intersection: POLYGON ((-1 -1,-1 1,1 1,1 -1,-1 -1))
This contradicts description of the overlap method in geos or am I doing something wrong?
The Java code to reproduce the condition attached.
--
Alex Sorokine
sorokina at ornl.gov
==== cut here ====
import org.gdal.ogr.Geometry;
import org.gdal.ogr.ogr;
public class OverlapTest {
public static void main(String[] args) {
Geometry lr1 = new Geometry(ogr.wkbLinearRing);
lr1.AddPoint_2D(-1.0, -1.0);
lr1.AddPoint_2D(-1.0, 1.0);
lr1.AddPoint_2D( 1.0, 1.0);
lr1.AddPoint_2D( 1.0, -1.0);
lr1.AddPoint_2D(-1.0, -1.0);
Geometry geom1 = new Geometry(ogr.wkbPolygon);
geom1.AddGeometry(lr1);
System.out.println("Geometry 1:" + geom1.ExportToWkt());
System.out.println(" boundary" + geom1.GetBoundary().ExportToWkt());
Geometry lr2 = new Geometry(ogr.wkbLinearRing);
lr2.AddPoint_2D(-2.0, -2.0);
lr2.AddPoint_2D(-2.0, 2.0);
lr2.AddPoint_2D( 2.0, 2.0);
lr2.AddPoint_2D( 2.0, -2.0);
lr2.AddPoint_2D(-2.0, -2.0);
Geometry geom2 = new Geometry(ogr.wkbPolygon);
geom2.AddGeometry(lr2);
System.out.println("Geometry 2:" + geom2.ExportToWkt());
System.out.println(" boundary" + geom2.GetBoundary().ExportToWkt());
System.out.print("Overlaps? ");
if (geom1.Overlaps(geom2)) System.out.println("YES");
else System.out.println("NO");
System.out.print("Intrsects? ");
if (geom1.Intersect(geom2)) System.out.println("YES");
else System.out.println("NO");
System.out.println("Intersection: " + geom1.Intersection(geom2).ExportToWkt());
}
}
More information about the gdal-dev
mailing list