org.locationtech.jts.geom.Polygon.isValid()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中org.locationtech.jts.geom.Polygon.isValid()方法的一些代码示例,展示了Polygon.isValid()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Polygon.isValid()方法的具体详情如下:
包路径:org.locationtech.jts.geom.Polygon
类名称:Polygon
方法名:isValid

Polygon.isValid介绍

暂无

代码示例

代码示例来源:origin: geotools/geotools

public boolean isValid() {
  return polygon.isValid();
}

代码示例来源:origin: geotools/geotools

/**
 * If validation is requested, scan the geometries and build valid polygons (in case they
 * aren't) by also removing holes.
 *
 * @param geometriesList
 * @return
 */
private List<Polygon> validateGeometries(List<Polygon> geometriesList) {
  if (forceValid && (geometriesList.size() > 0)) {
    List<Polygon> validated = new ArrayList<Polygon>(geometriesList.size());
    for (int i = 0; i < geometriesList.size(); i++) {
      Polygon polygon = geometriesList.get(i);
      if (!polygon.isValid()) {
        List<Polygon> validPolygons = JTS.makeValid(polygon, true);
        validated.addAll(validPolygons);
      } else {
        validated.add(polygon);
      }
    }
    geometriesList = validated;
  }
  return geometriesList;
}

代码示例来源:origin: mapsforge/mapsforge

/**
 * Converts a way with potential inner ways to a JTS geometry.
 *
 * @param way       the way
 * @param innerWays the inner ways or null
 * @return the JTS geometry
 */
public static Geometry toJtsGeometry(TDWay way, List<TDWay> innerWays) {
  if (way == null) {
    LOGGER.warning("way is null");
    return null;
  }
  if (way.isForcePolygonLine()) {
    // may build a single line string if inner ways are empty
    return buildMultiLineString(way, innerWays);
  }
  if (way.getShape() != TDWay.LINE || innerWays != null && innerWays.size() > 0) {
    // Have to be careful here about polygons and lines again, the problem with
    // polygons is that a certain direction is forced, so we do not want to reverse
    // closed lines that are not meant to be polygons
    // may contain holes if inner ways are not empty
    Polygon polygon = buildPolygon(way, innerWays);
    if (polygon.isValid()) {
      return polygon;
    }
    return repairInvalidPolygon(polygon);
  }
  // not a closed line
  return buildLineString(way);
}

代码示例来源:origin: mapsforge/mapsforge

@Test
public void testBuildInValidPolygonWith2InnerRings() {
  String testfile = "invalid-polygon-2-inner-rings.wkt";
  List<TDWay> ways = MockingUtils.wktPolygonToWays(testfile);
  Polygon polygon = JTSUtils.buildPolygon(ways.get(0), ways.subList(1, ways.size()));
  Geometry expected = MockingUtils.readWKTFile(testfile);
  Assert.isTrue(!polygon.isValid());
  Assert.equals(expected, polygon);
}

代码示例来源:origin: mapsforge/mapsforge

@Test
  public void testBuildValidPolygonWith2InnerRings() {
    String testfile = "valid-polygon-2-inner-rings.wkt";

    List<TDWay> ways = MockingUtils.wktPolygonToWays(testfile);
    Polygon polygon = JTSUtils.buildPolygon(ways.get(0), ways.subList(1, ways.size()));
    Geometry expected = MockingUtils.readWKTFile(testfile);
    Assert.isTrue(polygon.isValid());
    Assert.equals(expected, polygon);
  }
}

代码示例来源:origin: mapsforge/mapsforge

/**
 * @param way the TDWay
 * @return way as a polygon
 */
public static Polygon mapWayToPolygon(TDWay way) {
  TDNode[] wayNodes = way.getWayNodes();
  if (wayNodes.length < 3) {
    return null;
  }
  Coordinate[] wayCoords = new Coordinate[wayNodes.length + 1];
  for (int i = 0; i < wayCoords.length - 1; i++) {
    wayCoords[i] = new Coordinate(wayNodes[i].getLatitude(), wayNodes[i].getLongitude());
  }
  wayCoords[wayCoords.length - 1] = wayCoords[0];
  Polygon polygon = GEOMETRY_FACTORY.createPolygon(GEOMETRY_FACTORY.createLinearRing(wayCoords), null);
  if (!polygon.isValid()) {
    return null;
  }
  return polygon;
}

代码示例来源:origin: mapsforge/mapsforge

