Java Code Examples for com.esri.core.geometry.GeometryEngine#distance()

The following examples show how to use com.esri.core.geometry.GeometryEngine#distance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private String GetDistAsString(Graphic g, SpatialReference inputSr, String units)
{
	com.esri.core.geometry.Geometry geo = g.getGeometry();
	com.esri.core.geometry.Geometry curGeo;
	
	if(!inputSr.equals(srBuffer))
	{
		curGeo = GeometryEngine.project(geo, inputSr, srBuffer);
	}
	else
	{
		curGeo=geo;
	}
	double tmpDist = GeometryEngine.distance(inGeometry, curGeo, srBuffer);
	UnitConverter uc = new UnitConverter();
	int inUnitWkid = uc.findWkid(srBuffer.getUnit().getName());
	String cn = uc.findConnonicalName(units);
	int outUnitWkid = uc.findWkid(cn);
	double dist;
	if(inUnitWkid!=outUnitWkid)
	{
		dist = uc.Convert(tmpDist, inUnitWkid, outUnitWkid);
	}
	else
	{
		dist=tmpDist;
	}
	
	DecimalFormat df = new DecimalFormat("#.00");
	return df.format(dist);
}
 
Example 2
Source File: QueryReportProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private String GetDistAsString(Map<String, Object> objGeo, SpatialReference inputSr, String units) throws JsonParseException, IOException
{
	Geometry geo = generateGeoFromMap(objGeo);
	com.esri.core.geometry.Geometry curGeo;
	
	if(!inputSr.equals(srBuffer))
	{
		curGeo = GeometryEngine.project(geo, inputSr, srBuffer);
	}
	else
	{
		curGeo=geo;
	}
	double tmpDist = GeometryEngine.distance(inGeometry, curGeo, srBuffer);
	UnitConverter uc = new UnitConverter();
	int inUnitWkid = uc.findWkid(srBuffer.getUnit().getName());
	String cn = uc.findConnonicalName(units);
	int outUnitWkid = uc.findWkid(cn);
	double dist;
	if(inUnitWkid!=outUnitWkid)
	{
		dist = uc.Convert(tmpDist, inUnitWkid, outUnitWkid);
	}
	else
	{
		dist=tmpDist;
	}
	
	DecimalFormat df = new DecimalFormat("#.00");
	return df.format(dist);
}
 
Example 3
Source File: IncrementalPointProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private IncrementPoint getNextPoint(Polyline polyln, Point startPt, Integer i, Double dist)
{
	Point startVertex = polyln.getPoint(i);
	Double currentDist = GeometryEngine.distance(startPt, startVertex, processSr);
	Point segStart = null;
	Point segEnd = null;
	Boolean multipleVertices = true;
	if(currentDist > dist)
	{
		segStart = startPt;
		segEnd = startVertex;
		multipleVertices = false;
	}
	while(currentDist < dist)
	{
		Point start = polyln.getPoint(i);
		Point end = polyln.getPoint(i+1);
		currentDist += GeometryEngine.distance(start, end, processSr);
		++i;
	}
	if(multipleVertices)
	{
		segStart = polyln.getPoint(i-1);
		segEnd = polyln.getPoint(i);
	}
	Double segLen = GeometryEngine.distance(segStart, segEnd, processSr);
	Double distOver = currentDist - dist;
	Double distOnSeg = segLen - distOver;
	Point p = findPtOnSegment(segStart, segEnd, distOnSeg);
	IncrementPoint ip = new IncrementPoint(p, i);
	return ip;
}
 
Example 4
Source File: GeoFunctions.java    From Bats with Apache License 2.0 4 votes vote down vote up
/** Returns the distance between {@code geom1} and {@code geom2}. */
public static double ST_Distance(Geom geom1, Geom geom2) {
  return GeometryEngine.distance(geom1.g(), geom2.g(), geom1.sr());
}
 
Example 5
Source File: GeoFunctions.java    From Bats with Apache License 2.0 4 votes vote down vote up
/** Returns whether {@code geom1} and {@code geom2} are within
 * {@code distance} of each other. */
public static boolean ST_DWithin(Geom geom1, Geom geom2, double distance) {
  final double distance1 =
      GeometryEngine.distance(geom1.g(), geom2.g(), geom1.sr());
  return distance1 <= distance;
}
 
