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

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

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

Geometry.getNumGeometries介绍

[英]Returns the number of Geometrys in a GeometryCollection(or 1, if the geometry is not a collection).
[中]返回GeometryCollection中的几何体数(如果几何体不是集合,则返回1)。

代码示例

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

  1. for (int i = 0; i < jsonFeature.getGeometry().getNumGeometries(); i++) {
  2. Geometry poly = jsonFeature.getGeometry().getGeometryN(i);
  3. if (poly instanceof org.locationtech.jts.geom.Polygon)

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

  1. protected boolean testTypeAndVertexEquality(Geometry geom1, Geometry geom2) {
  2. if ( !geom1.getGeometryType().equals( geom2.getGeometryType() ) ) {
  3. return false;
  4. }
  5. if ( geom1.getNumGeometries() != geom2.getNumGeometries() ) {
  6. return false;
  7. }
  8. if ( geom1.getNumPoints() != geom2.getNumPoints() ) {
  9. return false;
  10. }
  11. Coordinate[] coordinates1 = geom1.getCoordinates();
  12. Coordinate[] coordinates2 = geom2.getCoordinates();
  13. for ( int i = 0; i < coordinates1.length; i++ ) {
  14. Coordinate c1 = coordinates1[i];
  15. Coordinate c2 = coordinates2[i];
  16. if ( !testCoordinateEquality( c1, c2 ) ) {
  17. return false;
  18. }
  19. }
  20. return true;
  21. }

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

  1. public int getNumGeometries() {
  2. return geometry.getNumGeometries();
  3. }

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

  1. private static void writePolygon(Geometry geometry, SliceOutput output, boolean multitype)
  2. int numGeometries = geometry.getNumGeometries();
  3. int numParts = 0;
  4. int numPoints = geometry.getNumPoints();

代码示例来源: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. @Override
  2. public void filter(Geometry gmtr) {
  3. if (MultiPolygon.class.isAssignableFrom(binding)) {
  4. if (gmtr.getArea() != 0.0d && gmtr.getGeometryType().equals("Polygon")) {
  5. collection.add(gmtr);
  6. }
  7. }
  8. if (MultiLineString.class.isAssignableFrom(binding)) {
  9. if (gmtr.getLength() != 0.0d && gmtr.getGeometryType().equals("LineString")) {
  10. collection.add(gmtr);
  11. }
  12. }
  13. if (MultiPoint.class.isAssignableFrom(binding)) {
  14. if (gmtr.getNumGeometries() > 0 && gmtr.getGeometryType().equals("Point")) {
  15. collection.add(gmtr);
  16. }
  17. }
  18. if (Point.class.isAssignableFrom(binding)) {
  19. if (gmtr.getGeometryType().equals("Point")) {
  20. collection.add(gmtr);
  21. }
  22. }
  23. }

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

  1. @DescribeProcess(
  2. title = "Geometry Count",
  3. description =
  4. "Returns the total number of elements in a geometry collection. If not a geometry collection, returns 1. If empty, returns 0."
  5. )
  6. @DescribeResult(description = "Total number of geometries")
  7. public static int numGeometries(
  8. @DescribeParameter(name = "geom", description = "Input geometry") Geometry collection) {
  9. return collection.getNumGeometries();
  10. }

代码示例来源: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 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. 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. 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. 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: 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. @Test
  2. public void testWrapGeometryLatLonMultipleTimes() throws Exception {
  3. ReferencedEnvelope renderingEnvelope =
  4. new ReferencedEnvelope(-90, 90, -580, 540, ED50_LATLON);
  5. // a geometry close to the dateline
  6. Geometry g = new WKTReader().read("POLYGON((-74 -33, -29 -33, -29 5, -74 5, -74 -33))");
  7. // make sure the geometry is not wrapped, but it is preserved
  8. ProjectionHandler handler =
  9. ProjectionHandlerFinder.getHandler(renderingEnvelope, WGS84, true);
  10. assertTrue(handler.requiresProcessing(g));
  11. Geometry preProcessed = handler.preProcess(g);
  12. MathTransform mt = handler.getRenderingTransform(CRS.findMathTransform(WGS84, ED50_LATLON));
  13. Geometry transformed = JTS.transform(preProcessed, mt);
  14. // post process (provide identity transform to force wrap heuristic)
  15. Geometry postProcessed = handler.postProcess(mt, transformed);
  16. assertTrue(postProcessed.isValid());
  17. // should have been replicated three times
  18. assertEquals(3, postProcessed.getNumGeometries());
  19. }

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

  1. @Test
  2. public void smoothMultiLineString() {
  3. LineString[] lines = new LineString[3];
  4. lines[0] = factory.createLineString(getLineCoords(0));
  5. lines[1] = factory.createLineString(getLineCoords(10));
  6. lines[2] = factory.createLineString(getLineCoords(20));
  7. MultiLineString mls = factory.createMultiLineString(lines);
  8. Geometry smoothed = JTS.smooth(mls, 0);
  9. assertTrue(smoothed instanceof MultiLineString);
  10. assertEquals(3, smoothed.getNumGeometries());
  11. Envelope mlsEnv = mls.getEnvelopeInternal();
  12. Envelope smoothEnv = smoothed.getEnvelopeInternal();
  13. assertTrue(smoothEnv.covers(mlsEnv));
  14. }

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

  1. @Test
  2. public void smoothMultiPolygon() {
  3. Polygon[] polys = new Polygon[3];
  4. polys[0] = factory.createPolygon(factory.createLinearRing(getPolyCoords(0)), null);
  5. polys[1] = factory.createPolygon(factory.createLinearRing(getPolyCoords(10)), null);
  6. polys[2] = factory.createPolygon(factory.createLinearRing(getPolyCoords(20)), null);
  7. MultiPolygon mp = factory.createMultiPolygon(polys);
  8. Geometry smoothed = JTS.smooth(mp, 0);
  9. assertTrue(smoothed instanceof MultiPolygon);
  10. assertEquals(3, smoothed.getNumGeometries());
  11. Envelope mpEnv = mp.getEnvelopeInternal();
  12. Envelope smoothEnv = smoothed.getEnvelopeInternal();
  13. assertTrue(smoothEnv.covers(mpEnv));
  14. }

相关文章