/** * update the IM with the sum of the IMs for each component */ private void updateIM(IntersectionMatrix im) { //Debug.println(im); for (Object isolatedEdge : isolatedEdges) { Edge e = (Edge) isolatedEdge; e.updateIM(im); //Debug.println(im); } for (Iterator ni = this.nodes.iterator(); ni.hasNext(); ) { RelateNode node = (RelateNode) ni.next(); node.updateIM(im); //Debug.println(im); node.updateIMFromEdges(im); //Debug.println(im); //node.print(System.out); } }
/** * update the IM with the sum of the IMs for each component */ private void updateIM(IntersectionMatrix im) { //Debug.println(im); for (Iterator ei = isolatedEdges.iterator(); ei.hasNext(); ) { Edge e = (Edge) ei.next(); e.updateIM(im); //Debug.println(im); } for (Iterator ni = nodes.iterator(); ni.hasNext(); ) { RelateNode node = (RelateNode) ni.next(); node.updateIM(im); //Debug.println(im); node.updateIMFromEdges(im); //Debug.println(im); //node.print(System.out); } }
/** * If the Geometries are disjoint, we need to enter their dimension and * boundary dimension in the Ext rows in the IM */ private void computeDisjointIM(IntersectionMatrix im) { Geometry ga = this.arg[0].getGeometry(); if (!ga.isEmpty()) { im.set(Location.INTERIOR, Location.EXTERIOR, ga.getDimension()); im.set(Location.BOUNDARY, Location.EXTERIOR, ga.getBoundaryDimension()); } Geometry gb = this.arg[1].getGeometry(); if (!gb.isEmpty()) { im.set(Location.EXTERIOR, Location.INTERIOR, gb.getDimension()); im.set(Location.EXTERIOR, Location.BOUNDARY, gb.getBoundaryDimension()); } }
/** * Update the IM with the contribution for the EdgeStubs around the node. */ void updateIM(IntersectionMatrix im) { for (Iterator it = this.iterator(); it.hasNext(); ) { EdgeEndBundle esb = (EdgeEndBundle) it.next(); esb.updateIM(im); } }
/** * Updates an IM from the label for an edge. * Handles edges from both L and A geometries. */ public static void updateIM(Label label, IntersectionMatrix im) { im.setAtLeastIfValid(label.getLocation(0, Position.ON), label.getLocation(1, Position.ON), 1); if (label.isArea()) { im.setAtLeastIfValid(label.getLocation(0, Position.LEFT), label.getLocation(1, Position.LEFT), 2); im.setAtLeastIfValid(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), 2); } }
protected boolean checkCoordinatesWithFilteringArea(double x, double y) { Geometry geom = this.geometryFactory.createPoint(new Coordinate(x, y)); IntersectionMatrix includingMatrix = geom.relate(this.includingArea); if (!includingMatrix.isWithin()) { LOGGER.info("Coordinates (" + x + ", " + y + ") are outside the including area " + this.includingAreaString); return false; } IntersectionMatrix excludingMatrix = geom.relate(this.excludingArea); if (excludingMatrix.isWithin()) { LOGGER.info("Coordinates (" + x + ", " + y + ") are inside the excluding area " + this.excludingAreaString); return false; } return true; }
/** * If the Geometries are disjoint, we need to enter their dimension and * boundary dimension in the Ext rows in the IM */ private void computeDisjointIM(IntersectionMatrix im) { Geometry ga = arg[0].getGeometry(); if (!ga.isEmpty()) { im.set(Location.INTERIOR, Location.EXTERIOR, ga.getDimension()); im.set(Location.BOUNDARY, Location.EXTERIOR, ga.getBoundaryDimension()); } Geometry gb = arg[1].getGeometry(); if (!gb.isEmpty()) { im.set(Location.EXTERIOR, Location.INTERIOR, gb.getDimension()); im.set(Location.EXTERIOR, Location.BOUNDARY, gb.getBoundaryDimension()); } }
/** * Update the IM with the contribution for the EdgeStubs around the node. */ void updateIM(IntersectionMatrix im) { for (Iterator it = iterator(); it.hasNext(); ) { EdgeEndBundle esb = (EdgeEndBundle) it.next(); esb.updateIM(im); } }
void runRelateTest(String wkt1, String wkt2, String expectedIM) throws ParseException { Geometry g1 = rdr.read(wkt1); Geometry g2 = rdr.read(wkt2); IntersectionMatrix im = RelateOp.relate(g1, g2); String imStr = im.toString(); System.out.println(imStr); assertTrue(im.matches(expectedIM)); }
void runRelateTest(String wkt1, String wkt2, BoundaryNodeRule bnRule, String expectedIM) throws ParseException { Geometry g1 = rdr.read(wkt1); Geometry g2 = rdr.read(wkt2); IntersectionMatrix im = RelateOp.relate(g1, g2, bnRule); String imStr = im.toString(); System.out.println(imStr); assertTrue(im.matches(expectedIM)); }
public IntersectionMatrix computeIM() { IntersectionMatrix im = new IntersectionMatrix(); // since Geometries are finite and embedded in a 2-D space, the EE element must always be 2 im.set(Location.EXTERIOR, Location.EXTERIOR, 2); // if the Geometries don't overlap there is nothing to do if (!this.arg[0].getGeometry().getEnvelopeInternal().intersects( this.arg[1].getGeometry().getEnvelopeInternal())) { this.computeDisjointIM(im); return im; } this.arg[0].computeSelfNodes(this.li, false); this.arg[1].computeSelfNodes(this.li, false); // compute intersections between edges of the two input geometries SegmentIntersector intersector = this.arg[0].computeEdgeIntersections(this.arg[1], this.li, false); //System.out.println("computeIM: # segment intersection tests: " + intersector.numTests); this.computeIntersectionNodes(0); this.computeIntersectionNodes(1); /** * Copy the labelling for the nodes in the parent Geometries. These override * any labels determined by intersections between the geometries. */ this.copyNodesAndLabels(0); this.copyNodesAndLabels(1); // complete the labelling for any nodes which only have a label for a single geometry //Debug.addWatch(nodes.find(new Coordinate(110, 200))); //Debug.printWatch(); this.labelIsolatedNodes(); //Debug.printWatch(); // If a proper intersection was found, we can set a lower bound on the IM. this.computeProperIntersectionIM(intersector, im); /** * Now process improper intersections * (eg where one or other of the geometries has a vertex at the intersection point) * We need to compute the edge graph at all nodes to determine the IM. */ // build EdgeEnds for all intersections EdgeEndBuilder eeBuilder = new EdgeEndBuilder(); List ee0 = eeBuilder.computeEdgeEnds(this.arg[0].getEdgeIterator()); this.insertEdgeEnds(ee0); List ee1 = eeBuilder.computeEdgeEnds(this.arg[1].getEdgeIterator()); this.insertEdgeEnds(ee1); //Debug.println("==== NodeList ==="); //Debug.print(nodes); this.labelNodeEdges(); /** * Compute the labeling for isolated components * <br> * Isolated components are components that do not touch any other components in the graph. * They can be identified by the fact that they will * contain labels containing ONLY a single element, the one for their parent geometry. * We only need to check components contained in the input graphs, since * isolated components will not have been replaced by new components formed by intersections. */ //debugPrintln("Graph A isolated edges - "); this.labelIsolatedEdges(0, 1); //debugPrintln("Graph B isolated edges - "); this.labelIsolatedEdges(1, 0); // update the IM from all components this.updateIM(im); return im; }
private void computeProperIntersectionIM(SegmentIntersector intersector, IntersectionMatrix im) { // If a proper intersection is found, we can set a lower bound on the IM. int dimA = this.arg[0].getGeometry().getDimension(); int dimB = this.arg[1].getGeometry().getDimension(); boolean hasProper = intersector.hasProperIntersection(); boolean hasProperInterior = intersector.hasProperInteriorIntersection(); // For Geometry's of dim 0 there can never be proper intersections. /** * If edge segments of Areas properly intersect, the areas must properly overlap. */ if (dimA == 2 && dimB == 2) { if (hasProper) { im.setAtLeast("212101212"); } } /** * If an Line segment properly intersects an edge segment of an Area, * it follows that the Interior of the Line intersects the Boundary of the Area. * If the intersection is a proper <i>interior</i> intersection, then * there is an Interior-Interior intersection too. * Note that it does not follow that the Interior of the Line intersects the Exterior * of the Area, since there may be another Area component which contains the rest of the Line. */ else if (dimA == 2 && dimB == 1) { if (hasProper) { im.setAtLeast("FFF0FFFF2"); } if (hasProperInterior) { im.setAtLeast("1FFFFF1FF"); } } else if (dimA == 1 && dimB == 2) { if (hasProper) { im.setAtLeast("F0FFFFFF2"); } if (hasProperInterior) { im.setAtLeast("1F1FFFFFF"); } } /* If edges of LineStrings properly intersect *in an interior point*, all we can deduce is that the interiors intersect. (We can NOT deduce that the exteriors intersect, since some other segments in the geometries might cover the points in the neighbourhood of the intersection.) It is important that the point be known to be an interior point of both Geometries, since it is possible in a self-intersecting geometry to have a proper intersection on one segment that is also a boundary point of another segment. */ else if (dimA == 1 && dimB == 1) { if (hasProperInterior) { im.setAtLeast("0FFFFFFFF"); } } }
/** * Update the IM with the contribution for this component. * A component only contributes if it has a labelling for both parent geometries */ @Override protected void computeIM(IntersectionMatrix im) { im.setAtLeastIfValid(this.label.getLocation(0), this.label.getLocation(1), 0); }
/** * Update the IM with the contribution for the EdgeEnds incident on this node. */ void updateIMFromEdges(IntersectionMatrix im) { ((EdgeEndBundleStar) this.edges).updateIM(im); }
/** * Update the IM with the contribution for the computed label for the EdgeStubs. */ void updateIM(IntersectionMatrix im) { Edge.updateIM(this.label, im); }
/** * Update the IM with the contribution for this component. * A component only contributes if it has a labelling for both parent geometries */ public void updateIM(IntersectionMatrix im) { Assert.isTrue(this.label.getGeometryCount() >= 2, "found partial label"); this.computeIM(im); }
/** * Update the IM with the contribution for this component. * A component only contributes if it has a labelling for both parent geometries */ @Override public void computeIM(IntersectionMatrix im) { updateIM(label, im); }
/** * Basic nodes do not compute IMs */ @Override protected void computeIM(IntersectionMatrix im) { }
private void readPbfQuadtree(PbfQuadtree pbfQuadtree, CSVFileWriter qtWriter) throws IOException { /** Build geometry of this quadrant */ Coordinate[] coordinatesQuadrant = new Coordinate[5]; coordinatesQuadrant[0] = new Coordinate(pbfQuadtree.getSplitx()-pbfQuadtree.getDimensionx(),pbfQuadtree.getSplity()-pbfQuadtree.getDimensiony()); coordinatesQuadrant[1] = new Coordinate(pbfQuadtree.getSplitx()+pbfQuadtree.getDimensionx(),pbfQuadtree.getSplity()-pbfQuadtree.getDimensiony()); coordinatesQuadrant[2] = new Coordinate(pbfQuadtree.getSplitx()+pbfQuadtree.getDimensionx(),pbfQuadtree.getSplity()+pbfQuadtree.getDimensiony()); coordinatesQuadrant[3] = new Coordinate(pbfQuadtree.getSplitx()-pbfQuadtree.getDimensionx(),pbfQuadtree.getSplity()+pbfQuadtree.getDimensiony()); coordinatesQuadrant[4] = coordinatesQuadrant[0]; Polygon quadrant = geometryFactory.createPolygon(geometryFactory.createLinearRing(coordinatesQuadrant), null); quadrant.setSRID(4326); // Polygon quadrant = GeoHelper.createPolygon(coordinatesQuadrant, 4326); /** Read this quadtree if it intersects with test region and if it has >0 features */ IntersectionMatrix intersectionMatrix = quadrant.relate(quadrant); /** default */ if (settings.getCurrentPolygon() != null) { intersectionMatrix = settings.getCurrentPolygon().getPolygon().relate(quadrant); /** quadrant specific */ } if (intersectionMatrix.isIntersects() && pbfQuadtree.getFeatureCount() > 0) { super.setPbfDataFolder(new File(settings.getPbfDataFolder() + "/Quadtree/" + pbfQuadtree.getPath())); if (intersectionMatrix.isWithin()) { super.setLocalizeType(LocalizeType.WITHIN); } else if (intersectionMatrix.isOverlaps(2, 2)) { super.setLocalizeType(LocalizeType.OVERLAPS); } /** Read or load features */ if (pbfQuadtree.getLevel() <= settings.getKeepInCacheLevel()) { if (settings.getCache().containsKey(pbfQuadtree.getPath())) { /** Load features from cache */ for (IVgiFeature feature : settings.getCache().get(pbfQuadtree.getPath())) { feature.setLocalizeType(localizeType); super.enqueueFeature(feature); } } else { super.cacheIdentifier = pbfQuadtree.getPath(); super.readPbfFiles(true); } } else { super.readPbfFiles(false); } qtWriter.writeLine(quadrant.toText() + ";" + pbfQuadtree.getPath() + ";" + pbfQuadtree.getLevel() + ";" + pbfQuadtree.getFeatureCount() + ";" + intersectionMatrix.isOverlaps(2, 2) + ";"); } if (pbfQuadtree.hasNw()) { readPbfQuadtree(pbfQuadtree.getNw(), qtWriter); readPbfQuadtree(pbfQuadtree.getNe(), qtWriter); readPbfQuadtree(pbfQuadtree.getSe(), qtWriter); readPbfQuadtree(pbfQuadtree.getSw(), qtWriter); } }
public IntersectionMatrix computeIM() { IntersectionMatrix im = new IntersectionMatrix(); // since Geometries are finite and embedded in a 2-D space, the EE element must always be 2 im.set(Location.EXTERIOR, Location.EXTERIOR, 2); // if the Geometries don't overlap there is nothing to do if (!arg[0].getGeometry().getEnvelopeInternal().intersects( arg[1].getGeometry().getEnvelopeInternal())) { computeDisjointIM(im); return im; } arg[0].computeSelfNodes(li, false); arg[1].computeSelfNodes(li, false); // compute intersections between edges of the two input geometries SegmentIntersector intersector = arg[0].computeEdgeIntersections(arg[1], li, false); //System.out.println("computeIM: # segment intersection tests: " + intersector.numTests); computeIntersectionNodes(0); computeIntersectionNodes(1); /** * Copy the labelling for the nodes in the parent Geometries. These override * any labels determined by intersections between the geometries. */ copyNodesAndLabels(0); copyNodesAndLabels(1); // complete the labelling for any nodes which only have a label for a single geometry //Debug.addWatch(nodes.find(new Coordinate(110, 200))); //Debug.printWatch(); labelIsolatedNodes(); //Debug.printWatch(); // If a proper intersection was found, we can set a lower bound on the IM. computeProperIntersectionIM(intersector, im); /** * Now process improper intersections * (eg where one or other of the geometries has a vertex at the intersection point) * We need to compute the edge graph at all nodes to determine the IM. */ // build EdgeEnds for all intersections EdgeEndBuilder eeBuilder = new EdgeEndBuilder(); List ee0 = eeBuilder.computeEdgeEnds(arg[0].getEdgeIterator()); insertEdgeEnds(ee0); List ee1 = eeBuilder.computeEdgeEnds(arg[1].getEdgeIterator()); insertEdgeEnds(ee1); //Debug.println("==== NodeList ==="); //Debug.print(nodes); labelNodeEdges(); /** * Compute the labeling for isolated components * <br> * Isolated components are components that do not touch any other components in the graph. * They can be identified by the fact that they will * contain labels containing ONLY a single element, the one for their parent geometry. * We only need to check components contained in the input graphs, since * isolated components will not have been replaced by new components formed by intersections. */ //debugPrintln("Graph A isolated edges - "); labelIsolatedEdges(0, 1); //debugPrintln("Graph B isolated edges - "); labelIsolatedEdges(1, 0); // update the IM from all components updateIM(im); return im; }
private void computeProperIntersectionIM(SegmentIntersector intersector, IntersectionMatrix im) { // If a proper intersection is found, we can set a lower bound on the IM. int dimA = arg[0].getGeometry().getDimension(); int dimB = arg[1].getGeometry().getDimension(); boolean hasProper = intersector.hasProperIntersection(); boolean hasProperInterior = intersector.hasProperInteriorIntersection(); // For Geometry's of dim 0 there can never be proper intersections. /** * If edge segments of Areas properly intersect, the areas must properly overlap. */ if (dimA == 2 && dimB == 2) { if (hasProper) im.setAtLeast("212101212"); } /** * If an Line segment properly intersects an edge segment of an Area, * it follows that the Interior of the Line intersects the Boundary of the Area. * If the intersection is a proper <i>interior</i> intersection, then * there is an Interior-Interior intersection too. * Note that it does not follow that the Interior of the Line intersects the Exterior * of the Area, since there may be another Area component which contains the rest of the Line. */ else if (dimA == 2 && dimB == 1) { if (hasProper) im.setAtLeast("FFF0FFFF2"); if (hasProperInterior) im.setAtLeast("1FFFFF1FF"); } else if (dimA == 1 && dimB == 2) { if (hasProper) im.setAtLeast("F0FFFFFF2"); if (hasProperInterior) im.setAtLeast("1F1FFFFFF"); } /* If edges of LineStrings properly intersect *in an interior point*, all we can deduce is that the interiors intersect. (We can NOT deduce that the exteriors intersect, since some other segments in the geometries might cover the points in the neighbourhood of the intersection.) It is important that the point be known to be an interior point of both Geometries, since it is possible in a self-intersecting geometry to have a proper intersection on one segment that is also a boundary point of another segment. */ else if (dimA == 1 && dimB == 1) { if (hasProperInterior) im.setAtLeast("0FFFFFFFF"); } }
/** * Update the IM with the contribution for the EdgeEnds incident on this node. */ void updateIMFromEdges(IntersectionMatrix im) { ((EdgeEndBundleStar) edges).updateIM(im); }
/** * Update the IM with the contribution for the computed label for the EdgeStubs. */ void updateIM(IntersectionMatrix im) { Edge.updateIM(label, im); }
/** * Update the IM with the contribution for this component. * A component only contributes if it has a labelling for both parent geometries */ public void updateIM(IntersectionMatrix im) { Assert.isTrue(label.getGeometryCount() >= 2, "found partial label"); computeIM(im); }
/** * Computes the {@link IntersectionMatrix} for the spatial relationship * between two {@link Geometry}s, using the default (OGC SFS) Boundary Node Rule * * @param a a Geometry to test * @param b a Geometry to test * @return the IntersectonMatrix for the spatial relationship between the geometries */ public static IntersectionMatrix relate(Geometry a, Geometry b) { RelateOp relOp = new RelateOp(a, b); IntersectionMatrix im = relOp.getIntersectionMatrix(); return im; }
/** * Computes the {@link IntersectionMatrix} for the spatial relationship * between two {@link Geometry}s using a specified Boundary Node Rule. * * @param a a Geometry to test * @param b a Geometry to test * @param boundaryNodeRule the Boundary Node Rule to use * @return the IntersectonMatrix for the spatial relationship between the input geometries */ public static IntersectionMatrix relate(Geometry a, Geometry b, BoundaryNodeRule boundaryNodeRule) { RelateOp relOp = new RelateOp(a, b, boundaryNodeRule); IntersectionMatrix im = relOp.getIntersectionMatrix(); return im; }
/** * Gets the IntersectionMatrix for the spatial relationship * between the input geometries. * * @return the IntersectonMatrix for the spatial relationship between the input geometries */ public IntersectionMatrix getIntersectionMatrix() { return this.relate.computeIM(); }
/** * compute the contribution to an IM for this component */ abstract protected void computeIM(IntersectionMatrix im);
/** * Gets the IntersectionMatrix for the spatial relationship * between the input geometries. * * @return the IntersectonMatrix for the spatial relationship between the input geometries */ public IntersectionMatrix getIntersectionMatrix() { return relate.computeIM(); }
/** * Update the IM with the contribution for this component. * A component only contributes if it has a labelling for both parent geometries */ protected void computeIM(IntersectionMatrix im) { im.setAtLeastIfValid(label.getLocation(0), label.getLocation(1), 0); }
/** * Update the IM with the contribution for this component. * A component only contributes if it has a labelling for both parent geometries */ public void computeIM(IntersectionMatrix im) { updateIM(label, im); }
/** * Basic nodes do not compute IMs */ protected void computeIM(IntersectionMatrix im) { }
/** * Basic nodes do not compute IMs */ protected void computeIM(IntersectionMatrix im) {}