com.vividsolutions.jts.geom.GeometryFactory.toPolygonArray()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(89)

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

GeometryFactory.toPolygonArray介绍

[英]Converts the List to an array.
[中]将List转换为数组。

代码示例

代码示例来源:origin: com.vividsolutions/jts

/**
  * Computes a {@link Geometry} containing only {@link Polygonal} components.
  * Extracts the {@link Polygon}s from the input 
  * and returns them as an appropriate {@link Polygonal} geometry.
  * <p>
  * If the input is already <tt>Polygonal</tt>, it is returned unchanged.
  * <p>
  * A particular use case is to filter out non-polygonal components
  * returned from an overlay operation.  
  * 
  * @param g the geometry to filter
  * @return a Polygonal geometry
  */
 private static Geometry restrictToPolygons(Geometry g)
 {
  if (g instanceof Polygonal) {
   return g;
  }
  List polygons = PolygonExtracter.getPolygons(g);
  if (polygons.size() == 1) 
   return (Polygon) polygons.get(0);
  return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons));
 }
}

代码示例来源:origin: com.vividsolutions/jts

if (isCollection) {
 if (geom0 instanceof Polygon) {
  return createMultiPolygon(toPolygonArray(geomList));

代码示例来源:origin: org.orbisgis/orbisgis-core

/**
 * Removes duplicated coordinates within a MultiPolygon.
 * @param g
 * @return
 */
public static MultiPolygon removeDuplicateCoordinates(MultiPolygon g) {
    ArrayList<Polygon> polys = new ArrayList<Polygon>();
    for (int i = 0; i < g.getNumGeometries(); i++) {
        Polygon poly = (Polygon) g.getGeometryN(i);
        polys.add(removeDuplicateCoordinates(poly));
    }
    return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(polys));
}

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

/**
 * Removes duplicated coordinates within a MultiPolygon.
 *
 * @param g
 * @return
 */
public static MultiPolygon removeCoordinates(MultiPolygon g) {
  ArrayList<Polygon> polys = new ArrayList<Polygon>();
  for (int i = 0; i < g.getNumGeometries(); i++) {
    Polygon poly = (Polygon) g.getGeometryN(i);
    polys.add(removeCoordinates(poly));
  }
  return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(polys));
}

代码示例来源:origin: org.orbisgis/h2gis-functions

/**
 * Removes duplicated coordinates within a MultiPolygon.
 *
 * @param g
 * @return
 */
public static MultiPolygon removeCoordinates(MultiPolygon g) {
  ArrayList<Polygon> polys = new ArrayList<Polygon>();
  for (int i = 0; i < g.getNumGeometries(); i++) {
    Polygon poly = (Polygon) g.getGeometryN(i);
    polys.add(removeCoordinates(poly));
  }
  return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(polys));
}

代码示例来源:origin: com.vividsolutions/jts-core

/**
  * Computes a {@link Geometry} containing only {@link Polygonal} components.
  * Extracts the {@link Polygon}s from the input 
  * and returns them as an appropriate {@link Polygonal} geometry.
  * <p>
  * If the input is already <tt>Polygonal</tt>, it is returned unchanged.
  * <p>
  * A particular use case is to filter out non-polygonal components
  * returned from an overlay operation.  
  * 
  * @param g the geometry to filter
  * @return a Polygonal geometry
  */
 private static Geometry restrictToPolygons(Geometry g)
 {
  if (g instanceof Polygonal) {
   return g;
  }
  List polygons = PolygonExtracter.getPolygons(g);
  if (polygons.size() == 1) 
   return (Polygon) polygons.get(0);
  return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons));
 }
}

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

/**
 * Removes duplicated coordinates within a MultiPolygon.
 *
 * @param multiPolygon
 * @param tolerance to delete the coordinates
 * @return
 * @throws java.sql.SQLException
 */
public static MultiPolygon removeDuplicateCoordinates(MultiPolygon multiPolygon, double tolerance) throws SQLException {
  ArrayList<Polygon> polys = new ArrayList<Polygon>();
  for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
    Polygon poly = (Polygon) multiPolygon.getGeometryN(i);
    polys.add(removeDuplicateCoordinates(poly, tolerance));
  }
  return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(polys));
}

