本文整理了Java中org.locationtech.jts.geom.Geometry.getCoordinates()
方法的一些代码示例,展示了Geometry.getCoordinates()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.getCoordinates()
方法的具体详情如下:
包路径:org.locationtech.jts.geom.Geometry
类名称:Geometry
方法名:getCoordinates
[英]Returns an array containing the values of all the vertices for this geometry. If the geometry is a composite, the array will contain all the vertices for the components, in the order in which the components occur in the geometry.
In general, the array cannot be assumed to be the actual internal storage for the vertices. Thus modifying the array may not modify the geometry itself. Use the CoordinateSequence#setOrdinate method (possibly on the components) to modify the underlying data. If the coordinates are modified, #geometryChanged must be called afterwards.
[中]返回一个数组,其中包含此几何体的所有顶点的值。如果几何体是复合的,则阵列将包含组件的所有顶点,按组件在几何体中出现的顺序排列。
通常,不能假定数组是顶点的实际内部存储。因此,修改阵列可能不会修改几何体本身。使用CoordinateSequence#SetCoordinate方法(可能在组件上)修改基础数据。如果修改了坐标,则必须随后调用#geometryChanged。
代码示例来源:origin: JanusGraph/janusgraph
public int size(Shape shape) {
switch(getType(shape)) {
case LINE:
case POLYGON:
case MULTIPOINT:
case MULTILINESTRING:
case MULTIPOLYGON:
return ((JtsGeometry) shape).getGeom().getCoordinates().length;
case POINT:
return 1;
case CIRCLE:
return 1;
case BOX:
return 2;
case GEOMETRYCOLLECTION:
return ((ShapeCollection<?>) shape).getShapes().stream().map(s -> (Shape) s).mapToInt(s -> size(s)).sum();
default:
throw new IllegalStateException("size() not supported for type: " + getType(shape));
}
}
代码示例来源:origin: hibernate/hibernate-orm
private boolean testVerticesEquality(Geometry geom1, Geometry geom2) {
if ( geom1.getNumPoints() != geom2.getNumPoints() ) {
return false;
}
for ( int i = 0; i < geom1.getNumPoints(); i++ ) {
Coordinate cn1 = geom1.getCoordinates()[i];
Coordinate cn2 = geom2.getCoordinates()[i];
if ( !cn1.equals2D( cn2 ) ) {
return false;
}
}
return true;
}
}
代码示例来源:origin: hibernate/hibernate-orm
private boolean testVerticesEquality(Geometry geom1, Geometry geom2) {
if ( geom1.getNumPoints() != geom2.getNumPoints() ) {
return false;
}
for ( int i = 0; i < geom1.getNumPoints(); i++ ) {
Coordinate cn1 = geom1.getCoordinates()[i];
Coordinate cn2 = geom2.getCoordinates()[i];
if ( !cn1.equals2D( cn2 ) ) {
return false;
}
}
return true;
}
}
代码示例来源:origin: JanusGraph/janusgraph
case MULTILINESTRING:
case MULTIPOLYGON:
Coordinate coordinate = ((JtsGeometry) shape).getGeom().getCoordinates()[position];
return new Geoshape.Point(coordinate.y, coordinate.x);
case POINT:
代码示例来源: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 Coordinate[] getCoordinates() {
return geometry.getCoordinates();
}
代码示例来源: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: graphhopper/graphhopper
/**
* This method fills the edgeIds hash with edgeIds found inside the specified geometry
*/
public void fillEdgeIDs(GHIntHashSet edgeIds, Geometry geometry, EdgeFilter filter) {
if (geometry instanceof Point) {
GHPoint point = GHPoint.create((Point) geometry);
findClosestEdgeToPoint(edgeIds, point, filter);
} else if (geometry instanceof LineString) {
PointList pl = PointList.fromLineString((LineString) geometry);
// TODO do map matching or routing
int lastIdx = pl.size() - 1;
if (pl.size() >= 2) {
double meanLat = (pl.getLatitude(0) + pl.getLatitude(lastIdx)) / 2;
double meanLon = (pl.getLongitude(0) + pl.getLongitude(lastIdx)) / 2;
findClosestEdge(edgeIds, meanLat, meanLon, filter);
}
} else if (geometry instanceof MultiPoint) {
for (Coordinate coordinate : geometry.getCoordinates()) {
findClosestEdge(edgeIds, coordinate.y, coordinate.x, filter);
}
}
}
代码示例来源:origin: mapsforge/mapsforge
private static List<Integer> toCoordinateList(Geometry jtsGeometry) {
Coordinate[] jtsCoords = jtsGeometry.getCoordinates();
ArrayList<Integer> result = new ArrayList<>();
for (int j = 0; j < jtsCoords.length; j++) {
LatLong latLong = new LatLong(jtsCoords[j].y, jtsCoords[j].x);
result.add(Integer.valueOf(LatLongUtils.degreesToMicrodegrees(latLong.latitude)));
result.add(Integer.valueOf(LatLongUtils.degreesToMicrodegrees(latLong.longitude)));
}
return result;
}
代码示例来源:origin: prestodb/presto
Coordinate[] coordinates = geometry.getCoordinates();
canonicalizePolygonCoordinates(coordinates, partIndexes, shellPart);
writeCoordinates(coordinates, output);
代码示例来源:origin: geotools/geotools
public ReferencedEnvelope3D get3DEnvelope(Geometry geom) {
Coordinate[] coordinates = geom.getCoordinates();
ReferencedEnvelope3D env = new ReferencedEnvelope3D();
for (Coordinate coordinate : coordinates) {
env.expandToInclude(coordinate);
}
return env;
}
代码示例来源:origin: geotools/geotools
private double pointToPolygonDist(Point point, MultiPolygon polygon) {
boolean inside = false;
double minDistSq = Double.POSITIVE_INFINITY;
for (int k = 0; k < polygon.getNumGeometries(); k++) {
Coordinate[] ring = polygon.getGeometryN(k).getCoordinates();
for (int i = 0, len = ring.length, j = len - 1; i < len; j = i++) {
Coordinate a = ring[i];
Coordinate b = ring[j];
if ((a.y > y != b.y > y) && (x < (b.x - a.x) * (y - a.y) / (b.y - a.y) + a.x))
inside = !inside;
minDistSq = Math.min(minDistSq, getSegDistSq(x, y, a, b));
}
}
// Points outside has a negative distance and thus will be weighted down later.
return (inside ? 1 : -1) * Math.sqrt(minDistSq);
}
// get squared distance from a point to a segment
代码示例来源:origin: geotools/geotools
private Geometry adaptGeometry(final Geometry value, Class<? extends Geometry> targetType) {
final Class<? extends Geometry> currentClass = value.getClass();
final GeometryFactory factory = value.getFactory();
Geometry adapted;
if (MultiPoint.class == targetType && Point.class == currentClass) {
adapted = factory.createMultiPoint(value.getCoordinates());
} else if (MultiLineString.class == targetType && LineString.class == currentClass) {
adapted = factory.createMultiLineString(new LineString[] {(LineString) value});
} else if (MultiPolygon.class == targetType && Polygon.class == currentClass) {
adapted = factory.createMultiPolygon(new Polygon[] {(Polygon) value});
} else {
throw new IllegalArgumentException(
"Don't know how to adapt "
+ currentClass.getName()
+ " to "
+ targetType.getName());
}
return adapted;
}
代码示例来源:origin: geotools/geotools
private Geometry buildShiftedGeometry(Geometry g, double shiftX, double shiftY) {
Geometry clone = g.copy();
Coordinate[] coords = clone.getCoordinates();
final int length = coords.length;
for (int i = 0; i < length; i++) {
Coordinate coord = coords[i];
coord.x += shiftX;
coord.y += shiftY;
}
return clone;
}
代码示例来源:origin: geotools/geotools
public static Geometry reverseGeometry(Geometry geom, boolean modify) {
if (geom instanceof Point) return (geom);
if (geom instanceof LineString) {
Coordinate[] reversed = reverseCoordinates(geom.getCoordinates(), modify);
if (modify) return (geom);
else return (gf().createLineString(reversed));
}
return (null);
}
代码示例来源:origin: geotools/geotools
@Test
public void toGeometry_Shape_Poly() {
Shape shape = new java.awt.Polygon(XPOINTS, YPOINTS, NPOINTS);
Geometry geom = JTS.toGeometry(shape);
assertTrue(geom instanceof LinearRing);
Coordinate[] coords = geom.getCoordinates();
assertEquals(NPOINTS + 1, coords.length);
CoordList list = new CoordList(coords);
Coordinate c = new Coordinate();
for (int i = 0; i < NPOINTS; i++) {
c.x = XPOINTS[i];
c.y = YPOINTS[i];
assertTrue(list.contains(c));
}
}
代码示例来源:origin: geotools/geotools
List<?> toList(Polygon p) {
BasicDBList l = new BasicDBList();
if (!CGAlgorithms.isCCW(p.getExteriorRing().getCoordinates())) {
l.add(toList(p.getExteriorRing().reverse().getCoordinates()));
} else {
l.add(toList(p.getExteriorRing().getCoordinateSequence()));
}
for (int i = 0; i < p.getNumInteriorRing(); i++) {
l.add(toList(p.getInteriorRingN(i).getCoordinateSequence()));
}
return l;
}
}
代码示例来源:origin: geotools/geotools
@Test
public void smoothLineString() {
Coordinate[] coords = getLineCoords();
LineString line = factory.createLineString(coords);
Geometry smoothed = JTS.smooth(line, 0);
assertTrue(smoothed instanceof LineString);
CoordList list = new CoordList(smoothed.getCoordinates());
assertTrue(list.containsAll(coords));
Envelope lineEnv = line.getEnvelopeInternal();
Envelope smoothEnv = smoothed.getEnvelopeInternal();
assertTrue(smoothEnv.covers(lineEnv));
}
代码示例来源:origin: geotools/geotools
@Test
public void smoothLinearRing() {
Coordinate[] coords = getPolyCoords();
LineString line = factory.createLinearRing(coords);
Geometry smoothed = JTS.smooth(line, 0);
assertTrue(smoothed instanceof LinearRing);
CoordList list = new CoordList(smoothed.getCoordinates());
assertTrue(list.containsAll(coords));
Envelope lineEnv = line.getEnvelopeInternal();
Envelope smoothEnv = smoothed.getEnvelopeInternal();
assertTrue(smoothEnv.covers(lineEnv));
}
代码示例来源:origin: geotools/geotools
@Test
public void smoothPolygon() {
Coordinate[] coords = getPolyCoords();
Polygon poly = factory.createPolygon(factory.createLinearRing(coords), null);
Geometry smoothed = JTS.smooth(poly, 0);
assertTrue(smoothed instanceof Polygon);
CoordList list = new CoordList(smoothed.getCoordinates());
assertTrue(list.containsAll(coords));
Envelope polyEnv = poly.getEnvelopeInternal();
Envelope smoothEnv = smoothed.getEnvelopeInternal();
assertTrue(smoothEnv.covers(polyEnv));
}
内容来源于网络,如有侵权,请联系作者删除!