本文整理汇总了Java中com.vividsolutions.jts.geom.LineString.getCoordinateN方法的典型用法代码示例。如果您正苦于以下问题:Java LineString.getCoordinateN方法的具体用法?Java LineString.getCoordinateN怎么用?Java LineString.getCoordinateN使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.geom.LineString
的用法示例。
在下文中一共展示了LineString.getCoordinateN方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLength
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
public static double getLength(Geometry geom, Boolean inMeters) throws Exception
{
if (!(geom instanceof LineString))
throw new Exception("Specified geometry type is not supported.");
LineString ls = (LineString)geom;
if (ls.getNumPoints() == 0)
return 0.0;
if (inMeters)
{
double length = 0.0;
DistanceCalc dc = new DistanceCalcEarth();
Coordinate c0 = ls.getCoordinateN(0);
for (int i = 1; i < ls.getNumPoints(); ++i)
{
Coordinate c1 = ls.getCoordinateN(i);
length += dc.calcDist(c0.y, c0.x, c1.y, c1.x);
c0 = c1;
}
return length;
}
else
return ls.getLength();
}
示例2: getLength
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
public double getLength(DistanceCalc dc) {
double res = 0;
if (this.getGeometry() != null) {
LineString ls = (LineString) this.getGeometry();
int nPoints = ls.getNumPoints();
if (nPoints > 1) {
Coordinate c = ls.getCoordinateN(0);
double x0 = c.x;
double y0 = c.y;
for (int i = 1; i < ls.getNumPoints(); i++) {
c = ls.getCoordinateN(i);
res += dc.calcDist(y0, x0, c.y, c.x);
x0 = c.x;
y0 = c.y;
}
}
}
return res;
}
示例3: indicesOf
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
public LinearLocation[] indicesOf(Geometry subLine) {
Coordinate startPt = ((LineString) subLine.getGeometryN(0)).getCoordinateN(0);
LineString lastLine = (LineString) subLine.getGeometryN(subLine.getNumGeometries() - 1);
Coordinate endPt = lastLine.getCoordinateN(lastLine.getNumPoints() - 1);
LocationIndexOfPoint locPt = new LocationIndexOfPoint(this.linearGeom);
LinearLocation[] subLineLoc = new LinearLocation[2];
subLineLoc[0] = locPt.indexOf(startPt);
// check for case where subline is zero length
if (subLine.getLength() == 0.0) {
subLineLoc[1] = (LinearLocation) subLineLoc[0].clone();
} else {
subLineLoc[1] = locPt.indexOfAfter(endPt, subLineLoc[0]);
}
return subLineLoc;
}
示例4: isClosed
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
private boolean isClosed(LineString[] array, int dimension) throws InvalidGeometryException {
int length = array.length;
int ordinatesLength = 0;
if (length != 0) {
LineString first = array[0];
LineString last = array[length - 1];
Coordinate coordinate1 = first.getCoordinateN(0);
Coordinate coordinate2 = last.getCoordinateN(last.getNumPoints() - 1);
for(int i=0; i<length && ordinatesLength<NUMBER_OF_COORDINATES_NEEDED_FOR_RING;i++) {
ordinatesLength += array[i].getNumPoints();
}
if (ordinatesLength < NUMBER_OF_COORDINATES_NEEDED_FOR_RING) {
throw new InvalidGeometryException(GeometryValidationErrorType.TOO_FEW_POINTS, coordinate1);
}
return coordinate1.equals2D(coordinate2);
}
return false;
}
示例5: isClosed
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
private boolean isClosed(LineString[] array) throws InvalidGeometryException {
int length = array.length;
int ordinatesLength = 0;
if (length != 0) {
LineString first = array[0];
LineString last = array[length - 1];
Coordinate coordinate1 = first.getCoordinateN(0);
Coordinate coordinate2 = last.getCoordinateN(last.getNumPoints() - 1);
for (int i = 0; i < length && ordinatesLength < NUMBER_OF_COORDINATES_NEEDED_FOR_RING; i++) {
ordinatesLength += array[i].getNumPoints();
}
if (ordinatesLength < NUMBER_OF_COORDINATES_NEEDED_FOR_RING) {
throw new InvalidGeometryException(GeometryValidationErrorType.TOO_FEW_POINTS, coordinate1);
}
return coordinate1.equals2D(coordinate2);
}
return false;
}
示例6: performMove
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
protected void performMove(Point imagePosition, OpenGLContext context) {
if (selectedGeometry == null) {
//super.mouseClicked(imagePosition, IClickable.BUTTON1, context);
if (this.editedPoint == null && selectedGeometry != null) {
if (type.equals(GeometryImage.POINT)) {
this.editedPoint = selectedGeometry.getCoordinate();
} else if (type.equals(GeometryImage.POLYGON)) {
LineString ls = ((Polygon) selectedGeometry).getExteriorRing();
for (int i = 0; i < ls.getNumPoints(); i++) {
Coordinate point = ls.getCoordinateN(i);
if (Math.abs(imagePosition.x - point.x) < 5 * context.getZoom() && Math.abs(imagePosition.y - point.y) < 5 * context.getZoom()) {
this.editedPoint = point;
break;
}
}
}
if (this.editedPoint == null) {
selectedGeometry.geometryChanged();
selectedGeometry = null;
}
} else {
if (selectedGeometry != null) {
selectedGeometry.geometryChanged();
}
this.editedPoint = null;
}
} else {
selectedGeometry.geometryChanged();
editedPoint = null;
selectedGeometry = null;
}
}
示例7: canMergeGeometries
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
private static boolean canMergeGeometries(List<Geometry> geoms)
{
int i = 0;
Coordinate pLast = null;
for(Geometry geom : geoms)
{
LineString ls = (LineString)geom;
if (i > 0)
{
int nCoords = ls.getNumPoints();
Coordinate pEnd = pLast;
Coordinate p0 = ls.getCoordinateN(0);
Coordinate pN = ls.getCoordinateN(nCoords - 1);
double dist0 = distCalc.calcDist(pEnd.y, pEnd.x, p0.y, p0.x);
double distN = distCalc.calcDist(pEnd.y, pEnd.x, pN.y, pN.x);
if (dist0 > 15 && distN > 15)
return false;
}
pLast = ls.getCoordinateN(ls.getNumPoints() - 1);
i++;
}
return true;
}
示例8: getArea
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
/**
* Convert a linear ring to an area using the coordinate transformation.
*
* @param ring the ring to create an area from
* @param ct the transformation to apply
* @return the created area.
*/
public static Area getArea(LineString ring, CoordinateTransformer ct) {
Path2D.Double path = new Path2D.Double();
Coordinate coord = ring.getCoordinateN(0);
path.moveTo(ct.getX(coord.x), ct.getY(coord.y));
for (int i = 1; i < ring.getNumPoints(); i++) {
coord = ring.getCoordinateN(i);
path.lineTo(ct.getX(coord.x), ct.getY(coord.y));
}
path.closePath();
return new Area(path);
}
示例9: getPath
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
/**
* Convert a linestring to a path using the coordinate transformation.
*
* @param string the string to create a path from.
* @param ct the transformation to apply.
* @return the path created.
*/
public static Path2D getPath(LineString string, CoordinateTransformer ct) {
Path2D.Double path = new Path2D.Double();
Coordinate coord = string.getCoordinateN(0);
path.moveTo(ct.getX(coord.x), ct.getY(coord.y));
for (int i = 1; i < string.getNumPoints(); i++) {
coord = string.getCoordinateN(i);
path.lineTo(ct.getX(coord.x), ct.getY(coord.y));
}
return path;
}
示例10: isSequenced
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
/**
* Tests whether a {@link Geometry} is sequenced correctly.
* {@link LineString}s are trivially sequenced.
* {@link MultiLineString}s are checked for correct sequencing.
* Otherwise, <code>isSequenced</code> is defined
* to be <code>true</code> for geometries that are not lineal.
*
* @param geom the geometry to test
* @return <code>true</code> if the geometry is sequenced or is not lineal
*/
public static boolean isSequenced(Geometry geom) {
if (!(geom instanceof MultiLineString)) {
return true;
}
MultiLineString mls = (MultiLineString) geom;
// the nodes in all subgraphs which have been completely scanned
Set prevSubgraphNodes = new TreeSet();
Coordinate lastNode = null;
List currNodes = new ArrayList();
for (int i = 0; i < mls.getNumGeometries(); i++) {
LineString line = (LineString) mls.getGeometryN(i);
Coordinate startNode = line.getCoordinateN(0);
Coordinate endNode = line.getCoordinateN(line.getNumPoints() - 1);
/**
* If this linestring is connected to a previous subgraph, geom is not sequenced
*/
if (prevSubgraphNodes.contains(startNode)) {
return false;
}
if (prevSubgraphNodes.contains(endNode)) {
return false;
}
if (lastNode != null) {
if (!startNode.equals(lastNode)) {
// start new connected sequence
prevSubgraphNodes.addAll(currNodes);
currNodes.clear();
}
}
currNodes.add(startNode);
currNodes.add(endNode);
lastNode = endNode;
}
return true;
}
示例11: getSegmentLength
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
/**
* Gets the length of the segment in the given
* Geometry containing this location.
*
* @param linearGeom a linear geometry
* @return the length of the segment
*/
public double getSegmentLength(Geometry linearGeom) {
LineString lineComp = (LineString) linearGeom.getGeometryN(this.componentIndex);
// ensure segment index is valid
int segIndex = this.segmentIndex;
if (this.segmentIndex >= lineComp.getNumPoints() - 1) {
segIndex = lineComp.getNumPoints() - 2;
}
Coordinate p0 = lineComp.getCoordinateN(segIndex);
Coordinate p1 = lineComp.getCoordinateN(segIndex + 1);
return p0.distance(p1);
}
示例12: getCoordinate
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
/**
* Gets the {@link Coordinate} along the
* given linear {@link Geometry} which is
* referenced by this location.
*
* @param linearGeom the linear geometry referenced by this location
* @return the <tt>Coordinate</tt> at the location
*/
public Coordinate getCoordinate(Geometry linearGeom) {
LineString lineComp = (LineString) linearGeom.getGeometryN(this.componentIndex);
Coordinate p0 = lineComp.getCoordinateN(this.segmentIndex);
if (this.segmentIndex >= lineComp.getNumPoints() - 1) {
return p0;
}
Coordinate p1 = lineComp.getCoordinateN(this.segmentIndex + 1);
return pointAlongSegmentByFraction(p0, p1, this.segmentFraction);
}
示例13: getSegment
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
/**
* Gets a {@link LineSegment} representing the segment of the
* given linear {@link Geometry} which contains this location.
*
* @param linearGeom a linear geometry
* @return the <tt>LineSegment</tt> containing the location
*/
public LineSegment getSegment(Geometry linearGeom) {
LineString lineComp = (LineString) linearGeom.getGeometryN(this.componentIndex);
Coordinate p0 = lineComp.getCoordinateN(this.segmentIndex);
// check for endpoint - return last segment of the line if so
if (this.segmentIndex >= lineComp.getNumPoints() - 1) {
Coordinate prev = lineComp.getCoordinateN(lineComp.getNumPoints() - 2);
return new LineSegment(prev, p0);
}
Coordinate p1 = lineComp.getCoordinateN(this.segmentIndex + 1);
return new LineSegment(p0, p1);
}
示例14: isOnRoundCap
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
/**
* Determine if the {@link Coordinate} is on the round cap of the buffer
* computed from the input {@link LineString} and the input distance. To
* determine that, it has to be at the given distance to the first or last
* point of the input {@link LineString} but closer to the first or last line
* segments.
* @param c a {@link Coordinate}
* @param line the input {@link LineString}
* @param distance distance used to compute the buffer
* @param tolerance tolerance used to compare distances
* @param startCoordinate if true, used the first point of the input
* {@link LineString}
* @return true if the input {@link Coordinate} is on the round cap
*/
private static boolean isOnRoundCap(Coordinate c, LineString line,
double distance, double tolerance, boolean startCoordinate) {
Coordinate c1 = startCoordinate ? line.getCoordinateN(0) : line
.getCoordinateN(line.getNumPoints() - 1);
double d = c.distance(c1);
if (d > distance - tolerance && d < distance + tolerance) {
Coordinate c2 = startCoordinate ? line.getCoordinateN(1) : line
.getCoordinateN(line.getNumPoints() - 2);
LineSegment l = new LineSegment(c2, c1);
d = l.distancePerpendicular(c);
return (d < distance - tolerance);
}
return false;
}
示例15: removeCollinearVertices
import com.vividsolutions.jts.geom.LineString; //导入方法依赖的package包/类
/**
* Removes collinear points from the provided linestring.
*
* @param ls the {@link LineString} to be simplified.
* @return a new version of the provided {@link LineString} with collinear points removed.
*/
static LineString removeCollinearVertices(final LineString ls) {
if (ls == null) {
throw new NullPointerException("The provided linestring is null");
}
final int N = ls.getNumPoints();
final boolean isLinearRing = ls instanceof LinearRing;
List<Coordinate> retain = new ArrayList<Coordinate>();
retain.add(ls.getCoordinateN(0));
int i0 = 0, i1 = 1, i2 = 2;
Coordinate firstCoord = ls.getCoordinateN(i0);
Coordinate midCoord;
Coordinate lastCoord;
while (i2 < N) {
midCoord = ls.getCoordinateN(i1);
lastCoord = ls.getCoordinateN(i2);
final int orientation = CGAlgorithms
.computeOrientation(firstCoord, midCoord, lastCoord);
// Colllinearity test
if (orientation != CGAlgorithms.COLLINEAR) {
// add midcoord and change head
retain.add(midCoord);
i0 = i1;
firstCoord = ls.getCoordinateN(i0);
}
i1++;
i2++;
}
retain.add(ls.getCoordinateN(N - 1));
//
// Return value
//
final int size = retain.size();
// nothing changed?
if (size == N) {
// free everything and return original
retain.clear();
return ls;
}
return isLinearRing ? ls.getFactory()
.createLinearRing(retain.toArray(new Coordinate[size])) : ls.getFactory()
.createLineString(retain.toArray(new Coordinate[size]));
}