[udig-devel] Problems comparing two geometries from diferent type of files

Jesse Eichar jeichar at refractions.net
Tue Jul 24 15:25:03 PDT 2007


Also make sure they are in the same projection.

Jesse
On Jul 24, 2007, at 2:06 PM, Schmitt, Magna (CIP) wrote:

> Hi
> I am trying to compare 2 geometries from different files (one of  
> them is a shapefile) and i would like to compare them if their  
> coordinates match together or one of them contains the other.
>
> 1. I use 2 files: one is a shapefile and the other a gridfile  
> (raster map).
> 2. I can easily extract the geometry from the shapefile, but for  
> the gridfile i have to create one for each coordinate i read from  
> the file.
> Coordinate m0 = new Coordinate();
> m0.x = resX;
> m0.y = resY;
> GeometryFactory gF = new GeometryFactory();
> gF.createPoint(m0);
> Geometry geometry = gF.toGeometry(new Envelope(m0));	
>
> 3. Then i have to compare the two geometries:
> if((geoShape.contains((geometry)))||(geometry.touches((geoShape)))){
> 	System.out.println("at last!!!");//print a message
> }
>
> 4. The problem i have is that my 'if' clause is never true like if  
> there are no geometries related. (I have checked the data)
>
> Here the complete extract of the code:
> / 
> ********************************************************************** 
> /
> URL urlMask = fShapeMask.toURL();
> ShapefileDataStore shpMask = new ShapefileDataStore(urlMask);
> FeatureSource fSourceMask = shpMask.getFeatureSource();
> FeatureCollection fColMask = fSourceMask.getFeatures();
> FeatureIterator it = fColMask.features();
> 		
> while(it.hasNext()){
> 	    	Feature featurePoint = (Feature) it.next();
> 	    	geoShape = featurePoint.getDefaultGeometry();
> 			    	
> 	    	minX = geoShape.getEnvelopeInternal().getMinX();
> 	    	maxX = geoShape.getEnvelopeInternal().getMaxX();
> 	    	minY = geoShape.getEnvelopeInternal().getMinY();
>             maxY = geoShape.getEnvelopeInternal().getMaxY();
>      }
> Coordinate m0 = new Coordinate();
> m0.x = resX;
> m0.y = resY;
> GeometryFactory gF = new GeometryFactory();
> gF.createPoint(m0);
> Geometry geometry = gF.toGeometry(new Envelope(m0));			    				
> if((geoShape.contains((geometry)))||(geometry.touches((geoShape)))){
> 	System.out.println("at last!!!");
> }
> / 
> ********************************************************************** 
> /
> Do you have an advice?
> Many thanks,
> Magna
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel



More information about the udig-devel mailing list