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

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

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

GeometryFactory.createGeometryCollection介绍

[英]Creates a GeometryCollection using the given Geometries; a null or empty array will create an empty GeometryCollection.
[中]使用给定的几何图形创建GeometryCollection;空数组或空数组将创建空GeometryCollection。

代码示例

代码示例来源:origin: prestodb/presto

private static Geometry readGeometryCollection(BasicSliceInput input)
{
  List<Geometry> geometries = new ArrayList<>();
  while (input.available() > 0) {
    // skip length
    input.readInt();
    GeometrySerializationType type = GeometrySerializationType.getForCode(input.readByte());
    geometries.add(readGeometry(input, type));
  }
  return GEOMETRY_FACTORY.createGeometryCollection(geometries.toArray(new Geometry[0]));
}

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

/**
 * Creates a GeometryCollection from a set of Geometrys
 *
 * @param geoms the component Geometrys
 * @return a GeometryCollection
 */
public GeometryCollection geometryCollection(Geometry... geoms) {
  return geomFact.createGeometryCollection(geoms);
}

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

public GeometryCollection createGeometryCollection(Geometry[] geometries) {
  return delegate.createGeometryCollection(geometries);
}

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

@Override
public GeometryCollection createGeometryCollection(Geometry[] geometries) {
  if (geometries != null && geometries.length == 1) {
    return new CollectionOfOne(geometries, this);
  } else {
    return super.createGeometryCollection(geometries);
  }
}

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

private Geometry toPolygon(GeometryFactory gf, final List<Polygon> polygons) {
  if (polygons.size() == 0) {
    return gf.createGeometryCollection(null);
  } else if (polygons.size() == 1) {
    return polygons.get(0);
  } else {
    return gf.createMultiPolygon(
        (Polygon[]) polygons.toArray(new Polygon[polygons.size()]));
  }
}

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

public GeometryCollection toGeometryCollection(BasicDBList obj) {
  List<Geometry> geoms = new ArrayList<Geometry>();
  for (Object o : obj) {
    geoms.add(toGeometry((DBObject) o)); // JG: changed from toGeometry( obj )
  }
  return geometryFactory.createGeometryCollection(geoms.toArray(new Geometry[geoms.size()]));
}

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

@Override
protected Geometry getEmpty() {
  if (EMPTY == null) {
    EMPTY = new GeometryFactory().createGeometryCollection(new Geometry[] {});
  }
  return EMPTY;
}

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

@Override
  public Geometry build(int jjtgeometryliteral) throws CQLException {

    List<Geometry> geometryList = popGeometryLiteral(jjtgeometryliteral);

    Geometry[] geometries = geometryList.toArray(new Geometry[geometryList.size()]);

    GeometryCollection geometryCollection =
        getGeometryFactory().createGeometryCollection(geometries);

    return geometryCollection;
  }
}

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

@Override
public boolean endObject() throws ParseException, IOException {
  if (delegate instanceof GeometryHandlerBase) {
    // end of a member geometry
    ((GeometryHandlerBase) delegate).endObject();
    Geometry geomObject = ((GeometryHandlerBase) delegate).getValue();
    if (geomObject != null) geoms.add(geomObject);
    delegate = NULL;
  } else {
    Geometry[] geometries = geoms.toArray(new Geometry[geoms.size()]);
    value = factory.createGeometryCollection(geometries);
    geoms = null;
  }
  return true;
}

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

private GeometryCollection readGeometryCollection() throws IOException, ParseException {
  int numGeom = dis.readInt();
  Geometry[] geoms = new Geometry[numGeom];
  for (int i = 0; i < numGeom; i++) {
    geoms[i] = readGeometry();
  }
  return factory.createGeometryCollection(geoms);
}

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

/**
 *
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated modifiable
 */
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
  ArrayList geometries = new ArrayList();
  if (node.hasChild(Geometry.class)) {
    geometries.addAll(node.getChildValues(Geometry.class));
  }
  if (node.hasChild(Geometry[].class)) {
    Geometry[] g = (Geometry[]) node.getChildValue(Geometry[].class);
    for (int i = 0; i < g.length; i++) geometries.add(g[i]);
  }
  return factory.createGeometryCollection(
      (Geometry[]) geometries.toArray(new Geometry[geometries.size()]));
}

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

