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

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

本文整理了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

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

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

  1. private static void writeGeometryCollection(Geometry collection, DynamicSliceOutput output)
  2. {
  3. output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code());
  4. for (int geometryIndex = 0; geometryIndex < collection.getNumGeometries(); geometryIndex++) {
  5. Geometry geometry = collection.getGeometryN(geometryIndex);
  6. int startPosition = output.size();
  7. // leave 4 bytes for the shape length
  8. output.appendInt(0);
  9. writeGeometry(geometry, output);
  10. int endPosition = output.size();
  11. int length = endPosition - startPosition - Integer.BYTES;
  12. output.getUnderlyingSlice().setInt(startPosition, length);
  13. }
  14. }

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

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

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

  1. int numPoints = geometry.getNumPoints();
  2. for (int i = 0; i < numGeometries; i++) {
  3. Polygon polygon = (Polygon) geometry.getGeometryN(i);
  4. if (polygon.getNumPoints() > 0) {
  5. numParts += polygon.getNumInteriorRing() + 1;
  6. int currentPoint = 0;
  7. for (int i = 0; i < numGeometries; i++) {
  8. Polygon polygon = (Polygon) geometry.getGeometryN(i);

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

  1. private static void writePolyline(Geometry geometry, SliceOutput output, boolean multitype)
  2. {
  3. int numParts;
  4. int numPoints = geometry.getNumPoints();
  5. if (multitype) {
  6. numParts = geometry.getNumGeometries();
  7. output.writeByte(GeometrySerializationType.MULTI_LINE_STRING.code());
  8. }
  9. else {
  10. numParts = numPoints > 0 ? 1 : 0;
  11. output.writeByte(GeometrySerializationType.LINE_STRING.code());
  12. }
  13. output.writeInt(EsriShapeType.POLYLINE.code);
  14. writeEnvelope(geometry, output);
  15. output.writeInt(numParts);
  16. output.writeInt(numPoints);
  17. int partIndex = 0;
  18. for (int i = 0; i < numParts; i++) {
  19. output.writeInt(partIndex);
  20. partIndex += geometry.getGeometryN(i).getNumPoints();
  21. }
  22. writeCoordinates(geometry.getCoordinates(), output);
  23. }

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

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

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

  1. public static ReferencedEnvelope reprojectEnvelope(
  2. ReferencedEnvelope sourceEnvelope,
  3. CoordinateReferenceSystem targetCRS,
  4. ReferencedEnvelope targetReferenceEnvelope)
  5. throws FactoryException, TransformException {
  6. Geometry reprojected =
  7. Utils.reprojectEnvelopeToGeometry(
  8. sourceEnvelope, targetCRS, targetReferenceEnvelope);
  9. if (reprojected == null) {
  10. return new ReferencedEnvelope(targetCRS);
  11. } else {
  12. if (reprojected.getNumGeometries() > 1) {
  13. return new ReferencedEnvelope(
  14. reprojected.getGeometryN(0).getEnvelopeInternal(), targetCRS);
  15. } else {
  16. return new ReferencedEnvelope(reprojected.getEnvelopeInternal(), targetCRS);
  17. }
  18. }
  19. }

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

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

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

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

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

  1. private static Geometry smoothMultiLineString(
  2. GeometryFactory factory, GeometrySmoother smoother, Geometry geom, double fit) {
  3. final int N = geom.getNumGeometries();
  4. LineString[] smoothed = new LineString[N];
  5. for (int i = 0; i < N; i++) {
  6. smoothed[i] =
  7. (LineString) smoothLineString(factory, smoother, geom.getGeometryN(i), fit);
  8. }
  9. return factory.createMultiLineString(smoothed);
  10. }

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

  1. public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
  2. // &lt;element maxOccurs="unbounded" minOccurs="0" ref="gml:curveMember"/&gt;
  3. List<Geometry> curveMemberList = node.getChildValues("curveMember");
  4. // &lt;element minOccurs="0" ref="gml:curveMembers"/&gt;
  5. Geometry curveMembers = (Geometry) node.getChildValue("curveMembers");
  6. List<LineString> lineStrings = new ArrayList<LineString>();
  7. if (curveMemberList != null) {
  8. for (Geometry curveMember : curveMemberList) {
  9. for (int i = 0; i < curveMember.getNumGeometries(); i++) {
  10. LineString lineString = (LineString) curveMember.getGeometryN(i);
  11. lineStrings.add(lineString);
  12. }
  13. }
  14. }
  15. if (curveMembers != null) {
  16. for (int i = 0; i < curveMembers.getNumGeometries(); i++) {
  17. LineString lineString = (LineString) curveMembers.getGeometryN(i);
  18. lineStrings.add(lineString);
  19. }
  20. }
  21. return gf.createMultiLineString(GeometryFactory.toLineStringArray(lineStrings));
  22. }

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

  1. /**
  2. * Adds the geometries into the collection by recursively splitting apart geometry collections,
  3. * so that geoms will contains only simple geometries.
  4. *
  5. * @param geoms
  6. * @param geometry
  7. * @param geomType
  8. * @return the geometry type that all geometries added to the collection conform to. Worst case
  9. * it's going to be Geometry.class
  10. */
  11. private Class accumulate(List<Geometry> geoms, Geometry geometry, Class geomType) {
  12. Class gtype = null;
  13. for (int i = 0; i < geometry.getNumGeometries(); i++) {
  14. Geometry g = geometry.getGeometryN(i);
  15. if (g instanceof GeometryCollection) {
  16. gtype = accumulate(geoms, g, geomType);
  17. } else {
  18. if (renderingEnvelope.intersects(g.getEnvelopeInternal())) {
  19. geoms.add(g);
  20. gtype = g.getClass();
  21. }
  22. }
  23. if (gtype == null) {
  24. gtype = g.getClass();
  25. } else if (geomType != null && !g.getClass().equals(geomType)) {
  26. gtype = Geometry.class;
  27. }
  28. }
  29. return gtype;
  30. }

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

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

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

  1. protected void encodeMembers(Geometry geometry, GMLWriter handler, String gmlId)
  2. throws SAXException, Exception {
  3. for (int i = 0; i < geometry.getNumGeometries(); i++) {
  4. handler.startElement(member, null);
  5. LineString line = (LineString) geometry.getGeometryN(i);
  6. String childId = gmlId + "." + (i + 1);
  7. if (curveEncoding && line instanceof CurvedGeometry) {
  8. ce.encode(line, null, handler, childId);
  9. } else if (line instanceof LinearRing) {
  10. lre.encode(line, null, handler, childId);
  11. } else {
  12. lse.encode(line, null, handler, childId);
  13. }
  14. handler.endElement(member);
  15. }
  16. }
  17. }

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

  1. @DescribeProcess(title = "Split Polygon", description = "Splits a polygon by a linestring")
  2. @DescribeResult(description = "The collection of split polygons")
  3. public static Geometry splitPolygon(
  4. @DescribeParameter(name = "polygon", description = "Polygon to split") Geometry polygon,
  5. @DescribeParameter(name = "line", description = "Linestring to split by")
  6. LineString line) {
  7. Geometry nodedLinework = polygon.getBoundary().union(line);
  8. Geometry polys = polygonize(nodedLinework);
  9. // Only keep polygons which are inside the input
  10. List<Polygon> output = new ArrayList<Polygon>();
  11. for (int i = 0; i < polys.getNumGeometries(); i++) {
  12. Polygon candpoly = (Polygon) polys.getGeometryN(i);
  13. // use interior point to test for inclusion in parent
  14. if (polygon.contains(candpoly.getInteriorPoint())) {
  15. output.add(candpoly);
  16. }
  17. }
  18. return polygon.getFactory()
  19. .createGeometryCollection(GeometryFactory.toGeometryArray(output));
  20. }

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

  1. public void testEncode() throws Exception {
  2. Geometry geometry = GML3MockData.multiLineString();
  3. GML3EncodingUtils.setID(geometry, "geometry");
  4. Document dom = encode(geometry, GML.MultiLineString);
  5. // print(dom);
  6. assertEquals("geometry", getID(dom.getDocumentElement()));
  7. assertEquals(2, dom.getElementsByTagNameNS(GML.NAMESPACE, "lineStringMember").getLength());
  8. NodeList children =
  9. dom.getElementsByTagNameNS(GML.NAMESPACE, GML.LineString.getLocalPart());
  10. assertEquals(2, children.getLength());
  11. assertEquals("geometry.1", getID(children.item(0)));
  12. assertEquals("geometry.2", getID(children.item(1)));
  13. checkDimension(dom, GML.MultiLineString.getLocalPart(), 2);
  14. checkDimension(dom, GML.LineString.getLocalPart(), 2);
  15. checkPosListOrdinates(dom, 2 * geometry.getGeometryN(0).getNumPoints());
  16. }
  17. }

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

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

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

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

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

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

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

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

相关文章