本文整理汇总了Java中com.vividsolutions.jts.geom.CoordinateSequence.getCoordinate方法的典型用法代码示例。如果您正苦于以下问题:Java CoordinateSequence.getCoordinate方法的具体用法?Java CoordinateSequence.getCoordinate怎么用?Java CoordinateSequence.getCoordinate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.geom.CoordinateSequence
的用法示例。
在下文中一共展示了CoordinateSequence.getCoordinate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkRepeatedPoints2d
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
private static int checkRepeatedPoints2d(LineString lineString) {
int repeatedPoints = 0;
final CoordinateSequence coordSeq = lineString.getCoordinateSequence();
Coordinate nextCoord = null;
Coordinate prevCoord;
for (int i = 0; i < coordSeq.size(); ++i) {
prevCoord = nextCoord;
nextCoord = coordSeq.getCoordinate(i);
if (nextCoord.equals(prevCoord)) {
++repeatedPoints;
}
}
return repeatedPoints;
}
示例2: toJSON
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
public static JSONArray toJSON(LineString line, boolean inverseSeq)
{
// "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
int size = line.getNumPoints();
JSONArray arrCoords = new JSONArray(size);
CoordinateSequence seq = line.getCoordinateSequence();
Coordinate coord = null;
for (int i = 0; i < size; ++i)
{
coord = seq.getCoordinate(inverseSeq ? size - i - 1: i);
arrCoords.put(toJSON(coord));
}
return arrCoords;
}
示例3: filter
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
@Override
public void filter(CoordinateSequence seq, int index) {
if (index == 0) {
return;
}
Coordinate p0 = seq.getCoordinate(index - 1);
Coordinate p1 = seq.getCoordinate(index);
Coordinate midPt = new Coordinate(
(p0.x + p1.x) / 2,
(p0.y + p1.y) / 2);
this.minPtDist.initialize();
DistanceToPointFinder.computeDistance(this.geom, midPt, this.minPtDist);
this.maxPtDist.setMaximum(this.minPtDist);
}
示例4: averageNormal
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
/**
* Computes an average normal vector from a list of polygon coordinates.
* Uses Newell's method, which is based
* on the fact that the vector with components
* equal to the areas of the projection of the polygon onto
* the Cartesian axis planes is normal.
*
* @param seq the sequence of coordinates for the polygon
* @return a normal vector
*/
private Vector3D averageNormal(CoordinateSequence seq) {
int n = seq.size();
Coordinate sum = new Coordinate(0, 0, 0);
Coordinate p1 = new Coordinate(0, 0, 0);
Coordinate p2 = new Coordinate(0, 0, 0);
for (int i = 0; i < n - 1; i++) {
seq.getCoordinate(i, p1);
seq.getCoordinate(i + 1, p2);
sum.x += (p1.y - p2.y) * (p1.z + p2.z);
sum.y += (p1.z - p2.z) * (p1.x + p2.x);
sum.z += (p1.x - p2.x) * (p1.y + p2.y);
}
sum.x /= n;
sum.y /= n;
sum.z /= n;
Vector3D norm = Vector3D.create(sum).normalize();
return norm;
}
示例5: locatePointInRing
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
/**
* Determines the {@link Location} of a point in a ring.
*
* @param p the point to test
* @param ring a coordinate sequence forming a ring
* @return the location of the point in the ring
*/
public static int locatePointInRing(Coordinate p, CoordinateSequence ring) {
RayCrossingCounter counter = new RayCrossingCounter(p);
Coordinate p1 = new Coordinate();
Coordinate p2 = new Coordinate();
for (int i = 1; i < ring.size(); i++) {
ring.getCoordinate(i, p1);
ring.getCoordinate(i - 1, p2);
counter.countSegment(p1, p2);
if (counter.isOnSegment()) {
return counter.getLocation();
}
}
return counter.getLocation();
}
示例6: addLineStringToPath2D
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
public void addLineStringToPath2D(LineString lineString, Path2D path)
{
CoordinateSequence coordinateSequence = lineString
.getCoordinateSequence();
if (coordinateSequence.size() == 0)
{
// sometimes JTS gives an empty LineString
return;
}
// add the first coord to the path
Coordinate coord = coordinateSequence.getCoordinate(0);
path.moveTo(coord.x, coord.y);
// The loop stops at the second-last coord since the last coord will be
// the same as the start coord.
for (int i = 1; i < coordinateSequence.size() - 1; i++)
{
coord = coordinateSequence.getCoordinate(i);
path.lineTo(coord.x, coord.y);
}
path.closePath();
}
示例7: transformLinearRing
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
protected Geometry transformLinearRing(LinearRing geom, Geometry parent) {
CoordinateSequence seq = transformCoordinates(geom.getCoordinateSequence(), geom);
int seqSize = seq.size();
if ((seqSize > 0) && (seqSize < 4)) {
return factory.createLineString(seq);
} else if ((seqSize > 2) && (!seq.getCoordinate(0).equals2D(seq.getCoordinate(seqSize - 1)))) {
// sometimes, dropping out points above creates a linear
// ring that's no longer closed, which makes JTS very sad
Coordinate[] newArray = new Coordinate[seqSize+1];
for (int i = 0; i < seqSize; i += 1) {
newArray[i] = seq.getCoordinate(i);
}
newArray[seqSize] = seq.getCoordinate(0);
seq = createCoordinateSequence(newArray);
}
return factory.createLinearRing(seq);
}
示例8: lngLatToMeters
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
/**
* Converts geometry from lat/lon (EPSG:4326)) to Spherical Mercator
* (EPSG:3857)
*
* @param geometry the geometry to convert
* @return the geometry transformed to EPSG:3857
*/
public Geometry lngLatToMeters(Geometry geometry) {
GeometryTransformer transformer = new GeometryTransformer() {
@Override
protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) {
Coordinate[] newCoords = new Coordinate[coords.size()];
for (int i = 0; i < coords.size(); ++i) {
Coordinate coord = coords.getCoordinate(i);
newCoords[i] = lngLatToMeters(coord);
}
return new CoordinateArraySequence(newCoords);
}
};
Geometry result = transformer.transform(geometry);
return result;
}
示例9: metersToLngLat
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
/**
* Converts geometry from Spherical Mercator
* (EPSG:3857) to lat/lon (EPSG:4326))
*
* @param geometry the geometry to convert
* @return the geometry transformed to EPSG:4326
*/
public Geometry metersToLngLat(Geometry geometry) {
GeometryTransformer transformer = new GeometryTransformer() {
@Override
protected CoordinateSequence transformCoordinates(CoordinateSequence coords, Geometry parent) {
Coordinate[] newCoords = new Coordinate[coords.size()];
for (int i = 0; i < coords.size(); ++i) {
Coordinate coord = coords.getCoordinate(i);
newCoords[i] = metersToLngLat(coord);
}
return new CoordinateArraySequence(newCoords);
}
};
Geometry result = transformer.transform(geometry);
return result;
}
示例10: averageNormal
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
/**
* Computes an average normal vector from a list of polygon coordinates.
* Uses Newell's method, which is based
* on the fact that the vector with components
* equal to the areas of the projection of the polygon onto
* the Cartesian axis planes is normal.
*
* @param seq the sequence of coordinates for the polygon
* @return a normal vector
*/
private Vector3D averageNormal(CoordinateSequence seq)
{
int n = seq.size();
Coordinate sum = new Coordinate(0,0,0);
Coordinate p1 = new Coordinate(0,0,0);
Coordinate p2 = new Coordinate(0,0,0);
for (int i = 0; i < n - 1; i++) {
seq.getCoordinate(i, p1);
seq.getCoordinate(i+1, p2);
sum.x += (p1.y - p2.y)*(p1.z + p2.z);
sum.y += (p1.z - p2.z)*(p1.x + p2.x);
sum.z += (p1.x - p2.x)*(p1.y + p2.y);
}
sum.x /= n;
sum.y /= n;
sum.z /= n;
Vector3D norm = Vector3D.create(sum).normalize();
return norm;
}
示例11: getLengthMultiplierFromElevation
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
public static double getLengthMultiplierFromElevation(CoordinateSequence elev) {
double trueLength = 0;
double flatLength = 0;
double lastX = elev.getX(0);
double lastY = elev.getY(0);
for (int i = 1; i < elev.size(); ++i) {
Coordinate c = elev.getCoordinate(i);
double x = c.x - lastX;
double y = c.y - lastY;
trueLength += Math.sqrt((x * x) + (y * y));
flatLength += x;
lastX = c.x;
lastY = c.y;
}
if (flatLength == 0) { return 0; }
return trueLength / flatLength;
}
示例12: isLineStringContainedInBoundary
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
/**
* Tests if a linestring is completely contained in the boundary of the target rectangle.
*
* @param line the linestring to test
* @return true if the linestring is contained in the boundary
*/
private boolean isLineStringContainedInBoundary(LineString line) {
CoordinateSequence seq = line.getCoordinateSequence();
Coordinate p0 = new Coordinate();
Coordinate p1 = new Coordinate();
for (int i = 0; i < seq.size() - 1; i++) {
seq.getCoordinate(i, p0);
seq.getCoordinate(i + 1, p1);
if (!this.isLineSegmentContainedInBoundary(p0, p1)) {
return false;
}
}
return true;
}
示例13: checkIntersectionWithSegments
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
private void checkIntersectionWithSegments(LineString testLine) {
CoordinateSequence seq1 = testLine.getCoordinateSequence();
for (int j = 1; j < seq1.size(); j++) {
seq1.getCoordinate(j - 1, this.p0);
seq1.getCoordinate(j, this.p1);
if (this.rectIntersector.intersects(this.p0, this.p1)) {
this.hasIntersection = true;
return;
}
}
}
示例14: isWithinToleranceOfBoundary
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
private boolean isWithinToleranceOfBoundary(Coordinate pt) {
for (int i = 0; i < this.linework.getNumGeometries(); i++) {
LineString line = (LineString) this.linework.getGeometryN(i);
CoordinateSequence seq = line.getCoordinateSequence();
for (int j = 0; j < seq.size() - 1; j++) {
seq.getCoordinate(j, this.seg.p0);
seq.getCoordinate(j + 1, this.seg.p1);
double dist = this.seg.distance(pt);
if (dist <= this.boundaryDistanceTolerance) {
return true;
}
}
}
return false;
}
示例15: signedArea
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
/**
* Computes the signed area for a ring. The signed area is:
* <ul>
* <li>positive if the ring is oriented CW
* <li>negative if the ring is oriented CCW
* <li>zero if the ring is degenerate or flat
* </ul>
*
* @param ring the coordinates forming the ring
* @return the signed area of the ring
*/
public static double signedArea(CoordinateSequence ring) {
int n = ring.size();
if (n < 3) {
return 0.0;
}
/**
* Based on the Shoelace formula.
* http://en.wikipedia.org/wiki/Shoelace_formula
*/
Coordinate p0 = new Coordinate();
Coordinate p1 = new Coordinate();
Coordinate p2 = new Coordinate();
ring.getCoordinate(0, p1);
ring.getCoordinate(1, p2);
double x0 = p1.x;
p2.x -= x0;
double sum = 0.0;
for (int i = 1; i < n - 1; i++) {
p0.y = p1.y;
p1.x = p2.x;
p1.y = p2.y;
ring.getCoordinate(i + 1, p2);
p2.x -= x0;
sum += p1.x * (p0.y - p2.y);
}
return sum / 2.0;
}