本文整理汇总了Java中com.vividsolutions.jts.geom.Coordinate类的典型用法代码示例。如果您正苦于以下问题:Java Coordinate类的具体用法?Java Coordinate怎么用?Java Coordinate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Coordinate类属于com.vividsolutions.jts.geom包,在下文中一共展示了Coordinate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: split
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
public static List<LineString> split(LineString given, int maxPoint) {
List<LineString> result = newArrayList();
Coordinate[] coordinates = given.getCoordinates();
int current = 0;
while (current < coordinates.length) {
int end = current + maxPoint - 1;
if (coordinates.length - end < 2) {
result.add(gf.createLineString(Arrays.copyOfRange(coordinates, current, coordinates.length)));
return result;
}
else {
result.add(gf.createLineString(Arrays.copyOfRange(coordinates, current, end + 1)));
current = end;
}
}
throw new IllegalStateException("Unexpected");
}
示例2: getShape
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
public Area getShape() {
Area maskArea = new Area();
Rectangle rect = new Rectangle(0, 0, reader.getWidth(), reader.getHeight());
GeometryFactory gf = new GeometryFactory();
Coordinate[] coords = new Coordinate[]{
new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
new Coordinate((int) rect.getMaxX(), (int) rect.getMinY()),
new Coordinate((int) rect.getMaxX(), (int) rect.getMaxY()),
new Coordinate((int) rect.getMinX(), (int) rect.getMaxY()),
new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
};
Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
for (Geometry p : glayer.getGeometries()) {
if (p.intersects(geom)) {
int[] xPoints = new int[p.getNumPoints()];
int[] yPoints = new int[p.getNumPoints()];
int i = 0;
for (Coordinate c : p.getCoordinates()) {
xPoints[i] = (int) (c.x);
yPoints[i++] = (int) (c.y);
}
maskArea.add(new Area(new java.awt.Polygon(xPoints, yPoints, p.getNumPoints())));
}
}
return maskArea;
}
示例3: contains
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
public boolean contains(int x, int y) {
GeometryFactory gf = new GeometryFactory();
Point geom = gf.createPoint(new Coordinate(x, y));
for (Geometry p : maskGeometries) {
if (p.contains(geom)) {
return true;
}
}
return false;
}
示例4: should_return_same_geom_if_necessary
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
@Test
public void should_return_same_geom_if_necessary() {
LineString linestring = linestring(
new Coordinate(0.0, 0.0),
new Coordinate(1.0, 0.0),
new Coordinate(1.0, 1.0));
List<LineString> lines = LongLineSplitter.split(linestring, 3);
assertThat(lines).containsExactly(
linestring(
new Coordinate(0.0, 0.0),
new Coordinate(1.0, 0.0),
new Coordinate(1.0, 1.0)));
assertThat(lines).isEqualTo(LongLineSplitter.split(linestring, 4));
assertThat(lines).isEqualTo(LongLineSplitter.split(linestring, 5));
}
示例5: range
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
private static final double[] range(Coordinate[] points, int offset, int length) {
double minX = points[0].x;
double maxX = points[0].x;
double minY = points[0].y;
double maxY = points[0].y;
// compute the bounding coordinates (@todo: cleanup brute force)
for (int i = 1; i < length; ++i) {
if (points[offset + i].x < minX) {
minX = points[offset + i].x;
}
if (points[offset + i].x > maxX) {
maxX = points[offset + i].x;
}
if (points[offset + i].y < minY) {
minY = points[offset + i].y;
}
if (points[offset + i].y > maxY) {
maxY = points[offset + i].y;
}
}
return new double[] {minX, maxX, minY, maxY};
}
示例6: createCatmullRom
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
/**
* Create a Catmull-Rom spline based on the given control points.
* The generated curve starts in the first control point and ends
* in the last control point.
* In addition, the curve intersects all the control points.
*
* @param controlPoints Control points of spline.
* @param maxDist Maximum distance between points along the spline.
* @return A Catmull-Rom spline based on the given control points.
*/
public static Spline3D createCatmullRom (Coordinate[] controlPoints, double maxDist) {
double[] cPoints = new double[controlPoints.length*3];
int counter = 0;
for (int i = 0; i < controlPoints.length; i++) {
cPoints[counter] = controlPoints[i].x;
cPoints[counter+1] = controlPoints[i].y;
cPoints[counter+2] = controlPoints[i].z;
counter+=3;
}
int numParts = 3;
Spline3D ret = null;
do {
ret = new Spline3D(new CatmullRomSpline (cPoints, numParts++).generate(), controlPoints, Spline3D.Type.SPLINE_CATMULL_ROM);
}
while(ret.computeMinMaxDistances()[1] > maxDist);
return ret;
}
示例7: addBufferPoints
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
private void addBufferPoints(List<Coordinate> points, Quadtree tree, double lon0, double lat0, double lon1,
double lat1, boolean addLast, boolean checkNeighbours, double bufferSize) {
double dx = (lon0 - lon1);
double dy = (lat0 - lat1);
double norm_length = Math.sqrt((dx * dx) + (dy * dy));
double scale = bufferSize /norm_length;
double dx2 = -dy*scale;
double dy2 = dx*scale;
addPoint(points, tree, lon0 + dx2, lat0 + dy2, checkNeighbours);
addPoint(points, tree, lon0 - dx2, lat0 - dy2, checkNeighbours);
// add a middle point if two points are too far from each other
if (norm_length > 2*bufferSize)
{
addPoint(points, tree, (lon0 + lon1)/2.0 + dx2, (lat0 + lat1)/2.0 + dy2, checkNeighbours);
addPoint(points, tree, (lon0 + lon1)/2.0 - dx2, (lat0 + lat1)/2.0 - dy2, checkNeighbours);
}
if (addLast) {
addPoint(points, tree, lon1 + dx2, lat1 + dy2, checkNeighbours);
addPoint(points, tree, lon1 - dx2, lat1 - dy2, checkNeighbours);
}
}
示例8: mouseClicked
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
/**
*
* @param imagePosition
* @param context
*/
public void mouseClicked(java.awt.Point imagePosition, OpenGLContext context) {
if(isEditable()){
this.selectedGeometry = null;
GeometryFactory gf = new GeometryFactory();
com.vividsolutions.jts.geom.Point p = gf.createPoint(new Coordinate(imagePosition.x, imagePosition.y));
for (Geometry temp : glayer.getGeometries()) {
if(temp instanceof Polygon){
Coordinate[] c=DistanceOp.nearestPoints(temp, p);
com.vividsolutions.jts.geom.Point nearest=gf.createPoint(c[0]);
if (nearest.isWithinDistance(temp,5 * context.getZoom())) {
this.selectedGeometry = temp;
System.out.println(""+temp.getCoordinate().x+","+temp.getCoordinate().y);
LayerPickedData.put(temp, glayer.getAttributes(temp));
break;
}
}
}
}
}
示例9: drawPoly
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
/**
*
* @param gl
* @param cs
* @param width
* @param height
* @param x
* @param y
*/
protected void drawPoly(GL2 gl,Coordinate[] cs,float width,float height,int x,int y,float rwidth){
gl.glLineWidth(rwidth);
gl.glBegin(GL.GL_LINE_STRIP);
for (int p = 0; p < cs.length; p++) {
double vx=(cs[p].x - x) / width;
double vy=1 - (cs[p].y - y) / height;
gl.glVertex2d(vx,vy);
}
//close polygon
Coordinate point = cs[0];
gl.glVertex2d((point.x - x) / width, 1 - (point.y - y) / height);
gl.glEnd();
gl.glFlush();
}
示例10: should_split_polygon_in_4
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
@Test
public void should_split_polygon_in_4() {
Polygon polygon = polygon(
new Coordinate(0.0, 0.0),
new Coordinate(1.0, 0.0),
new Coordinate(1.0, 1.0),
new Coordinate(0.0, 1.0),
new Coordinate(0.0, 0.0));
List<Geometry> geoms = LargePolygonSplitter.split(polygon, 0.4);
assertThat(geoms).extracting(Geometry::toString).containsExactly(
"POLYGON ((0.5 0, 0 0, 0 0.5, 0.5 0.5, 0.5 0))",
"POLYGON ((0 1, 0.5 1, 0.5 0.5, 0 0.5, 0 1))",
"POLYGON ((1 1, 1 0.5, 0.5 0.5, 0.5 1, 1 1))",
"POLYGON ((1 0, 0.5 0, 0.5 0.5, 1 0.5, 1 0))");
}
示例11: calculateLengthWGS84
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
/**
* Method that calculate the total length between the points of a coordinate
* array
*
* @param cArray
* Array of Coordinate
* @return dLength double Value Length
*/
public static double calculateLengthWGS84(Coordinate[] cArray) {
double length = 0;
int nLength = cArray.length;
if (nLength > 0) {
Coordinate c0 = cArray[0];
Coordinate c1 = null;
for (int index = 1; index < nLength; index++) {
c1 = cArray[index];
length += calcDistHaversine(c0.x, c0.y, c1.x, c1.y);
c0 = c1;
}
}
return length;
}
示例12: parse
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
public static Coordinate[] parse(String value, String separator, boolean is3D, boolean inverseXY)
{
String[] coordValues = value.split(separator);
Coordinate[] coords = new Coordinate[coordValues.length];
for (int i = 0; i < coordValues.length; i++)
{
String[] locations = coordValues[i].split(",");
if (inverseXY)
{
if (is3D && locations.length == 3)
coords[i] = new Coordinate(Double.parseDouble(locations[1]), Double.parseDouble(locations[0]), Double.parseDouble(locations[2]));
else
coords[i] = new Coordinate(Double.parseDouble(locations[1]), Double.parseDouble(locations[0]));
}
else
{
if (is3D && locations.length == 3)
coords[i] = new Coordinate(Double.parseDouble(locations[0]), Double.parseDouble(locations[1]), Double.parseDouble(locations[2]));
else
coords[i] = new Coordinate(Double.parseDouble(locations[0]), Double.parseDouble(locations[1]));
}
}
return coords;
}
示例13: main
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
public static void main(String[] args) {
ReedsSheppCarPlanner rsp = new ReedsSheppCarPlanner();
Coordinate footprint1 = new Coordinate(-2.0,0.5);
Coordinate footprint2 = new Coordinate(2.0,0.5);
Coordinate footprint3 = new Coordinate(2.0,-0.5);
Coordinate footprint4 = new Coordinate(-2.0,-0.5);
rsp.setRadius(0.5);
rsp.setFootprint(footprint1,footprint2,footprint3,footprint4);
JTSDrawingPanel panel = JTSDrawingPanel.makeEmpty("debug");
GeometryFactory gf = new GeometryFactory();
Polygon footprint = gf.createPolygon(new Coordinate[] {footprint1,footprint2,footprint3,footprint4,footprint1});
Polygon smoothedFootprint = gf.createPolygon(rsp.getCollisionCircleCenters());
System.out.println("Smoothing went from " + footprint.getCoordinates().length + " to " + smoothedFootprint.getCoordinates().length + " points");
panel.addGeometry("orig", footprint, true, true, true, "#00FF00");
panel.addGeometry("smooth", smoothedFootprint, false, false, true, "#FF0000");
for (int i = 0; i < smoothedFootprint.getCoordinates().length; i++) {
double delta = 0.1;
Coordinate p1 = new Coordinate(smoothedFootprint.getCoordinates()[i].x,smoothedFootprint.getCoordinates()[i].y);
Coordinate p2 = new Coordinate(smoothedFootprint.getCoordinates()[i].x+delta,smoothedFootprint.getCoordinates()[i].y+delta);
Coordinate p3 = new Coordinate(smoothedFootprint.getCoordinates()[i].x-delta,smoothedFootprint.getCoordinates()[i].y+delta);
panel.addGeometry("_cp"+i, gf.createPolygon(new Coordinate[] {p1,p2,p3,p1}), false, false, false, "#000000");
}
}
示例14: create
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的package包/类
public MatrixSearchContext create(Graph graph, Coordinate[] sources, Coordinate[] destinations, double maxSearchRadius) throws Exception
{
if (_locationCache == null)
_locationCache = new HashMap<Coordinate, LocationEntry>();
else
_locationCache.clear();
QueryGraph queryGraph = new QueryGraph(graph);
List<QueryResult> queryResults = new ArrayList<QueryResult>(sources.length + destinations.length);
resolveLocations(sources, queryResults, maxSearchRadius);
resolveLocations(destinations, queryResults, maxSearchRadius);
queryGraph.lookup(queryResults, _buffer);
MatrixLocations mlSources = createLocations(sources);
MatrixLocations mlDestinations = createLocations(destinations);
return new MatrixSearchContext(queryGraph, mlSources, mlDestinations);
}
示例15: getLength
import com.vividsolutions.jts.geom.Coordinate; //导入依赖的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();
}