代码示例来源:origin: org.orbisgis/h2gis-functions

/**
 * Removes duplicated coordinates within a MultiPolygon.
 *
 * @param multiPolygon
 * @param tolerance to delete the coordinates
 * @return
 * @throws java.sql.SQLException
 */
public static MultiPolygon removeDuplicateCoordinates(MultiPolygon multiPolygon, double tolerance) throws SQLException {
  ArrayList<Polygon> polys = new ArrayList<Polygon>();
  for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
    Polygon poly = (Polygon) multiPolygon.getGeometryN(i);
    polys.add(removeDuplicateCoordinates(poly, tolerance));
  }
  return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(polys));
}

代码示例来源:origin: mapplus/spatial_statistics_for_geotools_udig

private Geometry removeSmallHoles(Geometry inputPolygon, double areaTolerance) {
  Class<?> geomBinding = inputPolygon.getClass();
  Geometry finalGeom = inputPolygon;
  if (Polygon.class.equals(geomBinding)) {
    finalGeom = removeSmallHoles((Polygon) inputPolygon, areaTolerance);
  } else if (MultiPolygon.class.equals(geomBinding)) {
    List<Polygon> polygons = new ArrayList<Polygon>();
    for (int index = 0; index < inputPolygon.getNumGeometries(); index++) {
      Polygon polygon = (Polygon) inputPolygon.getGeometryN(index);
      polygons.add((Polygon) removeSmallHoles(polygon, areaTolerance));
    }
    finalGeom = inputPolygon.getFactory().createMultiPolygon(
        GeometryFactory.toPolygonArray(polygons));
  }
  finalGeom.setUserData(inputPolygon.getUserData());
  return finalGeom;
}

代码示例来源:origin: mapplus/spatial_statistics_for_geotools_udig

private Geometry removeHoles(Geometry inputPolygon) {
  Class<?> geomBinding = inputPolygon.getClass();
  Geometry finalGeom = inputPolygon;
  if (Polygon.class.equals(geomBinding)) {
    finalGeom = removeHoles((Polygon) inputPolygon);
  } else if (MultiPolygon.class.equals(geomBinding)) {
    List<Polygon> polygons = new ArrayList<Polygon>();
    for (int index = 0; index < inputPolygon.getNumGeometries(); index++) {
      Polygon polygon = (Polygon) inputPolygon.getGeometryN(index);
      polygons.add((Polygon) removeHoles(polygon));
    }
    finalGeom = inputPolygon.getFactory().createMultiPolygon(
        GeometryFactory.toPolygonArray(polygons));
  }
  finalGeom.setUserData(inputPolygon.getUserData());
  return finalGeom;
}

代码示例来源:origin: mapplus/spatial_statistics_for_geotools_udig

private Geometry removeHoles(Geometry inputPolygon) {
  Class<?> geomBinding = inputPolygon.getClass();
  Geometry finalGeom = inputPolygon;
  if (Polygon.class.equals(geomBinding)) {
    finalGeom = removeHoles((Polygon) inputPolygon);
  } else if (MultiPolygon.class.equals(geomBinding)) {
    List<Polygon> polygons = new ArrayList<Polygon>();
    for (int index = 0; index < inputPolygon.getNumGeometries(); index++) {
      Polygon polygon = (Polygon) inputPolygon.getGeometryN(index);
      polygons.add((Polygon) removeHoles(polygon));
    }
    finalGeom = inputPolygon.getFactory().createMultiPolygon(
        GeometryFactory.toPolygonArray(polygons));
  }
  finalGeom.setUserData(inputPolygon.getUserData());
  return finalGeom;
}

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

/**
   * Creates a GeometryCollection containing possible polygons formed 
   * from the constituent linework of a set of geometries.
   * 
   * @param geometry
   * @return 
   */
  public static Geometry polygonize(Geometry geometry) {
    if(geometry == null){
      return null;
    }
    Polygonizer polygonizer = new Polygonizer();
    polygonizer.add(geometry);
    Collection pols = polygonizer.getPolygons();
    if(pols.isEmpty()){
      return null;
    }
    return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(pols));
  }
}

