当前位置: 首页>>代码示例>>Java>>正文


Java TopologyException类代码示例

本文整理汇总了Java中com.vividsolutions.jts.geom.TopologyException的典型用法代码示例。如果您正苦于以下问题:Java TopologyException类的具体用法?Java TopologyException怎么用?Java TopologyException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TopologyException类属于com.vividsolutions.jts.geom包,在下文中一共展示了TopologyException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSharedAreaRatio

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/** */
public static double getSharedAreaRatio (Geometry geom1, Geometry geom2) {
    try {
        return geom1.intersection(geom2).getArea() / geom1.getArea();
    } catch (TopologyException e) {
        // HACK: there appears to be a bug in JTS, but I can't
        // reproduce it consistently. Why should computing the
        // intersection with a MultiPolygon fail when computing
        // the intersection with each of its constituent Polygons
        // succeeds? I have no idea, but it does happen. This
        // seems to fix the problem, though.
        double result = 0.0;
        if (geom2 instanceof GeometryCollection) {
            GeometryCollection gc = (GeometryCollection)geom2;
            for (int j = 0; j < gc.getNumGeometries(); j += 1) {
                result += geom1.intersection(gc.getGeometryN(j)).getArea();
            }
            return result / geom1.getArea();
        } else {
            throw e;
        }
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:24,代码来源:JTSUtil.java

示例2: flatIntersection

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/**
 * JTS 1.14 does not support intersection on a {@link GeometryCollection}. This function works
 * around this by performing intersection on a flat list of geometry. The resulting list is
 * pre-filtered for invalid or empty geometry (outside of bounds). Invalid geometry are logged as
 * errors.
 *
 * @param envelope  non-list geometry defines bounding area
 * @param dataGeoms geometry pre-passed through {@link #flatFeatureList(Geometry)}
 * @return list of geometry from {@code data} intersecting with {@code envelope}.
 */
private static List<Geometry> flatIntersection(Geometry envelope, List<Geometry> dataGeoms) {
  final List<Geometry> intersectedGeoms = new ArrayList<>(dataGeoms.size());

  Geometry nextIntersected;
  for (Geometry nextGeom : dataGeoms) {
    try {

      // AABB intersection culling
      if (envelope.getEnvelopeInternal().intersects(nextGeom.getEnvelopeInternal())) {

        nextIntersected = envelope.intersection(nextGeom);
        if (!nextIntersected.isEmpty()) {
          nextIntersected.setUserData(nextGeom.getUserData());
          intersectedGeoms.add(nextIntersected);
        }
      }

    } catch (TopologyException ex) {
      LoggerFactory.getLogger(JtsAdapter.class).error(ex.getMessage(), ex);
    }
  }

  return intersectedGeoms;
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:35,代码来源:JtsAdapter.java

示例3: bufferReducedPrecision

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
private void bufferReducedPrecision() {
    // try and compute with decreasing precision
    for (int precDigits = MAX_PRECISION_DIGITS; precDigits >= 0; precDigits--) {
        try {
            this.bufferReducedPrecision(precDigits);
        } catch (TopologyException ex) {
            // update the saved exception to reflect the new input geometry
            this.saveException = ex;
            // don't propagate the exception - it will be detected by fact that resultGeometry is null
        }
        if (this.resultGeometry != null) {
            return;
        }
    }

    // tried everything - have to bail
    throw this.saveException;
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:19,代码来源:BufferOp.java

示例4: computePoints

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/**
     * Collect all the points from the DirectedEdges of this ring into a contiguous list
     */
    protected void computePoints(DirectedEdge start) {
//System.out.println("buildRing");
        this.startDe = start;
        DirectedEdge de = start;
        boolean isFirstEdge = true;
        do {
//      Assert.isTrue(de != null, "found null Directed Edge");
            if (de == null) {
                throw new TopologyException("Found null DirectedEdge");
            }
            if (de.getEdgeRing() == this) {
                throw new TopologyException("Directed Edge visited twice during ring-building at " + de.getCoordinate());
            }

            this.edges.add(de);
//Debug.println(de);
//Debug.println(de.getEdge());
            Label label = de.getLabel();
            Assert.isTrue(label.isArea());
            this.mergeLabel(label);
            this.addPoints(de.getEdge(), de.isForward(), isFirstEdge);
            isFirstEdge = false;
            this.setEdgeRing(de, this);
            de = this.getNext(de);
        } while (de != this.startDe);
    }
 
开发者ID:gegy1000,项目名称:Earth,代码行数:30,代码来源:EdgeRing.java

示例5: computeDepths

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
public void computeDepths(DirectedEdge de) {
        int edgeIndex = this.findIndex(de);
        Label label = de.getLabel();
        int startDepth = de.getDepth(Position.LEFT);
        int targetLastDepth = de.getDepth(Position.RIGHT);
        // compute the depths from this edge up to the end of the edge array
        int nextDepth = this.computeDepths(edgeIndex + 1, this.edgeList.size(), startDepth);
        // compute the depths for the initial part of the array
        int lastDepth = this.computeDepths(0, edgeIndex, nextDepth);
//Debug.print(lastDepth != targetLastDepth, this);
//Debug.print(lastDepth != targetLastDepth, "mismatch: " + lastDepth + " / " + targetLastDepth);
        if (lastDepth != targetLastDepth) {
            throw new TopologyException("depth mismatch at " + de.getCoordinate());
        }
        //Assert.isTrue(lastDepth == targetLastDepth, "depth mismatch at " + de.getCoordinate());
    }
 
开发者ID:gegy1000,项目名称:Earth,代码行数:17,代码来源:DirectedEdgeStar.java

示例6: clipGeometry

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/**
 * Clip geometry according to buffer given at construct time. This method
 * can be overridden to change clipping behavior. See also
 * {@link #clipCovers(Geometry)}.
 *
 * @param geometry
 * @return
 */
protected Geometry clipGeometry(Geometry geometry) {
    try {
        Geometry original = geometry;
        geometry = clipGeometry.intersection(original);

        // some times a intersection is returned as an empty geometry.
        // going via wkt fixes the problem.
        if (geometry.isEmpty() && original.intersects(clipGeometry)) {
            Geometry originalViaWkt = new WKTReader().read(original.toText());
            geometry = clipGeometry.intersection(originalViaWkt);
        }

        return geometry;
    } catch (TopologyException e) {
        // could not intersect. original geometry will be used instead.
        return geometry;
    } catch (ParseException e1) {
        // could not encode/decode WKT. original geometry will be used
        // instead.
        return geometry;
    }
}
 
开发者ID:stefan0722,项目名称:gs-mvt,代码行数:31,代码来源:VectorTileEncoder.java

示例7: mapWayToTiles

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/**
 * Computes which tiles on the given base zoom level need to include the given way (which may be a polygon).
 * 
 * @param way
 *            the way that is mapped to tiles
 * @param baseZoomLevel
 *            the base zoom level which is used in the mapping
 * @param enlargementInMeter
 *            amount of pixels that is used to enlarge the bounding box of the way and the tiles in the mapping
 *            process
 * @return all tiles on the given base zoom level that need to include the given way, an empty set if no tiles are
 *         matched
 */
public static Set<TileCoordinate> mapWayToTiles(final TDWay way, final byte baseZoomLevel,
		final int enlargementInMeter) {
	if (way == null) {
		LOGGER.fine("way is null in mapping to tiles");
		return Collections.emptySet();
	}

	HashSet<TileCoordinate> matchedTiles = new HashSet<TileCoordinate>();
	Geometry wayGeometry = toJTSGeometry(way, !way.isForcePolygonLine());
	if (wayGeometry == null) {
		LOGGER.fine("unable to create geometry from way: " + way.getId());
		return matchedTiles;
	}

	TileCoordinate[] bbox = getWayBoundingBox(way, baseZoomLevel, enlargementInMeter);
	// calculate the tile coordinates and the corresponding bounding boxes
	try {
		for (int k = bbox[0].getX(); k <= bbox[1].getX(); k++) {
			for (int l = bbox[0].getY(); l <= bbox[1].getY(); l++) {
				Geometry bboxGeometry = tileToJTSGeometry(k, l, baseZoomLevel, enlargementInMeter);
				if (bboxGeometry.intersects(wayGeometry)) {
					matchedTiles.add(new TileCoordinate(k, l, baseZoomLevel));
				}
			}
		}
	} catch (TopologyException e) {
		LOGGER.log(Level.FINE,
				"encountered error during mapping of a way to corresponding tiles, way id: " + way.getId());
		return Collections.emptySet();
	}

	return matchedTiles;
}
 
开发者ID:DonTomika,项目名称:mapsforge,代码行数:47,代码来源:GeoUtils.java

示例8: clipToTile

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/**
 * Clips a geometry to a tile.
 * 
 * @param way
 *            the way
 * @param geometry
 *            the geometry
 * @param tileCoordinate
 *            the tile coordinate
 * @param enlargementInMeters
 *            the bounding box buffer
 * @return the clipped geometry
 */
public static Geometry clipToTile(TDWay way, Geometry geometry, TileCoordinate tileCoordinate,
		int enlargementInMeters) {
	// clip geometry?
	Geometry tileBBJTS = null;
	Geometry ret = null;

	// create tile bounding box
	tileBBJTS = tileToJTSGeometry(tileCoordinate.getX(), tileCoordinate.getY(), tileCoordinate.getZoomlevel(),
			enlargementInMeters);

	// clip the polygon/ring by intersection with the bounding box of the tile
	// may throw a TopologyException
	try {
		// geometry = OverlayOp.overlayOp(tileBBJTS, geometry, OverlayOp.INTERSECTION);
		ret = tileBBJTS.intersection(geometry);
	} catch (TopologyException e) {
		LOGGER.log(Level.FINE, "JTS cannot clip way, not storing it in data file: " + way.getId(), e);
		way.setInvalid(true);
		return null;
	}
	return ret;
}
 
开发者ID:DonTomika,项目名称:mapsforge,代码行数:36,代码来源:GeoUtils.java

示例9: simplifyGeometry

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/**
 * Simplifies a geometry using the Douglas Peucker algorithm.
 * 
 * @param way
 *            the way
 * @param geometry
 *            the geometry
 * @param zoomlevel
 *            the zoom level
 * @param simplificationFactor
 *            the simplification factor
 * @return the simplified geometry
 */
public static Geometry simplifyGeometry(TDWay way, Geometry geometry, byte zoomlevel, double simplificationFactor) {
	Geometry ret = null;

	Envelope bbox = geometry.getEnvelopeInternal();
	// compute maximal absolute latitude (so that we don't need to care if we
	// are on northern or southern hemisphere)
	double latMax = Math.max(Math.abs(bbox.getMaxY()), Math.abs(bbox.getMinY()));
	double deltaLat = MercatorProjection.deltaLat(simplificationFactor, latMax, zoomlevel);

	try {
		ret = TopologyPreservingSimplifier.simplify(geometry, deltaLat);
	} catch (TopologyException e) {
		LOGGER.log(Level.FINE,
				"JTS cannot simplify way due to an error, not simplifying way with id: " + way.getId(), e);
		way.setInvalid(true);
		return geometry;
	}

	return ret;
}
 
开发者ID:DonTomika,项目名称:mapsforge,代码行数:34,代码来源:GeoUtils.java

示例10: getSharedAreaRatio

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/** */
public static double getSharedAreaRatio (Geometry geom1, Geometry geom2) {
    try {
        return geom1.intersection(geom2).getArea() / geom1.getArea();
    } catch (TopologyException e) {
        // HACK: there appears to be a bug in JTS, but I can't
        // reproduce it consistently. Why should computing the
        // intersection with a MultiPolygon fail when computing
        // the intersection with each of its constituent Polygons
        // succeeds? I have no idea, but it does happen. This 
        // seems to fix the problem, though.
        double result = 0.0;
        if (geom2 instanceof GeometryCollection) {
            GeometryCollection gc = (GeometryCollection)geom2;
            for (int j = 0; j < gc.getNumGeometries(); j += 1) {
                result += geom1.intersection(gc.getGeometryN(j)).getArea();
            }
            return result / geom1.getArea();
        } else {
            throw e;
        }
    }
}
 
开发者ID:reuven,项目名称:modelingcommons,代码行数:24,代码来源:JTSUtils.java

示例11: placeFreeHoles

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/**
     * This method determines finds a containing shell for all holes
     * which have not yet been assigned to a shell.
     * These "free" holes should
     * all be <b>properly</b> contained in their parent shells, so it is safe to use the
     * <code>findEdgeRingContaining</code> method.
     * (This is the case because any holes which are NOT
     * properly contained (i.e. are connected to their
     * parent shell) would have formed part of a MaximalEdgeRing
     * and been handled in a previous step).
     *
     * @throws TopologyException if a hole cannot be assigned to a shell
     */
    private void placeFreeHoles(List shellList, List freeHoleList) {
        for (Object aFreeHoleList : freeHoleList) {
            EdgeRing hole = (EdgeRing) aFreeHoleList;
            // only place this hole if it doesn't yet have a shell
            if (hole.getShell() == null) {
                EdgeRing shell = this.findEdgeRingContaining(hole, shellList);
                if (shell == null) {
                    throw new TopologyException("unable to assign hole to a shell", hole.getCoordinate(0));
                }
//        Assert.isTrue(shell != null, "unable to assign hole to a shell");
                hole.setShell(shell);
            }
        }
    }
 
开发者ID:gegy1000,项目名称:Earth,代码行数:28,代码来源:PolygonBuilder.java

示例12: checkValid

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/**
 * Checks for an intersection and throws
 * a TopologyException if one is found.
 *
 * @throws TopologyException if an intersection is found
 */
public void checkValid() {
    this.execute();
    if (!this.isValid) {
        throw new TopologyException(this.getErrorMessage(), this.segInt.getInteriorIntersection());
    }
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:13,代码来源:FastNodingValidator.java

示例13: computeNodes

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
/**
     * Fully nodes a list of {@link SegmentString}s, i.e. peforms noding iteratively
     * until no intersections are found between segments.
     * Maintains labelling of edges correctly through
     * the noding.
     *
     * @param segStrings a collection of SegmentStrings to be noded
     * @throws TopologyException if the iterated noding fails to converge.
     */
    @Override
    public void computeNodes(Collection segStrings)
            throws TopologyException {
        int[] numInteriorIntersections = new int[1];
        this.nodedSegStrings = segStrings;
        int nodingIterationCount = 0;
        int lastNodesCreated = -1;
        do {
            this.node(this.nodedSegStrings, numInteriorIntersections);
            nodingIterationCount++;
            int nodesCreated = numInteriorIntersections[0];

            /**
             * Fail if the number of nodes created is not declining.
             * However, allow a few iterations at least before doing this
             */
//System.out.println("# nodes created: " + nodesCreated);
            if (lastNodesCreated > 0
                    && nodesCreated >= lastNodesCreated
                    && nodingIterationCount > this.maxIter) {
                throw new TopologyException("Iterated noding failed to converge after "
                        + nodingIterationCount + " iterations");
            }
            lastNodesCreated = nodesCreated;
        } while (lastNodesCreated > 0);
//System.out.println("# nodings = " + nodingIterationCount);
    }
 
开发者ID:gegy1000,项目名称:Earth,代码行数:37,代码来源:IteratedNoder.java

示例14: setDepth

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
public void setDepth(int position, int depthVal) {
        if (this.depth[position] != -999) {
//      if (depth[position] != depthVal) {
//        Debug.print(this);
//      }
            if (this.depth[position] != depthVal) {
                throw new TopologyException("assigned depths do not match", this.getCoordinate());
            }
            //Assert.isTrue(depth[position] == depthVal, "assigned depths do not match at " + getCoordinate());
        }
        this.depth[position] = depthVal;
    }
 
开发者ID:gegy1000,项目名称:Earth,代码行数:13,代码来源:DirectedEdge.java

示例15: updateGeometry

import com.vividsolutions.jts.geom.TopologyException; //导入依赖的package包/类
@Override
protected void updateGeometry() {
	if (this.coordinates == null) {
		LinearRing nullLR = new LinearRing(null, new GeometryFactory());
		this.geom = new GeometryFactory().createPolygon(nullLR);
	}
	else {
		Coordinate[] newCoords = new Coordinate[coordinates.length+1];
		for (int i = 0; i < coordinates.length; i++) {
			newCoords[i] = coordinates[i];
		}
		newCoords[coordinates.length] = this.coordinates[0];
		this.geom = new GeometryFactory().createPolygon(newCoords);						
		if (!this.geom.isValid()) {
			try { 
				this.geom = this.geom.symDifference(this.geom.getBoundary());
			}
			catch(TopologyException e) {
				logger.info("Trying to fix GeometricShapeVariable " + this.getVariable().getID());
				this.geom = this.geom.buffer(0.1);
				if (!this.geom.isValid()) {
					logger.severe("... giving up!");
					throw e;
				}
			}
		}
	}
}
 
开发者ID:FedericoPecora,项目名称:meta-csp-framework,代码行数:29,代码来源:PolygonalDomain.java


注:本文中的com.vividsolutions.jts.geom.TopologyException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。