本文整理汇总了Java中com.vividsolutions.jts.operation.distance.DistanceOp.nearestPoints方法的典型用法代码示例。如果您正苦于以下问题:Java DistanceOp.nearestPoints方法的具体用法?Java DistanceOp.nearestPoints怎么用?Java DistanceOp.nearestPoints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.vividsolutions.jts.operation.distance.DistanceOp
的用法示例。
在下文中一共展示了DistanceOp.nearestPoints方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mouseClicked
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的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;
}
}
}
}
}
示例2: getClosestPoints
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
/**
* détermine les points les plus proches deux géométries. Les points sont
* donnés dans le même ordre que les deux géométries d'entrée. Compute the
* nearest points of two geometries. The points are presented in the same
* order as the input Geometries.
*
* @param g1 une géométrie
* @param g2 une autre géométrie
* @return la liste des 2 points les plus proches
*/
public static IDirectPositionList getClosestPoints(IGeometry g1, IGeometry g2) {
try {
Geometry jtsGeom1 = JtsGeOxygene.makeJtsGeom(g1);
Geometry jtsGeom2 = JtsGeOxygene.makeJtsGeom(g2);
Coordinate[] coord = DistanceOp.nearestPoints(jtsGeom1, jtsGeom2);
IDirectPosition dp1 = new DirectPosition(coord[0].x, coord[0].y);
IDirectPosition dp2 = new DirectPosition(coord[1].x, coord[1].y);
IDirectPositionList listePoints = new DirectPositionList();
listePoints.add(dp1);
listePoints.add(dp2);
return listePoints;
} catch (Exception e) {
JtsAlgorithms.logger.error(I18N
.getString("JtsAlgorithms.ClosestPointsError")); //$NON-NLS-1$
if (JtsAlgorithms.logger.isDebugEnabled()) {
JtsAlgorithms.logger.debug(e.getMessage());
}
}
return null;
}
示例3: closest_points_with
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
@operator (
value = "closest_points_with",
type = IType.LIST,
content_type = IType.POINT,
category = { IOperatorCategory.SPATIAL, IOperatorCategory.POINT },
concept = { IConcept.GEOMETRY, IConcept.SPATIAL_COMPUTATION, IConcept.SPATIAL_RELATION,
IConcept.POINT })
@doc (
value = "A list of two closest points between the two geometries.",
examples = { @example (
value = "geom1 closest_points_with(geom2)",
equals = "[pt1, pt2] with pt1 the closest point of geom1 to geom2 and pt1 the closest point of geom2 to geom1",
isExecutable = false) },
see = { "any_location_in", "any_point_in", "farthest_point_to", "points_at" })
public static IList<GamaPoint> closest_points_with(final IShape a, final IShape b) {
final Coordinate[] coors = DistanceOp.nearestPoints(a.getInnerGeometry(), b.getInnerGeometry());
return GamaListFactory.createWithoutCasting(Types.POINT, new GamaPoint(coors[0]), new GamaPoint(coors[1]));
}
示例4: findClosestPoint
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
public void findClosestPoint(String wktA, String wktB) {
System.out.println("-------------------------------------");
try {
Geometry A = wktRdr.read(wktA);
Geometry B = wktRdr.read(wktB);
System.out.println("Geometry A: " + A);
System.out.println("Geometry B: " + B);
DistanceOp distOp = new DistanceOp(A, B);
double distance = distOp.distance();
System.out.println("Distance = " + distance);
Coordinate[] closestPt = distOp.nearestPoints();
LineString closestPtLine = fact.createLineString(closestPt);
System.out.println("Closest points: " + closestPtLine
+ " (distance = " + closestPtLine.getLength() + ")");
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例5: checkMinimumDistance
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
/**
* Checks that two geometries are at least a minumum distance apart.
*
* @param g1 a geometry
* @param g2 a geometry
* @param minDist the minimum distance the geometries should be separated by
*/
private void checkMinimumDistance(Geometry g1, Geometry g2, double minDist) {
DistanceOp distOp = new DistanceOp(g1, g2, minDist);
minDistanceFound = distOp.distance();
if (minDistanceFound < minDist) {
isValid = false;
Coordinate[] pts = distOp.nearestPoints();
errorLocation = distOp.nearestPoints()[1];
errorIndicator = g1.getFactory().createLineString(pts);
errMsg = "Distance between buffer curve and input is too small "
+ "(" + minDistanceFound
+ " at " + WKTWriter.toLineString(pts[0], pts[1]) + " )";
}
}
示例6: findClosestPointOnGeometry
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
/**
* Finds the closest point on the geometry to the specified point. If the specified point is within the geometry,
* it returns a point that is equal to the specified point. If a closest point cannot be found, it returns null.
* @param geometry The geometry.
* @param point The specified point.
* @return The closest point, or the specified point if it is within the geometry, or null if a closest point
* cannot be found.
*/
public static Point findClosestPointOnGeometry(Geometry geometry, Point point) {
Coordinate[] coordinates = DistanceOp.nearestPoints(geometry, point);
// After the closest point is rounded, it may no longer lie in the geometry. So make tiny adjustments to the
// coordinates until it does. By default the original point is returned (this is because the first adjustment
// involves adding 0 to both x and y).
for (double xAdjustment : PRECISION_ADJUSTMENTS) {
for (double yAdjustment : PRECISION_ADJUSTMENTS) {
Point closestPoint = createPoint(coordinates[0].x + xAdjustment, coordinates[0].y + yAdjustment);
if (contains(geometry, closestPoint)) {
return closestPoint;
}
}
}
// We cannot find a closest point that conforms to our precision model, so return null
return null;
}
示例7: measure
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
@Override
public double measure(
final ClusterItem x,
final ClusterItem y ) {
final Geometry gx = x.getGeometry();
final Geometry gy = y.getGeometry();
if (gx instanceof Point && gy instanceof Point) {
return coordinateDistanceFunction.measure(
gx.getCoordinate(),
gy.getCoordinate());
}
final DistanceOp op = new DistanceOp(
gx,
gy);
Coordinate[] points = op.nearestPoints();
return coordinateDistanceFunction.measure(
points[0],
points[1]);
}
示例8: getClosestSegment
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
public TmcSegment getClosestSegment(Coordinate c, double thresholdDistance)
{
if (quadTree == null)
buildQuadTree();
Point p = geomFactory.createPoint(c);
BBox bbox = distanceCalc.createBBox(c.y, c.x, thresholdDistance);
Envelope env = new Envelope(bbox.minLon, bbox.maxLon, bbox.minLat, bbox.maxLat);
@SuppressWarnings("unchecked")
List<TmcSegment> segments = (List<TmcSegment>)(quadTree.query(env));
double minDistance = Double.MAX_VALUE;
TmcSegment res = null;
for( TmcSegment seg : segments)
{
Coordinate c1 = DistanceOp.nearestPoints(seg.getGeometry(), p)[0];
double dist = distanceCalc.calcDist(c.y, c.x, c1.y, c1.x);
if (dist < minDistance)
{
minDistance = dist;
if (dist <= thresholdDistance)
res = seg;
}
}
return res;
}
示例9: checkMinimumDistance
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
/**
* Checks that two geometries are at least a minumum distance apart.
*
* @param g1 a geometry
* @param g2 a geometry
* @param minDist the minimum distance the geometries should be separated by
*/
private void checkMinimumDistance(Geometry g1, Geometry g2, double minDist) {
DistanceOp distOp = new DistanceOp(g1, g2, minDist);
this.minDistanceFound = distOp.distance();
if (this.minDistanceFound < minDist) {
this.isValid = false;
Coordinate[] pts = distOp.nearestPoints();
this.errorLocation = distOp.nearestPoints()[1];
this.errorIndicator = g1.getFactory().createLineString(pts);
this.errMsg = "Distance between buffer curve and input is too small "
+ "(" + this.minDistanceFound
+ " at " + WKTWriter.toLineString(pts[0], pts[1]) + " )";
}
}
示例10: measure
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
@Override
public double measure(
final SimpleFeature x,
final SimpleFeature y ) {
final Geometry xGeo = getGeometry(x);
final Geometry yGeo = getGeometry(y);
final DistanceOp op = new DistanceOp(
xGeo,
yGeo);
Coordinate[] points = op.nearestPoints();
return coordinateDistanceFunction.measure(
points[0],
points[1]);
}
示例11: computeProfile
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
@Override
public DistanceProfile<ClusterProfileContext> computeProfile(
ClusterItem item1,
ClusterItem item2 ) {
DistanceProfile<ClusterProfileContext> localProfile = profile.get();
ClusterProfileContext context = localProfile.getContext();
final Geometry gx = item1.getGeometry();
final Geometry gy = item2.getGeometry();
context.setItem1(item1);
context.setItem2(item2);
if (gx instanceof Point && gy instanceof Point) {
context.setPoint1(gx.getCoordinate());
context.setPoint2(gy.getCoordinate());
}
else {
final DistanceOp op = new DistanceOp(
gx,
gy);
Coordinate[] points = op.nearestPoints();
context.setPoint1(points[0]);
context.setPoint2(points[1]);
}
localProfile.setDistance(coordinateDistanceFunction.measure(
context.getPoint1(),
context.getPoint2()));
return localProfile;
}
示例12: getDistanceInMeters
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
private static double getDistanceInMeters(Geometry one, Geometry two)
{
Coordinate[] nearest = DistanceOp.nearestPoints(one, two);
return SphericalEarthMath.distance(
JTSConst.toLatLon(nearest[0]), JTSConst.toLatLon(nearest[1]));
}
示例13: contains
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
private static boolean contains(Geometry geometry, Point point) {
// Ideally we would use Geometry.intersects() instead, but it sometimes reports "side location conflict" errors
Coordinate[] coordinate = DistanceOp.nearestPoints(geometry, point);
return point.getCoordinate().equals(coordinate[0]);
}
示例14: nearestPoints
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
public static Geometry nearestPoints(Geometry a, Geometry b)
{
Coordinate[] pts = DistanceOp.nearestPoints(a, b);
return geomFactory.createLineString(
new Coordinate[] { pts[0], pts[1] });
}
示例15: distanceMeters
import com.vividsolutions.jts.operation.distance.DistanceOp; //导入方法依赖的package包/类
/**
* Based on @see DistanceOp which computest
*
* "Computes the distance between the nearest points"
*
* Points have to be WGS84, are not checked.
*
* Distance calculated then with distanceSphericalSimple(coords[0], coords[1]) (nearest points)
* @param point
* @param ws
* @return
*/
public static double distanceMeters(Geometry g1, Geometry g2) {
DistanceOp distanceOp = new DistanceOp(g1, g2);
Coordinate[] coords = distanceOp.nearestPoints();
return GeometryUtils.distanceSphericalSimple(coords[0], coords[1]);
}