[gdal-dev] Geometry overlap test

Even Rouault even.rouault at mines-paris.org
Fri Apr 23 16:20:02 EDT 2010


Alexandre,

Overlap has a very particular meaning. See 
http://postgis.refractions.net/documentation/manual-1.5/ST_Overlaps.html

Your 2 polygons intersects well, but they do not "overlap" because the 
intersection is equal to geometry 1... 

Best regards,

Even

Le Friday 23 April 2010 21:29:02 Sorokine, Alexandre, vous avez écrit :
> 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()); }
>
> }
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev




More information about the gdal-dev mailing list