@Test
public void testBuildInvalidPolygon() {
  String testfile = "invalid-polygon.wkt";
  List<TDWay> ways = MockingUtils.wktPolygonToWays(testfile);
  Polygon polygon = JTSUtils.buildPolygon(ways.get(0));
  Geometry expected = MockingUtils.readWKTFile(testfile);
  Assert.isTrue(!polygon.isValid());
  Assert.equals(expected, polygon);
}

代码示例来源:origin: mapsforge/mapsforge

@Test
public void testBuildValidPolygon() {
  String testfile = "valid-polygon.wkt";
  List<TDWay> ways = MockingUtils.wktPolygonToWays(testfile);
  Polygon polygon = JTSUtils.buildPolygon(ways.get(0));
  Geometry expected = MockingUtils.readWKTFile(testfile);
  Assert.isTrue(polygon.isValid());
  Assert.equals(expected, polygon);
}

代码示例来源:origin: mapsforge/mapsforge

if (!polygon.isValid()) {
  return;

代码示例来源:origin: geotools/geotools

@Test
  public void testMakeValid() throws Exception {
    // An invalid polygon similar to this one
    //
    // *----*
    // |    |
    // *----*----*
    //      |    |
    //      *----*
    //
    // Will be split into 2 separate polygons through the makeValid method
    final int[] xPoints = {0, 5, 5, 5, 10, 10, 5, 0};
    final int[] yPoints = {0, 0, 5, 10, 10, 5, 5, 5};
    final int nPoints = xPoints.length;

    final Shape shape = new java.awt.Polygon(xPoints, yPoints, nPoints);
    final LinearRing geom = (LinearRing) JTS.toGeometry(shape);
    final GeometryFactory factory = new GeometryFactory();
    final org.locationtech.jts.geom.Polygon polygon = factory.createPolygon(geom);
    assertFalse(polygon.isValid());

    final List<org.locationtech.jts.geom.Polygon> validPols = JTS.makeValid(polygon, false);

    assertEquals(2, validPols.size());
    org.locationtech.jts.geom.Polygon polygon1 = validPols.get(0);
    org.locationtech.jts.geom.Polygon polygon2 = validPols.get(1);
    assertEquals(5, polygon1.getNumPoints());
    assertEquals(5, polygon2.getNumPoints());
  }
}

代码示例来源:origin: Geomatys/geotoolkit

public boolean isValid() {
  org.locationtech.jts.geom.Polygon poly = (org.locationtech.jts.geom.Polygon)
    this.getJTSGeometry();
  return poly.isValid();
}

代码示例来源:origin: geotools/geotools

@Test
public void testInvalidMultipolygon() throws Exception {
  WKTReader reader = new WKTReader();
  // three triangles that united form a rectangle with a triangular hole in the middle
  GeometryCollector collector = new GeometryCollector();
  collector.setFactory(null);
  final Geometry p0 = reader.read("POLYGON((0 0, 0 3, 3 3, 3 0, 0 0))");
  collector.add(p0);
  final Geometry p1 = reader.read("POLYGON((1 1, 1 2, 2 2, 2 1, 1 1))");
  collector.add(p1);
  GeometryCollection result = collector.collect();
  assertEquals(1, result.getNumGeometries());
  Polygon p = (org.locationtech.jts.geom.Polygon) result.getGeometryN(0);
  assertTrue(p.isValid());
}

代码示例来源:origin: orbisgis/h2gis

/**
   * Create and collect shadow polygons.
   *
   * @param shadows
   * @param coordinates
   * @param shadow
   * @param factory
   */
  private static void createShadowPolygons(Collection<Polygon> shadows, Coordinate[] coordinates, double[] shadow, GeometryFactory factory) {
    for (int i = 1; i < coordinates.length; i++) {
      Coordinate startCoord = coordinates[i - 1];
      Coordinate endCoord = coordinates[i];
      Coordinate nextEnd = moveCoordinate(endCoord, shadow);
      Coordinate nextStart = moveCoordinate(startCoord, shadow);
      Polygon polygon = factory.createPolygon(new Coordinate[]{startCoord,
        endCoord, nextEnd,
        nextStart, startCoord});
      if (polygon.isValid()) {                
        shadows.add(polygon);
      }
    }
  }
}

代码示例来源:origin: orbisgis/h2gis

if (!geom.isValid()) {
  throw new SQLException("Geometry not valid");

相关文章