Example 6
Source File: GeoFunctions.java    From presto with Apache License 2.0 4 votes vote down vote up
private static List<Point> interpolatePoints(OGCGeometry geometry, double fractionStep, boolean repeated)
{
    validateType("line_interpolate_point", geometry, EnumSet.of(LINE_STRING));
    if (fractionStep < 0 || fractionStep > 1) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "fraction must be between 0 and 1");
    }

    MultiPath path = (MultiPath) geometry.getEsriGeometry();

    if (fractionStep == 0) {
        return Collections.singletonList(path.getPoint(0));
    }
    if (fractionStep == 1) {
        return Collections.singletonList((path.getPoint(path.getPointCount() - 1)));
    }

    int pointCount = repeated ? (int) Math.floor(1 / fractionStep) : 1;
    List<Point> interpolatedPoints = new ArrayList<>(pointCount);

    double lineStringLength = path.calculateLength2D();
    Point previous = path.getPoint(0);
    double fractionConsumed = 0.0;
    double fractionIncrement = fractionStep;

    for (int i = 1; i < path.getPointCount() && interpolatedPoints.size() < pointCount; i++) {
        Point current = path.getPoint(i);
        double segmentLengthFraction = GeometryEngine.distance(previous, current, null) / lineStringLength;

        while (fractionStep < fractionConsumed + segmentLengthFraction && interpolatedPoints.size() < pointCount) {
            double segmentFraction = (fractionStep - fractionConsumed) / segmentLengthFraction;
            Point point = new Point();
            point.setX(previous.getX() + (current.getX() - previous.getX()) * segmentFraction);
            point.setY(previous.getY() + (current.getY() - previous.getY()) * segmentFraction);
            interpolatedPoints.add(point);
            fractionStep += fractionIncrement;
        }

        fractionConsumed += segmentLengthFraction;
        previous = current;
    }

    if (interpolatedPoints.size() < pointCount) {
        interpolatedPoints.add(path.getPoint(path.getPointCount() - 1));
    }

    return interpolatedPoints;
}
 
Example 7
Source File: GeoFunctions.java    From Quicksql with MIT License 4 votes vote down vote up
/** Returns the distance between {@code geom1} and {@code geom2}. */
public static double ST_Distance(Geom geom1, Geom geom2) {
  return GeometryEngine.distance(geom1.g(), geom2.g(), geom1.sr());
}
 
Example 8
Source File: GeoFunctions.java    From Quicksql with MIT License 4 votes vote down vote up
/** Returns whether {@code geom1} and {@code geom2} are within
 * {@code distance} of each other. */
public static boolean ST_DWithin(Geom geom1, Geom geom2, double distance) {
  final double distance1 =
      GeometryEngine.distance(geom1.g(), geom2.g(), geom1.sr());
  return distance1 <= distance;
}
 
Example 9
Source File: GeoFunctions.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Returns the distance between {@code geom1} and {@code geom2}. */
public static double ST_Distance(Geom geom1, Geom geom2) {
  return GeometryEngine.distance(geom1.g(), geom2.g(), geom1.sr());
}
 
Example 10
Source File: GeoFunctions.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Returns whether {@code geom1} and {@code geom2} are within
 * {@code distance} of each other. */
public static boolean ST_DWithin(Geom geom1, Geom geom2, double distance) {
  final double distance1 =
      GeometryEngine.distance(geom1.g(), geom2.g(), geom1.sr());
  return distance1 <= distance;
}
 
Example 11
Source File: ViewshedController.java    From defense-solutions-proofs-of-concept with Apache License 2.0 3 votes vote down vote up
/**
 * Displays a temporary graphic on the map representing the bounds of the viewshed
 * that will be calculated if the given points are used.
 * @param viewshedCenter the center of the proposed viewshed (i.e. the observer).
 * @param viewshedOuter the outer point of the proposed viewshed's boundaries.
 * @return the distance between the two points.
 * @see #showViewshedBoundsGraphic(com.esri.core.geometry.Point, double)
 * @see #removeViewshedBoundsGraphic()
 */
public double showViewshedBoundsGraphic(Point viewshedCenter, Point viewshedOuter) {
    double radius = GeometryEngine.distance(
            viewshedCenter,
            viewshedOuter,
            mapController.getSpatialReference());
    showViewshedBoundsGraphic(viewshedCenter, radius);
    return radius;
}