org.locationtech.jts.geom.TopologyException Java Examples

The following examples show how to use org.locationtech.jts.geom.TopologyException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VectorTileEncoder.java    From java-vector-tile with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #2
Source File: DBScanClusterList.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected void union(final Geometry otherGeo) {

    if (otherGeo == null) {
      return;
    }
    try {

      if (clusterGeo == null) {
        clusterGeo = otherGeo;
      } else if (clusterGeo instanceof Point) {
        clusterGeo = connectGeometryTool.connect(otherGeo, clusterGeo);
      } else {
        clusterGeo = connectGeometryTool.connect(clusterGeo, otherGeo);
      }
    } catch (final TopologyException ex) {

      LOGGER.error("Union failed due to non-simple geometries", ex);
      clusterGeo =
          connectGeometryTool.createHullFromGeometry(
              clusterGeo,
              Arrays.asList(otherGeo.getCoordinates()),
              false);
    }
  }