com.vividsolutions.jts.geom.Geometry.getCoordinates()方法的使用及代码示例

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

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

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: opentripplanner/OpenTripPlanner

/**
 * Returns the length of the geometry in meters.
 *
 * @param geometry
 * @return
 */
private double getGeometryLengthMeters(Geometry geometry) {
  Coordinate[] coordinates = geometry.getCoordinates();
  double d = 0;
  for (int i = 1; i < coordinates.length; ++i) {
    d += SphericalDistanceLibrary.distance(coordinates[i - 1], coordinates[i]);
  }
  return d;
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

@Override
public void serialize(Geometry arg, JsonGenerator jgen, SerializerProvider provider)
    throws IOException, JsonProcessingException {
  
  if (arg == null) {
    jgen.writeNull();
  }
  Coordinate[] lineCoords = arg.getCoordinates();
  List<Coordinate> coords = Arrays.asList(lineCoords);
  
  jgen.writeObject(PolylineEncoder.createEncodings(coords).getPoints());
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

@JsonSerialize(using = EncodedPolylineJSONSerializer.class)
@XmlJavaTypeAdapter(LineStringAdapter.class)
public LineString getGeometry() {
  if (geometry == null) {
    List<Coordinate> coords = new ArrayList<Coordinate>();
    for (RouteSegment segment : exemplarSegments) {
      if (segment.hopOut != null) {
        Geometry segGeometry = segment.getGeometry();
        coords.addAll(Arrays.asList(segGeometry.getCoordinates()));
      }
    }
    Coordinate[] coordArray = new Coordinate[coords.size()];
    geometry = GeometryUtils.getGeometryFactory().createLineString(
        coords.toArray(coordArray));
  }
  return geometry;
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

private Geometry removeDuplicatePoints(Geometry routeGeometry) {
  List<Coordinate> coords = new ArrayList<Coordinate>();
  Coordinate last = null;
  for (Coordinate c : routeGeometry.getCoordinates()) {
    if (!c.equals(last)) {
      last = c;
      coords.add(c);
    }
  }
  if (coords.size() < 2) {
    return null;
  }
  Coordinate[] coordArray = new Coordinate[coords.size()];
  return routeGeometry.getFactory().createLineString(coords.toArray(coordArray));
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

/**
 * @param index The index of the segment in the list
 * @return The partial geometry between this segment's stop and the next one.
 */
public LineString getGeometrySegment(int index) {
  RouteSegment segment = exemplarSegments.get(index);
  if (segment.hopOut != null) {
    return GeometryUtils.getGeometryFactory().createLineString(
        segment.getGeometry().getCoordinates());
  }
  return null;
}

代码示例来源:origin: osmandapp/Osmand

final Coordinate[] geomCoords = geom.getCoordinates();
if(geomCoords.length <= 0) {
  Collections.emptyList();

代码示例来源:origin: opentripplanner/OpenTripPlanner

private boolean isValid(Geometry geometry, Stop s0, Stop s1) {
  Coordinate[] coordinates = geometry.getCoordinates();
  if (coordinates.length < 2) {
    return false;
  }
  if (geometry.getLength() == 0) {
    return false;
  }
  for (Coordinate coordinate : coordinates) {
    if (Double.isNaN(coordinate.x) || Double.isNaN(coordinate.y)) {
      return false;
    }
  }
  Coordinate geometryStartCoord = coordinates[0];
  Coordinate geometryEndCoord = coordinates[coordinates.length - 1];
  
  Coordinate startCoord = new Coordinate(s0.getLon(), s0.getLat());
  Coordinate endCoord = new Coordinate(s1.getLon(), s1.getLat());
  if (SphericalDistanceLibrary.fastDistance(startCoord, geometryStartCoord) > maxStopToShapeSnapDistance) {
    return false;
  } else if (SphericalDistanceLibrary.fastDistance(endCoord, geometryEndCoord) > maxStopToShapeSnapDistance) {
    return false;
  }
  return true;
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

Coordinate[] coords = g.getCoordinates();

代码示例来源:origin: osmandapp/Osmand

final int minLineToLen) {
final Coordinate[] geomCoords = geom.getCoordinates();

代码示例来源:origin: opentripplanner/OpenTripPlanner

continue;
for (Coordinate c : g.getCoordinates()) {
  if (Double.isNaN(c.x) || Double.isNaN(c.y)) {
    LOG.warn(graph.addBuilderAnnotation(new BogusEdgeGeometry(e)));
  Coordinate edgeStartCoord = e.getFromVertex().getCoordinate();
  Coordinate edgeEndCoord = e.getToVertex().getCoordinate();
  Coordinate[] geometryCoordinates = g.getCoordinates();
  if (geometryCoordinates.length < 2) {
    LOG.warn(graph.addBuilderAnnotation(new BogusEdgeGeometry(e)));

代码示例来源:origin: opentripplanner/OpenTripPlanner

Geometry geometry = s1.getBackEdge().getGeometry();
if (geometry != null) {
  List<Coordinate> coordinates = new ArrayList<Coordinate>(Arrays.asList(geometry.getCoordinates()));
  for (int i = 0; i < coordinates.size(); ++i) {
    Coordinate coordinate = new Coordinate(coordinates.get(i));

代码示例来源:origin: opentripplanner/OpenTripPlanner

OffsetCurveBuilder offsetBuilder = new OffsetCurveBuilder(new PrecisionModel(),
    bufParams);
Coordinate[] coords = offsetBuilder.getOffsetCurve(midLineGeom.getCoordinates(),
    lineWidth * 0.4);
if (coords.length < 2)

代码示例来源:origin: opentripplanner/OpenTripPlanner

coords = circleShape.getCoordinates();

代码示例来源:origin: com.vividsolutions/jts

public Coordinate[] extractTargetCoordinates(Geometry g)
{
 // TODO: should do this more efficiently.  Use CoordSeq filter to get points, KDTree for uniqueness & queries
 Set ptSet = new TreeSet();
 Coordinate[] pts = g.getCoordinates();
 for (int i = 0; i < pts.length; i++) {
  ptSet.add(pts[i]);
 }
 return (Coordinate[]) ptSet.toArray(new Coordinate[0]);
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

/**
 * Splits the input geometry into two LineStrings at a fraction of the distance covered.
 */
public static P2<LineString> splitGeometryAtFraction(Geometry geometry, double fraction) {
  LineString empty = new LineString(null, gf);
  Coordinate[] coordinates = geometry.getCoordinates();
  CoordinateSequence sequence = gf.getCoordinateSequenceFactory().create(coordinates);
  LineString total = new LineString(sequence, gf);
  if (coordinates.length < 2) return new P2<LineString>(empty, empty);
  if (fraction <= 0) return new P2<LineString>(empty, total);
  if (fraction >= 1) return new P2<LineString>(total, empty);
  double totalDistance = total.getLength();
  double requestedDistance = totalDistance * fraction;
  // An index in JTS can actually refer to any point along the line. It is NOT an array index.
  LocationIndexedLine line = new LocationIndexedLine(geometry);
  LinearLocation l = LengthLocationMap.getLocation(geometry, requestedDistance);
  LineString beginning = (LineString) line.extractLine(line.getStartIndex(), l);
  LineString ending = (LineString) line.extractLine(l, line.getEndIndex());
  return new P2<LineString>(beginning, ending);
}

代码示例来源:origin: com.vividsolutions/jts

private void createVertices(Geometry geom)
{
  Coordinate[] coords = geom.getCoordinates();
  for (int i = 0; i < coords.length; i++) {
    Vertex v = new ConstraintVertex(coords[i]);
    constraintVertexMap.put(coords[i], v);
  }
}

代码示例来源:origin: com.vividsolutions/jts

public void loadSourceGeometries(Collection geoms)
{
  for (Iterator i = geoms.iterator(); i.hasNext(); ) {
    Geometry geom = (Geometry) i.next();
    loadVertices(geom.getCoordinates(), geom.getUserData());
  }
}

代码示例来源:origin: com.vividsolutions/jts

/**
 * Extracts the unique {@link Coordinate}s from the given {@link Geometry}.
 * @param geom the geometry to extract from
 * @return a List of the unique Coordinates
 */
public static CoordinateList extractUniqueCoordinates(Geometry geom)
{
  if (geom == null)
    return new CoordinateList();
  
  Coordinate[] coords = geom.getCoordinates();
  return unique(coords);
}

代码示例来源:origin: com.vividsolutions/jts

public final Geometry edit(Geometry geometry, GeometryFactory factory) {
 if (geometry instanceof LinearRing) {
  return factory.createLinearRing(edit(geometry.getCoordinates(),
    geometry));
 }
 if (geometry instanceof LineString) {
  return factory.createLineString(edit(geometry.getCoordinates(),
    geometry));
 }
 if (geometry instanceof Point) {
  Coordinate[] newCoordinates = edit(geometry.getCoordinates(),
    geometry);
  return factory.createPoint((newCoordinates.length > 0)
                ? newCoordinates[0] : null);
 }
 return geometry;
}

代码示例来源:origin: com.vividsolutions/jts

public void loadSourceGeometries(Geometry geomColl)
{
  for (int i = 0; i < geomColl.getNumGeometries(); i++) {
    Geometry geom = geomColl.getGeometryN(i);
    loadVertices(geom.getCoordinates(), geom.getUserData());
  }
}

相关文章