当前位置: 首页>>代码示例>>Java>>正文


Java DistanceOp类代码示例

本文整理汇总了Java中com.vividsolutions.jts.operation.distance.DistanceOp的典型用法代码示例。如果您正苦于以下问题:Java DistanceOp类的具体用法?Java DistanceOp怎么用?Java DistanceOp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DistanceOp类属于com.vividsolutions.jts.operation.distance包,在下文中一共展示了DistanceOp类的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;
          }
     	}
     }
	}
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:25,代码来源:MaskVectorLayer.java

示例2: getNearestPoint

import com.vividsolutions.jts.operation.distance.DistanceOp; //导入依赖的package包/类
/**
 * le point de geom1 le plus proche de geom2
 * 
 * @param geom1
 * @param geom2
 * @return
 */
public static IDirectPosition getNearestPoint(IGeometry geom1,
    IGeometry geom2) {

  // conversion en geometrie JTS
  Geometry geom1_ = null;
  Geometry geom2_ = null;
  try {
    geom1_ = AdapterFactory.toGeometry(new GeometryFactory(), geom1);
    geom2_ = AdapterFactory.toGeometry(new GeometryFactory(), geom2);
  } catch (Exception e) {
    return null;
  }

  // recupere points les plus proches
  Coordinate[] cp = new DistanceOp(geom1_, geom2_).nearestPoints();

  return new DirectPosition(cp[0].x, cp[0].y, cp[0].z);
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:26,代码来源:CommonAlgorithms.java

示例3: getPointsLesPlusProches

import com.vividsolutions.jts.operation.distance.DistanceOp; //导入依赖的package包/类
public static IDirectPositionList getPointsLesPlusProches(IGeometry geom1,
    IGeometry geom2) {
  DirectPositionList dl = new DirectPositionList();

  Coordinate[] coords = null;
  try {
    coords = new DistanceOp(
        AdapterFactory.toGeometry(new GeometryFactory(), geom1),
        AdapterFactory.toGeometry(new GeometryFactory(), geom2))
            .nearestPoints();
    dl.add(new DirectPosition(coords[0].x, coords[0].y));
    dl.add(new DirectPosition(coords[1].x, coords[1].y));
  } catch (Exception e) {
    e.printStackTrace();
  }

  return dl;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:19,代码来源:CommonAlgorithms.java

示例4: 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;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:31,代码来源:JtsAlgorithms.java

示例5: 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]));
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:19,代码来源:Spatial.java

示例6: 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();
    }
}
 
开发者ID:Semantive,项目名称:jts,代码行数:21,代码来源:ClosestPointExample.java

示例7: 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]) + " )";
    }
}
 
开发者ID:Semantive,项目名称:jts,代码行数:23,代码来源:BufferDistanceValidator.java

示例8: 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;
}
 
开发者ID:SEEG-Oxford,项目名称:ABRAID-MP,代码行数:27,代码来源:GeometryUtils.java

示例9: measure

import com.vividsolutions.jts.operation.distance.DistanceOp; //导入依赖的package包/类
@Override
public double measure(
		final SimpleFeature x,
		final SimpleFeature y ) {

	double dist = Double.MAX_VALUE;
	final Coordinate[] coords = new DistanceOp(
			getGeometry(x),
			getGeometry(y)).nearestPoints();
	for (int i = 0; i < coords.length; i++) {
		for (int j = i + 1; j < coords.length; j++) {
			dist = Math.min(
					dist,
					coordinateDistanceFunction.measure(
							coords[j],
							coords[i]));
		}
	}
	return dist;
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:21,代码来源:FeatureDistanceFn.java

示例10: 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]);
}
 
开发者ID:locationtech,项目名称:geowave,代码行数:21,代码来源:ClusterItemDistanceFn.java

示例11: 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;
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:30,代码来源:TmcSegmentsCollection.java

示例12: 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]) + " )";
    }
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:22,代码来源:BufferDistanceValidator.java

示例13: isWithinDistance

import com.vividsolutions.jts.operation.distance.DistanceOp; //导入依赖的package包/类
/**
 * Tests whether the distance from this <code>Geometry</code>
 * to another is less than or equal to a specified value.
 *
 * @param geom the Geometry to check the distance to
 * @param distance the distance value to compare
 * @return <code>true</code> if the geometries are less than <code>distance</code> apart.
 */
public boolean isWithinDistance(Geometry geom, double distance) {
    double envDist = this.getEnvelopeInternal().distance(geom.getEnvelopeInternal());
    if (envDist > distance) {
        return false;
    }
    return DistanceOp.isWithinDistance(this, geom, distance);
/*
double geomDist = this.distance(geom);
if (geomDist > distance)
  return false;
return true;
*/
}
 
开发者ID:gegy1000,项目名称:Earth,代码行数:22,代码来源:Geometry.java

示例14: manhattanDistanceBetween

import com.vividsolutions.jts.operation.distance.DistanceOp; //导入依赖的package包/类
@Override
public int manhattanDistanceBetween(final IShape g1, final IShape g2) {

	IGridAgent s1 = g1.getAgent() != null && g1.getAgent().getSpecies() == this.getCellSpecies()
			? (IGridAgent) g1.getAgent() : null;
	IGridAgent s2 = g2.getAgent() != null && g2.getAgent().getSpecies() == this.getCellSpecies()
			? (IGridAgent) g2.getAgent() : null;

	if (s1 == null || s2 == null) {
		ILocation p1 = g1.isPoint() ? g1.getLocation() : null;
		ILocation p2 = g2.isPoint() ? g2.getLocation() : null;
		if (s1 == null) {
			s1 = (IGridAgent) this.getPlaceAt(g1.getLocation());
			if (!s1.covers(g1))
				s1 = null;
		}
		if (s2 == null) {
			s2 = (IGridAgent) this.getPlaceAt(g2.getLocation());
			if (!s2.covers(g2))
				s2 = null;
		}
		final Coordinate[] coord = new DistanceOp(g1.getInnerGeometry(), g2.getInnerGeometry()).nearestPoints();
		if (s1 == null) {
			p1 = new GamaPoint(coord[0]);
			s1 = (IGridAgent) this.getPlaceAt(p1);
		}
		if (s2 == null) {
			p2 = new GamaPoint(coord[1]);
			s2 = (IGridAgent) this.getPlaceAt(p2);
		}
	}

	final int dx = CmnFastMath.abs(s1.getX() - s2.getX());
	final int dy = CmnFastMath.abs(s1.getY() - s2.getY());
	if (usesVN)
		return dx + dy;
	return CmnFastMath.max(dx, dy);
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:39,代码来源:GamaSpatialMatrix.java

示例15: isWithinDistance

import com.vividsolutions.jts.operation.distance.DistanceOp; //导入依赖的package包/类
/**
 * Tests whether the distance from this <code>Geometry</code>
 * to another is less than or equal to a specified value.
 *
 * @param geom     the Geometry to check the distance to
 * @param distance the distance value to compare
 * @return <code>true</code> if the geometries are less than <code>distance</code> apart.
 */
public boolean isWithinDistance(Geometry geom, double distance) {
    double envDist = getEnvelopeInternal().distance(geom.getEnvelopeInternal());
    if (envDist > distance)
        return false;
    return DistanceOp.isWithinDistance(this, geom, distance);
/*
double geomDist = this.distance(geom);
if (geomDist > distance)
  return false;
return true;
*/
}
 
开发者ID:Semantive,项目名称:jts,代码行数:21,代码来源:Geometry.java


注:本文中的com.vividsolutions.jts.operation.distance.DistanceOp类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。