代码示例来源:origin: org.orbisgis/h2gis-functions

/**
   * Creates a GeometryCollection containing possible polygons formed 
   * from the constituent linework of a set of geometries.
   * 
   * @param geometry
   * @return 
   */
  public static Geometry polygonize(Geometry geometry) {
    if(geometry == null){
      return null;
    }
    Polygonizer polygonizer = new Polygonizer();
    polygonizer.add(geometry);
    Collection pols = polygonizer.getPolygons();
    if(pols.isEmpty()){
      return null;
    }
    return FACTORY.createMultiPolygon(GeometryFactory.toPolygonArray(pols));
  }
}

代码示例来源:origin: com.vividsolutions/jts-ora

/**
 * Create MultiPolygon as encoded by elemInfo.
 *
 * @param oraGeom SDO_GEOMETRY attributes being read
 * @param coords the coordinates of the entire geometry
 * @return MultiPolygon
 */
private MultiPolygon readMultiPolygon(OraGeom oraGeom)
{
 int nElem = oraGeom.numElements();
 List geoms = new ArrayList();
 for (int i = 0; i < nElem; i++) {
  int etype = oraGeom.eType(i);
  if ((etype == OraGeom.ETYPE.POLYGON) || (etype == OraGeom.ETYPE.POLYGON_EXTERIOR)) {
   Polygon poly = readPolygon(oraGeom, i);
   i += poly.getNumInteriorRing(); // skip interior rings
   geoms.add(poly);
  } 
  else { // not a Polygon - stop reading
    break;
  }
 }
 MultiPolygon polys = geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray(geoms));
 return polys;
}

代码示例来源:origin: mapplus/spatial_statistics_for_geotools_udig

private Geometry removeSmallParts(Geometry polygon, double areaTolerance) {
    Class<?> geomBinding = polygon.getClass();
    if (Polygon.class.equals(geomBinding)) {
      return polygon;
    } else if (MultiPolygon.class.equals(geomBinding)) {
      List<Polygon> remains = new ArrayList<Polygon>();
      Geometry largest = polygon.getGeometryN(0);
      for (int index = 0; index < polygon.getNumGeometries(); index++) {
        Geometry part = polygon.getGeometryN(index);
        double area = part.getArea();
        if (area > largest.getArea()) {
          largest = part;
        }
        if (area >= areaTolerance) {
          remains.add((Polygon) part);
        }
      }
      if (remains.size() == 0) {
        remains.add((Polygon) largest);
      }
      // return multipolygon
      Geometry parts = polygon.getFactory().createMultiPolygon(
          GeometryFactory.toPolygonArray(remains));
      parts.setUserData(polygon.getUserData());
      return parts;
    } else {
      return polygon;
    }
  }
}

代码示例来源:origin: com.vividsolutions/jts-core

if (isCollection) {
 if (geom0 instanceof Polygon) {
  return createMultiPolygon(toPolygonArray(geomList));

代码示例来源:origin: org.geotools/gt-main

Polygon[] polygonArray = geometryFactory.toPolygonArray(geometries);
MultiPolygon multiPolygon = geometryFactory.createMultiPolygon(polygonArray);
multiPolygon.setUserData( getSRS() );

代码示例来源:origin: org.geotools/gt2-main

Polygon[] polygonArray = geometryFactory.toPolygonArray(geometries);
MultiPolygon multiPolygon = geometryFactory.createMultiPolygon(polygonArray);
multiPolygon.setUserData( getSRS() );

代码示例来源:origin: org.orbisgis/h2gis-utilities

MultiLineString voronoiSegs = geometryFactory.createMultiLineString(lineStrings.toArray(new LineString[lineStrings.size()]));
polygonizer.add(voronoiSegs);
return geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray(polygonizer.getPolygons()));

代码示例来源:origin: org.orbisgis/spatial-utilities

MultiLineString voronoiSegs = geometryFactory.createMultiLineString(lineStrings.toArray(new LineString[lineStrings.size()]));
polygonizer.add(voronoiSegs);
return geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray(polygonizer.getPolygons()));

相关文章