/** * Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any. The * innermost enclosing ring is the <i>smallest</i> enclosing ring. The algorithm used depends on * the fact that: <br> * ring A contains ring B iff envelope(ring A) contains envelope(ring B) <br> * This routine is only safe to use if the chosen point of the hole is known to be properly * contained in a shell (which is guaranteed to be the case if the hole does not touch its shell) * * @return containing EdgeRing, if there is one or null if no containing EdgeRing is found */ public static EdgeRing findEdgeRingContaining(EdgeRing testEr, List shellList) { LinearRing testRing = testEr.getRing(); Envelope testEnv = testRing.getEnvelopeInternal(); Coordinate testPt = testRing.getCoordinateN(0); EdgeRing minShell = null; Envelope minShellEnv = null; for (Iterator it = shellList.iterator(); it.hasNext(); ) { EdgeRing tryShell = (EdgeRing) it.next(); LinearRing tryShellRing = tryShell.getRing(); Envelope tryShellEnv = tryShellRing.getEnvelopeInternal(); // the hole envelope cannot equal the shell envelope // (also guards against testing rings against themselves) if (tryShellEnv.equals(testEnv)) continue; // hole must be contained in shell if (!tryShellEnv.contains(testEnv)) continue; testPt = CoordinateArrays.ptNotInList(testRing.getCoordinates(), tryShellRing.getCoordinates()); boolean isContained = false; if (CGAlgorithms.isPointInRing(testPt, tryShellRing.getCoordinates())) isContained = true; // check if this new containing ring is smaller than the current minimum ring if (isContained) { if (minShell == null || minShellEnv.contains(tryShellEnv)) { minShell = tryShell; minShellEnv = minShell.getRing().getEnvelopeInternal(); } } } return minShell; }
/** * Ensure Line crosses the other Line at a node. * * <p> * * @param layers a HashMap of key="TypeName" value="FeatureSource" * @param envelope The bounding box of modified features * @param results Storage for the error and warning messages * @return True if no features intersect. If they do then the validation failed. * @throws Exception DOCUMENT ME! * @see org.geotools.validation.IntegrityValidation#validate(java.util.Map, * com.vividsolutions.jts.geom.Envelope, org.geotools.validation.ValidationResults) */ public boolean validate(Map layers, Envelope envelope, ValidationResults results) throws Exception { boolean r = true; FeatureSource<SimpleFeatureType, SimpleFeature> fsLine = (FeatureSource<SimpleFeatureType, SimpleFeature>) layers.get(getLineTypeRef()); FeatureCollection<SimpleFeatureType, SimpleFeature> fcLine = fsLine.getFeatures(); FeatureIterator<SimpleFeature> fLine = fcLine.features(); FeatureSource<SimpleFeatureType, SimpleFeature> fsRLine = (FeatureSource<SimpleFeatureType, SimpleFeature>) layers.get(getRestrictedLineTypeRef()); FeatureCollection<SimpleFeatureType, SimpleFeature> fcRLine = fsRLine.getFeatures(); while (fLine.hasNext()) { SimpleFeature line = fLine.next(); FeatureIterator<SimpleFeature> fRLine = fcRLine.features(); Geometry lineGeom = (Geometry) line.getDefaultGeometry(); if (envelope.contains(lineGeom.getEnvelopeInternal())) { // check for valid comparison if (LineString.class.isAssignableFrom(lineGeom.getClass())) { while (fRLine.hasNext()) { SimpleFeature rLine = fRLine.next(); Geometry rLineGeom = (Geometry) rLine.getDefaultGeometry(); if (envelope.contains(rLineGeom.getEnvelopeInternal())) { if (LineString.class.isAssignableFrom(rLineGeom.getClass())) { if (lineGeom.intersects(rLineGeom)) { if (!hasPair( ((LineString) lineGeom).getCoordinateSequence(), ((LineString) rLineGeom).getCoordinateSequence())) { results.error( rLine, "Line does not intersect line at node covered by the specified Line."); r = false; } } else { results.warning(rLine, "Does not intersect the LineString"); } // do next. } else { fcRLine.remove(rLine); results.warning( rLine, "Invalid type: this feature is not a derivative of a LineString"); } } else { fcRLine.remove(rLine); } } } else { results.warning(line, "Invalid type: this feature is not a derivative of a LineString"); } } } return r; }
public Iterable<Tuple2<Integer, Point>> call(Iterator<Point> s) throws Exception { // int id=-1; ArrayList<Tuple2<Integer, Point>> list = new ArrayList<Tuple2<Integer, Point>>(); while (s.hasNext()) { Point currentElement = s.next(); Integer id = 0; for (int j = 0; j < gridNumberVertical; j++) { for (int i = 0; i < gridNumberHorizontal; i++) { Envelope currentGrid = new Envelope( gridHorizontalBorder[i], gridHorizontalBorder[i + 1], gridVerticalBorder[j], gridVerticalBorder[j + 1]); /*if(currentElement.getX()>=gridHorizontalBorder[i] && currentElement.getX()<=gridHorizontalBorder[i+1] && currentElement.getY()>=gridVerticalBorder[j] && currentElement.getY()<=gridVerticalBorder[j+1]) { id=i*gridNumberHorizontal+j; list.add(new Tuple2(id,currentElement)); }*/ if (currentGrid.intersects(currentElement.getCoordinate()) || currentGrid.contains(currentElement.getCoordinate())) { // id=j*gridNumberHorizontal+i; list.add(new Tuple2(id, currentElement)); } id++; } } } return list; }
@Override public void visitElement(int row, Envelope env) { fired = true; try { assertTrue(env.contains(ds.getGeometry(row).getEnvelopeInternal())); } catch (DriverException ex) { fail(); } }
public void highlightVertex(Vertex v) { Coordinate c = v.getCoordinate(); double xd = 0, yd = 0; while (!modelBounds.contains(c)) { xd = modelBounds.getWidth() / 100; yd = modelBounds.getHeight() / 100; modelBounds.expandBy(xd, yd); } modelBounds.expandBy(xd, yd); highlightedVertex = v; drawLevel = DRAW_ALL; }
void insertNode(Node node) { Assert.isTrue(env == null || env.contains(node.env)); // System.out.println(env); // System.out.println(quad.env); int index = getSubnodeIndex(node.env, centrex, centrey); // System.out.println(index); if (node.level == level - 1) { subnode[index] = node; // System.out.println("inserted"); } else { // the quad is not a direct child, so make a new child quad to contain it // and recursively insert the quad Node childNode = createSubnode(index); childNode.insertNode(node); subnode[index] = childNode; } }
Expression clipToWorld(BinarySpatialOperator filter, Expression e) { if (e instanceof Literal) { Geometry eval = e.evaluate(filter, Geometry.class); // Oracle cannot deal with filters using geometries that span beyond the whole world // in case the if (dialect != null && isCurrentGeometryGeodetic() && !WORLD.contains(eval.getEnvelopeInternal())) { Geometry result = eval.intersection(JTS.toGeometry(WORLD)); if (result != null && !result.isEmpty()) { if (result instanceof GeometryCollection) { result = distillSameTypeGeometries((GeometryCollection) result, eval); } e = new FilterFactoryImpl().createLiteralExpression(result); } } } return e; }
/** * Tests whether a point lies in the envelopes of both input segments. A correctly computed * intersection point should return <code>true</code> for this test. Since this test is for * debugging purposes only, no attempt is made to optimize the envelope test. * * @return <code>true</code> if the input point lies within both input segment envelopes */ private boolean isInSegmentEnvelopes(Coordinate intPt) { Envelope env0 = new Envelope(inputLines[0][0], inputLines[0][1]); Envelope env1 = new Envelope(inputLines[1][0], inputLines[1][1]); return env0.contains(intPt) && env1.contains(intPt); }
/* * (non-Javadoc) * * @see org.geotools.data.shapefile.shp.ShapeHandler#read(java.nio.ByteBuffer, * org.geotools.data.shapefile.shp.ShapeType) */ public Object read(ByteBuffer buffer, ShapeType type) { if (type == ShapeType.NULL) { return null; } // read bounding box Envelope geomBBox = GeometryHandlerUtilities.readBounds(buffer); if (!bbox.intersects(geomBBox)) { return null; } boolean bboxdecimate = geomBBox.getWidth() <= spanx && geomBBox.getHeight() <= spany; int numParts = buffer.getInt(); double[][] coords = new double[numParts][]; double[][] transformed = new double[numParts][]; // if bbox is less than a pixel then decimate the geometry. But // orientation must // remain the same so geometry data must be parsed. if (bboxdecimate) { coords = new double[1][]; coords[0] = new double[2]; transformed = new double[1][]; transformed[0] = new double[2]; coords[0][0] = buffer.getDouble(); coords[0][1] = buffer.getDouble(); try { mt.transform(coords[0], 0, transformed[0], 0, 1); } catch (Exception e) { ShapefileRenderer.LOGGER.severe( "could not transform coordinates " + e.getLocalizedMessage()); transformed[0] = coords[0]; } if (screenMap.get((int) transformed[0][0], (int) transformed[0][1])) { LOGGER.finest("Point already rendered" + transformed[0][0] + " " + transformed[0][1]); return null; } screenMap.set((int) transformed[0][0], (int) transformed[0][1], true); } else { int partsInBBox = 0; for (int part = 0; part < numParts; part++) { coords[part] = new double[2]; coords[part][0] = buffer.getDouble(); coords[part][1] = buffer.getDouble(); if (!bbox.contains(coords[part][0], coords[part][1])) continue; if (!mt.isIdentity()) { try { transformed[partsInBBox] = new double[2]; mt.transform(coords[part], 0, transformed[partsInBBox], 0, 1); } catch (Exception e) { ShapefileRenderer.LOGGER.severe( "could not transform coordinates " + e.getLocalizedMessage()); transformed[partsInBBox] = coords[part]; } } else { transformed[partsInBBox] = new double[2]; System.arraycopy(coords[part], 0, transformed[partsInBBox], 0, 1); } if (!screenMap.get((int) transformed[partsInBBox][0], (int) transformed[partsInBBox][1])) partsInBBox++; } if (partsInBBox == 0) return null; if (partsInBBox != numParts) { double[][] tmp = new double[partsInBBox][]; System.arraycopy(transformed, 0, tmp, 0, partsInBBox); transformed = tmp; } } return createGeometry(type, geomBBox, transformed); }