本文整理了Java中org.locationtech.jts.geom.Geometry.getNumGeometries()
方法的一些代码示例,展示了Geometry.getNumGeometries()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.getNumGeometries()
方法的具体详情如下:
包路径:org.locationtech.jts.geom.Geometry
类名称:Geometry
方法名:getNumGeometries
[英]Returns the number of Geometrys in a GeometryCollection(or 1, if the geometry is not a collection).
[中]返回GeometryCollection中的几何体数(如果几何体不是集合,则返回1)。
代码示例来源:origin: graphhopper/graphhopper
for (int i = 0; i < jsonFeature.getGeometry().getNumGeometries(); i++) {
Geometry poly = jsonFeature.getGeometry().getGeometryN(i);
if (poly instanceof org.locationtech.jts.geom.Polygon)
代码示例来源: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: hibernate/hibernate-orm
protected boolean testTypeAndVertexEquality(Geometry geom1, Geometry geom2) {
if ( !geom1.getGeometryType().equals( geom2.getGeometryType() ) ) {
return false;
}
if ( geom1.getNumGeometries() != geom2.getNumGeometries() ) {
return false;
}
if ( geom1.getNumPoints() != geom2.getNumPoints() ) {
return false;
}
Coordinate[] coordinates1 = geom1.getCoordinates();
Coordinate[] coordinates2 = geom2.getCoordinates();
for ( int i = 0; i < coordinates1.length; i++ ) {
Coordinate c1 = coordinates1[i];
Coordinate c2 = coordinates2[i];
if ( !testCoordinateEquality( c1, c2 ) ) {
return false;
}
}
return true;
}
代码示例来源:origin: geotools/geotools
public int getNumGeometries() {
return geometry.getNumGeometries();
}
代码示例来源: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: prestodb/presto
private static void writePolygon(Geometry geometry, SliceOutput output, boolean multitype)
int numGeometries = geometry.getNumGeometries();
int numParts = 0;
int numPoints = geometry.getNumPoints();
代码示例来源: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
@Override
public void filter(Geometry gmtr) {
if (MultiPolygon.class.isAssignableFrom(binding)) {
if (gmtr.getArea() != 0.0d && gmtr.getGeometryType().equals("Polygon")) {
collection.add(gmtr);
}
}
if (MultiLineString.class.isAssignableFrom(binding)) {
if (gmtr.getLength() != 0.0d && gmtr.getGeometryType().equals("LineString")) {
collection.add(gmtr);
}
}
if (MultiPoint.class.isAssignableFrom(binding)) {
if (gmtr.getNumGeometries() > 0 && gmtr.getGeometryType().equals("Point")) {
collection.add(gmtr);
}
}
if (Point.class.isAssignableFrom(binding)) {
if (gmtr.getGeometryType().equals("Point")) {
collection.add(gmtr);
}
}
}
代码示例来源:origin: geotools/geotools
@DescribeProcess(
title = "Geometry Count",
description =
"Returns the total number of elements in a geometry collection. If not a geometry collection, returns 1. If empty, returns 0."
)
@DescribeResult(description = "Total number of geometries")
public static int numGeometries(
@DescribeParameter(name = "geom", description = "Input geometry") Geometry collection) {
return collection.getNumGeometries();
}
代码示例来源: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 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
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
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
// <element maxOccurs="unbounded" minOccurs="0" ref="gml:curveMember"/>
List<Geometry> curveMemberList = node.getChildValues("curveMember");
// <element minOccurs="0" ref="gml:curveMembers"/>
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
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: 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
@Test
public void testWrapGeometryLatLonMultipleTimes() throws Exception {
ReferencedEnvelope renderingEnvelope =
new ReferencedEnvelope(-90, 90, -580, 540, ED50_LATLON);
// a geometry close to the dateline
Geometry g = new WKTReader().read("POLYGON((-74 -33, -29 -33, -29 5, -74 5, -74 -33))");
// make sure the geometry is not wrapped, but it is preserved
ProjectionHandler handler =
ProjectionHandlerFinder.getHandler(renderingEnvelope, WGS84, true);
assertTrue(handler.requiresProcessing(g));
Geometry preProcessed = handler.preProcess(g);
MathTransform mt = handler.getRenderingTransform(CRS.findMathTransform(WGS84, ED50_LATLON));
Geometry transformed = JTS.transform(preProcessed, mt);
// post process (provide identity transform to force wrap heuristic)
Geometry postProcessed = handler.postProcess(mt, transformed);
assertTrue(postProcessed.isValid());
// should have been replicated three times
assertEquals(3, postProcessed.getNumGeometries());
}
代码示例来源:origin: geotools/geotools
@Test
public void smoothMultiLineString() {
LineString[] lines = new LineString[3];
lines[0] = factory.createLineString(getLineCoords(0));
lines[1] = factory.createLineString(getLineCoords(10));
lines[2] = factory.createLineString(getLineCoords(20));
MultiLineString mls = factory.createMultiLineString(lines);
Geometry smoothed = JTS.smooth(mls, 0);
assertTrue(smoothed instanceof MultiLineString);
assertEquals(3, smoothed.getNumGeometries());
Envelope mlsEnv = mls.getEnvelopeInternal();
Envelope smoothEnv = smoothed.getEnvelopeInternal();
assertTrue(smoothEnv.covers(mlsEnv));
}
代码示例来源:origin: geotools/geotools
@Test
public void smoothMultiPolygon() {
Polygon[] polys = new Polygon[3];
polys[0] = factory.createPolygon(factory.createLinearRing(getPolyCoords(0)), null);
polys[1] = factory.createPolygon(factory.createLinearRing(getPolyCoords(10)), null);
polys[2] = factory.createPolygon(factory.createLinearRing(getPolyCoords(20)), null);
MultiPolygon mp = factory.createMultiPolygon(polys);
Geometry smoothed = JTS.smooth(mp, 0);
assertTrue(smoothed instanceof MultiPolygon);
assertEquals(3, smoothed.getNumGeometries());
Envelope mpEnv = mp.getEnvelopeInternal();
Envelope smoothEnv = smoothed.getEnvelopeInternal();
assertTrue(smoothEnv.covers(mpEnv));
}
内容来源于网络,如有侵权,请联系作者删除!