本文整理汇总了Java中com.vividsolutions.jts.geom.CoordinateSequence.size方法的典型用法代码示例。如果您正苦于以下问题:Java CoordinateSequence.size方法的具体用法?Java CoordinateSequence.size怎么用?Java CoordinateSequence.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.geom.CoordinateSequence
的用法示例。
在下文中一共展示了CoordinateSequence.size方法的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: 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;
}
示例3: 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();
}
示例4: toLineString
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
/**
* Generates the WKT for a <tt>LINESTRING</tt>
* specified by a {@link CoordinateSequence}.
*
* @param seq the sequence to write
* @return the WKT string
*/
public static String toLineString(CoordinateSequence seq) {
StringBuffer buf = new StringBuffer();
buf.append("LINESTRING ");
if (seq.size() == 0) {
buf.append(" EMPTY");
} else {
buf.append("(");
for (int i = 0; i < seq.size(); i++) {
if (i > 0) {
buf.append(", ");
}
buf.append(seq.getX(i)).append(" ").append(seq.getY(i));
}
buf.append(")");
}
return buf.toString();
}
示例5: appendSequenceText
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
/**
* Converts a <code>LineString</code> to <LineString Text> format, then
* appends it to the writer.
*
* @param lineString the <code>LineString</code> to process
* @param writer the output writer to append to
*/
private void appendSequenceText(CoordinateSequence seq, int level, boolean doIndent, Writer writer)
throws IOException {
if (seq.size() == 0) {
writer.write("EMPTY");
} else {
if (doIndent) {
this.indent(level, writer);
}
writer.write("(");
for (int i = 0; i < seq.size(); i++) {
if (i > 0) {
writer.write(", ");
if (this.coordsPerLine > 0
&& i % this.coordsPerLine == 0) {
this.indent(level + 1, writer);
}
}
this.appendCoordinate(seq, i, writer);
}
writer.write(")");
}
}
示例6: reverseRing
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
/**
* Does what it says, reverses the order of the Coordinates in the ring.
* <p>
* This is different then lr.reverses() in that a copy is produced using a
* new coordinate sequence.
* </p>
*
* @param lr The ring to reverse.
* @return A new ring with the reversed Coordinates.
*/
public static final LinearRing reverseRing(LinearRing lr) {
GeometryFactory gf = lr.getFactory();
CoordinateSequenceFactory csf = gf.getCoordinateSequenceFactory();
CoordinateSequence csOrig = lr.getCoordinateSequence();
int numPoints = csOrig.size();
int dimensions = csOrig.getDimension();
CoordinateSequence csNew = csf.create(numPoints, dimensions);
for (int i = 0; i < numPoints; i++) {
for (int j = 0; j < dimensions; j++) {
csNew.setOrdinate(numPoints - 1 - i, j, csOrig.getOrdinate(i, j));
}
}
return gf.createLinearRing(csNew);
}
示例7: 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();
}
示例8: 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);
}
示例9: getAsPoints
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
private static Points getAsPoints( CoordinateSequence seq, ICRS crs, boolean swapAxis ) {
int dim = seq.getDimension();
double[] coordinates = new double[ seq.size() * dim ];
int idx = 0;
for(int i = 0; i < seq.size(); i++) {
for(int j = 0; j < dim; j++) {
if(swapAxis) {
if(j == 0) {
coordinates[idx++] = seq.getOrdinate(i, 1);
} else if( j == 1) {
coordinates[idx++] = seq.getOrdinate(i, 0);
} else {
coordinates[idx++] = seq.getOrdinate(i, j);
}
} else {
coordinates[idx++] = seq.getOrdinate(i, j);
}
}
}
PackedCoordinateSequenceFactory factory = new PackedCoordinateSequenceFactory();
seq = factory.create(coordinates, dim);
return new JTSPoints( crs, seq );
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: distanceToEnd
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
public double distanceToEnd() {
CoordinateSequence cs = (this.edge.getGeometry()).getCoordinateSequence();
int s = this.seg + 1;
double x0 = cs.getX(s);
double y0 = cs.getY(s);
double dist = distanceLibrary.fastDistance(y0, x0, this.y, this.x); // dist along
// partial segment
int nc = cs.size();
for (; s < nc; s++) {
double x1 = cs.getX(s);
double y1 = cs.getY(s);
dist += distanceLibrary.fastDistance(y0, x0, y1, x1);
x0 = x1;
y0 = y1;
}
return dist;
}
示例14: 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;
}
示例15: getSignedArea
import com.vividsolutions.jts.geom.CoordinateSequence; //导入方法依赖的package包/类
private static double getSignedArea(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();
getMercatorCoordinate(ring, 0, p1);
getMercatorCoordinate(ring, 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;
getMercatorCoordinate(ring, i + 1, p2);
p2.x -= x0;
sum += p1.x * (p0.y - p2.y);
}
return sum / 2.0;
}