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

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

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

Geometry.getGeometryN介绍

[英]Returns an element Geometry from a GeometryCollection(or this, if the geometry is not a collection).
[中]从GeometryCollection返回元素几何体(如果几何体不是集合,则返回this

代码示例

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

Geometry poly = jsonFeature.getGeometry().getGeometryN(i);
if (poly instanceof org.locationtech.jts.geom.Polygon)
  borders.add(Polygon.create((org.locationtech.jts.geom.Polygon) poly));

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

private static void writeGeometryCollection(Geometry collection, DynamicSliceOutput output)
{
  output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code());
  for (int geometryIndex = 0; geometryIndex < collection.getNumGeometries(); geometryIndex++) {
    Geometry geometry = collection.getGeometryN(geometryIndex);
    int startPosition = output.size();
    // leave 4 bytes for the shape length
    output.appendInt(0);
    writeGeometry(geometry, output);
    int endPosition = output.size();
    int length = endPosition - startPosition - Integer.BYTES;
    output.getUnderlyingSlice().setInt(startPosition, length);
  }
}

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

public Geometry getGeometryN(int n) {
  return geometry.getGeometryN(n);
}

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

int numPoints = geometry.getNumPoints();
for (int i = 0; i < numGeometries; i++) {
  Polygon polygon = (Polygon) geometry.getGeometryN(i);
  if (polygon.getNumPoints() > 0) {
    numParts += polygon.getNumInteriorRing() + 1;
int currentPoint = 0;
for (int i = 0; i < numGeometries; i++) {
  Polygon polygon = (Polygon) geometry.getGeometryN(i);

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

private static void writePolyline(Geometry geometry, SliceOutput output, boolean multitype)
{
  int numParts;
  int numPoints = geometry.getNumPoints();
  if (multitype) {
    numParts = geometry.getNumGeometries();
    output.writeByte(GeometrySerializationType.MULTI_LINE_STRING.code());
  }
  else {
    numParts = numPoints > 0 ? 1 : 0;
    output.writeByte(GeometrySerializationType.LINE_STRING.code());
  }
  output.writeInt(EsriShapeType.POLYLINE.code);
  writeEnvelope(geometry, output);
  output.writeInt(numParts);
  output.writeInt(numPoints);
  int partIndex = 0;
  for (int i = 0; i < numParts; i++) {
    output.writeInt(partIndex);
    partIndex += geometry.getGeometryN(i).getNumPoints();
  }
  writeCoordinates(geometry.getCoordinates(), output);
}

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

/**
 * Set a synthetic gml:id on each child of a multigeometry. If the multigeometry has no gml:id,
 * this method has no effect. The synthetic gml:id of each child is constructed from that of the
 * parent by appending "." and then an integer starting from one for the first child.
 *
 * @param multiGeometry parent multigeometry containing the children to be modified
 */
static void setChildIDs(Geometry multiGeometry) {
  String id = getID(multiGeometry);
  if (id != null) {
    for (int i = 0; i < multiGeometry.getNumGeometries(); i++) {
      StringBuilder builder = new StringBuilder(id);
      builder.append("."); // separator
      builder.append(i + 1); // synthetic gml:id suffix one-based
      GML2EncodingUtils.setID(multiGeometry.getGeometryN(i), builder.toString());
    }
  }
}

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

public static ReferencedEnvelope reprojectEnvelope(
    ReferencedEnvelope sourceEnvelope,
    CoordinateReferenceSystem targetCRS,
    ReferencedEnvelope targetReferenceEnvelope)
    throws FactoryException, TransformException {
  Geometry reprojected =
      Utils.reprojectEnvelopeToGeometry(
          sourceEnvelope, targetCRS, targetReferenceEnvelope);
  if (reprojected == null) {
    return new ReferencedEnvelope(targetCRS);
  } else {
    if (reprojected.getNumGeometries() > 1) {
      return new ReferencedEnvelope(
          reprojected.getGeometryN(0).getEnvelopeInternal(), targetCRS);
    } else {
      return new ReferencedEnvelope(reprojected.getEnvelopeInternal(), targetCRS);
    }
  }
}

代码示例来源: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

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

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

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

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

public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
  // &lt;element maxOccurs="unbounded" minOccurs="0" ref="gml:curveMember"/&gt;
  List<Geometry> curveMemberList = node.getChildValues("curveMember");
  // &lt;element minOccurs="0" ref="gml:curveMembers"/&gt;
  Geometry curveMembers = (Geometry) node.getChildValue("curveMembers");
  List<LineString> lineStrings = new ArrayList<LineString>();
  if (curveMemberList != null) {
    for (Geometry curveMember : curveMemberList) {
      for (int i = 0; i < curveMember.getNumGeometries(); i++) {
        LineString lineString = (LineString) curveMember.getGeometryN(i);
        lineStrings.add(lineString);
      }
    }
  }
  if (curveMembers != null) {
    for (int i = 0; i < curveMembers.getNumGeometries(); i++) {
      LineString lineString = (LineString) curveMembers.getGeometryN(i);
      lineStrings.add(lineString);
    }
  }
  return gf.createMultiLineString(GeometryFactory.toLineStringArray(lineStrings));
}

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

/**
 * Adds the geometries into the collection by recursively splitting apart geometry collections,
 * so that geoms will contains only simple geometries.
 *
 * @param geoms
 * @param geometry
 * @param geomType
 * @return the geometry type that all geometries added to the collection conform to. Worst case
 *     it's going to be Geometry.class
 */
private Class accumulate(List<Geometry> geoms, Geometry geometry, Class geomType) {
  Class gtype = null;
  for (int i = 0; i < geometry.getNumGeometries(); i++) {
    Geometry g = geometry.getGeometryN(i);
    if (g instanceof GeometryCollection) {
      gtype = accumulate(geoms, g, geomType);
    } else {
      if (renderingEnvelope.intersects(g.getEnvelopeInternal())) {
        geoms.add(g);
        gtype = g.getClass();
      }
    }
    if (gtype == null) {
      gtype = g.getClass();
    } else if (geomType != null && !g.getClass().equals(geomType)) {
      gtype = Geometry.class;
    }
  }
  return gtype;
}

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

LineString gg = (LineString) g.getGeometryN(t);
  lines.add(gg);
int count = 0;
for (int t = 0; t < g.getNumGeometries(); t++) {
  count += accumulateLineStrings(g.getGeometryN(t), lines);

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

protected void encodeMembers(Geometry geometry, GMLWriter handler, String gmlId)
      throws SAXException, Exception {
    for (int i = 0; i < geometry.getNumGeometries(); i++) {
      handler.startElement(member, null);
      LineString line = (LineString) geometry.getGeometryN(i);
      String childId = gmlId + "." + (i + 1);
      if (curveEncoding && line instanceof CurvedGeometry) {
        ce.encode(line, null, handler, childId);
      } else if (line instanceof LinearRing) {
        lre.encode(line, null, handler, childId);
      } else {
        lse.encode(line, null, handler, childId);
      }
      handler.endElement(member);
    }
  }
}

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

@DescribeProcess(title = "Split Polygon", description = "Splits a polygon by a linestring")
@DescribeResult(description = "The collection of split polygons")
public static Geometry splitPolygon(
    @DescribeParameter(name = "polygon", description = "Polygon to split") Geometry polygon,
    @DescribeParameter(name = "line", description = "Linestring to split by")
        LineString line) {
  Geometry nodedLinework = polygon.getBoundary().union(line);
  Geometry polys = polygonize(nodedLinework);
  // Only keep polygons which are inside the input
  List<Polygon> output = new ArrayList<Polygon>();
  for (int i = 0; i < polys.getNumGeometries(); i++) {
    Polygon candpoly = (Polygon) polys.getGeometryN(i);
    // use interior point to test for inclusion in parent
    if (polygon.contains(candpoly.getInteriorPoint())) {
      output.add(candpoly);
    }
  }
  return polygon.getFactory()
      .createGeometryCollection(GeometryFactory.toGeometryArray(output));
}

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

public void testEncode() throws Exception {
    Geometry geometry = GML3MockData.multiLineString();
    GML3EncodingUtils.setID(geometry, "geometry");
    Document dom = encode(geometry, GML.MultiLineString);
    // print(dom);
    assertEquals("geometry", getID(dom.getDocumentElement()));
    assertEquals(2, dom.getElementsByTagNameNS(GML.NAMESPACE, "lineStringMember").getLength());
    NodeList children =
        dom.getElementsByTagNameNS(GML.NAMESPACE, GML.LineString.getLocalPart());
    assertEquals(2, children.getLength());
    assertEquals("geometry.1", getID(children.item(0)));
    assertEquals("geometry.2", getID(children.item(1)));

    checkDimension(dom, GML.MultiLineString.getLocalPart(), 2);
    checkDimension(dom, GML.LineString.getLocalPart(), 2);
    checkPosListOrdinates(dom, 2 * geometry.getGeometryN(0).getNumPoints());
  }
}

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

@Test
public void testUTMDatelineWrapping() throws Exception {
  CoordinateReferenceSystem crs = CRS.decode("EPSG:32601", true);
  ReferencedEnvelope re = new ReferencedEnvelope(300000, 409800, 5890200, 6000000, crs);
  MathTransform mt = CRS.findMathTransform(crs, WGS84);
  Geometry geom = JTS.toGeometry(re);
  ReferencedEnvelope targetReferenceEnvelope =
      new ReferencedEnvelope(-180, 180, -90, 90, WGS84);
  ProjectionHandler ph =
      ProjectionHandlerFinder.getHandler(targetReferenceEnvelope, crs, true);
  Geometry preProcessed = ph.preProcess(geom);
  Geometry transformed = JTS.transform(preProcessed, mt);
  Geometry postProcessed = ph.postProcess(mt.inverse(), transformed);
  // sits across the dateline and it's "small" (used to cover the entire planet)
  Envelope ppEnvelope = postProcessed.getGeometryN(0).getEnvelopeInternal();
  assertTrue(ppEnvelope.contains(180, 54));
  // the original width is 109km, at this latitude one degree of longitude is only 65km
  assertEquals(1.7, ppEnvelope.getWidth(), 0.1);
}

代码示例来源:origin: locationtech/spatial4j

/** Given {@code geoms} which has already been checked for being in world
 * bounds, return the minimal longitude range of the bounding box.
 */
protected Rectangle computeGeoBBox(Geometry geoms) {
 final Envelope env = geoms.getEnvelopeInternal();//for minY & maxY (simple)
 if (ctx.isGeo() && env.getWidth() > 180 && geoms.getNumGeometries() > 1)  {
  // This is ShapeCollection's bbox algorithm
  BBoxCalculator bboxCalc = new BBoxCalculator(ctx);
  for (int i = 0; i < geoms.getNumGeometries(); i++ ) {
   Envelope envI = geoms.getGeometryN(i).getEnvelopeInternal();
   bboxCalc.expandXRange(envI.getMinX(), envI.getMaxX());
   if (bboxCalc.doesXWorldWrap())
    break; // can't grow any bigger
  }
  return new RectangleImpl(bboxCalc.getMinX(), bboxCalc.getMaxX(), env.getMinY(), env.getMaxY(), ctx);
 } else {
  return new RectangleImpl(env.getMinX(), env.getMaxX(), env.getMinY(), env.getMaxY(), ctx);
 }
}

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

assertTrue(geoms[0] == smoothed.getGeometryN(0));
Geometry g = smoothed.getGeometryN(1);
assertTrue(g instanceof LineString);
g = smoothed.getGeometryN(2);
assertTrue(g instanceof Polygon);

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

assertEquals(numGeometries, 3);
for (int i = 0; i < numGeometries; i++) {
  assertTrue(preProcessed.getGeometryN(i) instanceof Polygon);

相关文章

微信公众号

最新文章

更多