private static Geometry smoothGeometryCollection(
    GeometryFactory factory, GeometrySmoother smoother, Geometry geom, double fit) {
  final int N = geom.getNumGeometries();
  Geometry[] smoothed = new Geometry[N];
  for (int i = 0; i < N; i++) {
    smoothed[i] = smooth(geom.getGeometryN(i), fit, factory, smoother);
  }
  return factory.createGeometryCollection(smoothed);
}

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

/**
 * Helper method for {@link #intersection(Geometry, Geometry) intersection(Geometry, Geometry)}
 */
private static GeometryCollection intersection(GeometryCollection gc1, GeometryCollection gc2) {
  List<Geometry> ret = new ArrayList<Geometry>();
  final int size = gc1.getNumGeometries();
  for (int i = 0; i < size; i++) {
    Geometry g1 = gc1.getGeometryN(i);
    List<Geometry> partial = intersection(gc2, g1);
    ret.addAll(partial);
  }
  return gc1.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(ret));
}

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

private static final Geometry cloneGeometry(GeometryCollection geom, int dimension) {
  if (geom.getNumGeometries() == 0) {
    Geometry[] gs = new Geometry[0];
    return geomFac.createGeometryCollection(gs);
  }
  ArrayList gs = new ArrayList(geom.getNumGeometries());
  int n = geom.getNumGeometries();
  for (int t = 0; t < n; t++) {
    gs.add(cloneGeometry(geom.getGeometryN(t), dimension));
  }
  return geomFac.buildGeometry(gs);
}

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

/** @see schema.Type#getValue(java.util.List) */
public Object getValue(Element element, ElementValue[] value, Attributes attrs, Map hints)
    throws SAXException {
  Element e = value[0].getElement();
  if (e == null) {
    if (!element.isNillable())
      throw new SAXException(
          "Internal error, ElementValues require an associated Element.");
    return null;
  }
  GeometryFactory gf = new GeometryFactory(DefaultCoordinateSequenceFactory.instance());
  Geometry[] geoms = new Geometry[value.length];
  for (int i = 0; i < value.length; i++) {
    geoms[i] = (Geometry) value[i].getValue();
  }
  return gf.createGeometryCollection(geoms);
}

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

@Test
public void testCoordinateDimensionGeometryCollectionEmpty() {
  Geometry geom = gf.createGeometryCollection(new Geometry[0]);
  // empty GCs have no sequences to carry dimension, so always report dim=3
  assertEquals(3, CoordinateSequences.coordinateDimension(geom));
}

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

@Test
public void testCoordinateDimensionGeometryCollectionEmptyLite3D() {
  Geometry geom = liteGF.createGeometryCollection(new Geometry[0]);
  assertEquals(3, CoordinateSequences.coordinateDimension(geom));
}

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

public void testValidConstruction() throws Exception {
  Literal a = new LiteralExpressionImpl(new Double(10));
  Literal b = new LiteralExpressionImpl("Label");
  Literal c = new LiteralExpressionImpl(Integer.valueOf(10));
  GeometryFactory gf = new GeometryFactory(new PrecisionModel());
  Literal d = new LiteralExpressionImpl(gf.createGeometryCollection(null));
}

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

private GeometryCollection makeSampleGeometryCollection(final GeometryFactory geomFac) {
  try {
    Geometry polyg = buildShiftedGeometry(makeSamplePolygon(geomFac), 50, 50);
    Geometry lineString = buildShiftedGeometry(makeSampleLineString(geomFac), 50, 50);
    return geomFac.createGeometryCollection(new Geometry[] {polyg, lineString});
  } catch (TopologyException te) {
    fail("Error creating sample polygon for testing " + te);
  }
  return null;
}

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

@DescribeProcess(
  title = "Polygonize",
  description =
      "Creates a set of polygons from linestrings delineating them.  The linestrings must be correctly noded (i.e. touch only at endpoints)."
)
@DescribeResult(description = "The collection of created polygons")
public static Geometry polygonize(
    @DescribeParameter(name = "geom", description = "Linework to polygonize")
        Geometry geom) {
  @SuppressWarnings("rawtypes")
  List lines = LineStringExtracter.getLines(geom);
  Polygonizer polygonizer = new Polygonizer();
  polygonizer.add(lines);
  @SuppressWarnings("rawtypes")
  Collection polys = polygonizer.getPolygons();
  Polygon[] polyArray = GeometryFactory.toPolygonArray(polys);
  return geom.getFactory().createGeometryCollection(polyArray);
}

相关文章