Java Code Examples for com.esri.core.geometry.Polyline#lineTo()

The following examples show how to use com.esri.core.geometry.Polyline#lineTo() . 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: MatcherKState.java    From barefoot with Apache License 2.0 6 votes vote down vote up
private Polyline monitorRoute(MatcherCandidate candidate) {
    Polyline routes = new Polyline();
    MatcherCandidate predecessor = candidate;
    while (predecessor != null) {
        MatcherTransition transition = predecessor.transition();
        if (transition != null) {
            Polyline route = transition.route().geometry();
            routes.startPath(route.getPoint(0));
            for (int i = 1; i < route.getPointCount(); ++i) {
                routes.lineTo(route.getPoint(i));
            }
        }
        predecessor = predecessor.predecessor();
    }
    return routes;
}
 
Example 2
Source File: GeographyTest.java    From barefoot with Apache License 2.0 6 votes vote down vote up
@Test
public void testPathAzimuth() {
    Point reyk = new Point(-21.933333, 64.15);
    Point berl = new Point(13.408056, 52.518611);
    Point mosk = new Point(37.616667, 55.75);

    Polyline p = new Polyline();
    p.startPath(berl);
    p.lineTo(mosk);
    p.lineTo(reyk);

    assertEquals(azimuth(berl, mosk, true), spatial.azimuth(p, 0f), 1E-9);
    assertEquals(azimuth(mosk, reyk, false), spatial.azimuth(p, 1f), 1E-9);
    assertEquals(azimuth(berl, mosk, false),
            spatial.azimuth(p, spatial.distance(berl, mosk) / spatial.length(p)), 1E-9);
    Point c = spatial.interpolate(berl, mosk, 0.5);
    assertEquals(azimuth(berl, c, false),
            spatial.azimuth(p, spatial.distance(berl, c) / spatial.length(p)), 1E-9);
    Point d = spatial.interpolate(mosk, reyk, 0.5);
    assertEquals(azimuth(mosk, d, false), spatial.azimuth(p,
            (spatial.distance(berl, mosk) + spatial.distance(mosk, d)) / spatial.length(p)),
            1E-9);
}
 
Example 3
Source File: ST_LineString.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public BytesWritable evaluate(DoubleWritable ... xyPairs) throws UDFArgumentException{
	
	if (xyPairs == null || xyPairs.length == 0 ||  xyPairs.length%2 != 0) {
		return null;
	}

	try {		
		Polyline linestring = new Polyline();
		linestring.startPath(xyPairs[0].get(), xyPairs[1].get());
	
		for (int i=2; i<xyPairs.length; i+=2) {
			linestring.lineTo(xyPairs[i].get(), xyPairs[i+1].get());
		}
	
		return GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(linestring, null));
	} catch (Exception e) {
	    LogUtils.Log_InternalError(LOG, "ST_LineString: " + e);
	    return null;
	}
}
 
Example 4
Source File: ST_LineString.java    From spatial-framework-for-hadoop with Apache License 2.0 6 votes vote down vote up
public BytesWritable evaluate(ArrayList<DoubleWritable> xs, ArrayList<DoubleWritable> ys) throws UDFArgumentException {
	if (null == xs || null == ys || xs.size() == 0 || ys.size() == 0 || xs.size() != ys.size()) {
		return null;
	}

	try {		
		Polyline linestring = new Polyline();
	
		for (int ix=0; ix < xs.size(); ++ix) {
			DoubleWritable xdw = xs.get(ix), ydw = ys.get(ix);
			if (xdw == null || ydw == null) {
				LogUtils.Log_ArgumentsNull(LOG);
			}
			if (ix == 0) {
				linestring.startPath(xdw.get(), ydw.get());
			} else {
				linestring.lineTo(xdw.get(), ydw.get());
			}
		}
	
		return GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(linestring, null));
	} catch (Exception e) {
	    LogUtils.Log_InternalError(LOG, "ST_LineString: " + e);
	    return null;
	}
}
 
Example 5
Source File: GeoJsonParser.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a line string
 * Example:
 * [ [100.0, 0.0], [101.0, 1.0] ].
 * @param parser
 * @return a polyline.
 * @throws Exception
 */
private Polyline parseLineStringCoordinates(JsonNode node) {
  Polyline g = new Polyline();
  boolean first = true;
  ArrayNode points = (ArrayNode) node;
  for (JsonNode point : points) {
    Point p = parsePointCoordinates(point);
    if (first) {
      g.startPath(p);
      first = false;
    } else {
      g.lineTo(p);
    }  
  }
  return g;
}
 
Example 6
Source File: GeoFunctions.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Polygon getSubPolygon(Polygon polygon, int startIndex, int endIndex)
{
    Polyline boundary = new Polyline();
    boundary.startPath(polygon.getPoint(startIndex));
    for (int i = startIndex + 1; i < endIndex; i++) {
        Point current = polygon.getPoint(i);
        boundary.lineTo(current);
    }

    final Polygon newPolygon = new Polygon();
    newPolygon.add(boundary, false);
    return newPolygon;
}
 
Example 7
Source File: BearingProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private MapGeometry GenerateGeometry(Double ox, Double oy, Double dx, Double dy, SpatialReference sr)
{
	Point origin = new Point();
	Point destination = new Point();
	origin.setXY(ox, oy);
	destination.setXY(dx, dy);
	Polyline ln = new Polyline();
	ln.startPath(origin);
	ln.lineTo(destination);
	MapGeometry mapGeo = new MapGeometry(ln, sr);
	return mapGeo;
	
}
 
Example 8
Source File: BearingProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private MapGeometry GenerateGeometry(Double ox, Double oy, Double dx, Double dy, SpatialReference srin, SpatialReference srout)
{
	Point origin = new Point();
	Point destination = new Point();
	origin.setXY(ox, oy);
	destination.setXY(dx, dy);
	Polyline ln = new Polyline();
	ln.startPath(origin);
	ln.lineTo(destination);
	MapGeometry tmp_mapGeo = new MapGeometry(ln, srin);
	Geometry projected = GeometryEngine.project(tmp_mapGeo.getGeometry(), srin, srout);
	MapGeometry mapGeo = new MapGeometry(projected, srout);
	return mapGeo;
	
}
 
Example 9
Source File: IncrementalPointProcessor.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
private void processVertices(GeoEvent ge, Polyline polyln, double distTotal, long start, long end, LinearUnit lu, Boolean projected) throws MessagingException, FieldException
{
	int count = polyln.getPointCount();
	double currentDist = 0;
	long currentTime = start;
	long totalTime = end - start;
	Geometry outGeo = null;
	Point projGeo = null;
	Point lastPoint = null;
	for(int i = 0; i < count; ++i)
	{
		projGeo = polyln.getPoint(i);
		
		if(i!=0)
		{
			Polyline seg = new Polyline();
			seg.startPath(lastPoint);
			seg.lineTo(projGeo);
			double segDist = GeometryEngine.geodesicLength(seg, processSr, lu);
			currentDist += segDist;
			double percent = currentDist/distTotal;
			currentTime = (long) Math.floor((start + (totalTime*percent)));
			
		}
		if(projected)
		{
			outGeo = GeometryEngine.project(projGeo, processSr, outSr);
		}
		else
		{
			outGeo=projGeo;
		}
		MapGeometry outMapGeo = new MapGeometry(outGeo, outSr);
		double minutesFromStart = (currentTime - start)/60000;
		GeoEvent msg = createVertexGeoevent(ge, outMapGeo, currentDist, currentTime, minutesFromStart, i);
		send(msg);
		lastPoint = projGeo;
	}
}
 
Example 10
Source File: Road.java    From barefoot with Apache License 2.0 5 votes vote down vote up
static Polyline invert(Polyline geometry) {
    Polyline reverse = new Polyline();
    int last = geometry.getPointCount() - 1;
    reverse.startPath(geometry.getPoint(last));

    for (int i = last - 1; i >= 0; --i) {
        reverse.lineTo(geometry.getPoint(i));
    }

    return reverse;
}
 
Example 11
Source File: ST_MultiLineString.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
public BytesWritable evaluate(List<DoubleWritable> ... multipaths) throws UDFArgumentLengthException{
	
	if (multipaths == null || multipaths.length == 0) {
		LogUtils.Log_ArgumentsNull(LOG);
		return null;
	}

	try {
		Polyline mPolyline = new Polyline();

		int arg_idx=0;
		for (List<DoubleWritable> multipath : multipaths)
			{
				if (multipath.size() %2 != 0){
					LogUtils.Log_VariableArgumentLengthXY(LOG, arg_idx);
					return null;
				}

				mPolyline.startPath(multipath.get(0).get(), multipath.get(1).get());

				for (int i=2;i<multipath.size();i+=2){
					mPolyline.lineTo(multipath.get(i).get(), multipath.get(i+1).get());
				}
				arg_idx++;
			}

		return GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(mPolyline, null, true));
	} catch (Exception e) {
	    LogUtils.Log_InternalError(LOG, "ST_MultiLineString: " + e);
	    return null;
	}
}
 
Example 12
Source File: ST_LineString.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
public BytesWritable evaluate(ArrayList<BytesWritable> points) throws UDFArgumentException {
	if (null == points || points.size() == 0) {
		return null;
	}

	try {		
		Polyline linestring = new Polyline();
	
		for (int ix = 0; ix < points.size(); ++ix) {
			BytesWritable geomref = points.get(ix);
			OGCGeometry gcur = GeometryUtils.geometryFromEsriShape(geomref);
			if (gcur == null || GeometryUtils.getType(geomref) != GeometryUtils.OGCType.ST_POINT) {
				if (gcur == null)
					LogUtils.Log_ArgumentsNull(LOG);
				else
					LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POINT, GeometryUtils.getType(geomref));
				return null;
			}
			if (ix == 0) {
				linestring.startPath((Point)gcur.getEsriGeometry());
			} else {
				linestring.lineTo((Point)gcur.getEsriGeometry());
			}
		}
	
		return GeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(linestring, null));
	} catch (Exception e) {
	    LogUtils.Log_InternalError(LOG, "ST_LineString: " + e);
	    return null;
	}
}
 
Example 13
Source File: TestStGeomFromShape.java    From spatial-framework-for-hadoop with Apache License 2.0 5 votes vote down vote up
private static Polyline createPolyline() {
	Polyline line = new Polyline();
	line.startPath(createFirstLocation());
	line.lineTo(createSecondLocation());
	line.lineTo(createThirdLocation());
	line.lineTo(createFourthLocation());
	return line;
}
 
Example 14
Source File: ESRI.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a polyline from the given coordinate values.
 * Each {@link Double#NaN} coordinate value starts a new path.
 *
 * @param  dimension  the number of dimensions (2 or 3).
 * @throws UnsupportedOperationException if this operation is not implemented for the given number of dimensions.
 */
@Override
public Geometry createPolyline(final int dimension, final Vector... coordinates) {
    if (dimension != 2) {
        throw new UnsupportedOperationException(unsupported(dimension));
    }
    boolean lineTo = false;
    final Polyline path = new Polyline();
    for (final Vector v : coordinates) {
        if (v != null) {
            final int size = v.size();
            for (int i=0; i<size;) {
                final double x = v.doubleValue(i++);
                final double y = v.doubleValue(i++);
                if (Double.isNaN(x) || Double.isNaN(y)) {
                    lineTo = false;
                } else if (lineTo) {
                    path.lineTo(x, y);
                } else {
                    path.startPath(x, y);
                    lineTo = true;
                }
            }
        }
    }
    return path;
}
 
Example 15
Source File: ESRI.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
     * Merges a sequence of points or paths if the first instance is an implementation of this library.
     *
     * @throws ClassCastException if an element in the iterator is not an ESRI geometry.
     */
    @Override
    final Geometry tryMergePolylines(Object next, final Iterator<?> polylines) {
        if (!(next instanceof MultiPath || next instanceof Point)) {
            return null;
        }
        final Polyline path = new Polyline();
        boolean lineTo = false;
add:    for (;;) {
            if (next instanceof Point) {
                final Point pt = (Point) next;
                if (pt.isEmpty()) {
                    lineTo = false;
                } else {
                    final double x = ((Point) next).getX();
                    final double y = ((Point) next).getY();
                    if (lineTo) {
                        path.lineTo(x, y);
                    } else {
                        path.startPath(x, y);
                        lineTo = true;
                    }
                }
            } else {
                path.add((MultiPath) next, false);
                lineTo = false;
            }
            /*
             * 'polylines.hasNext()' check is conceptually part of 'for' instruction,
             * except that we need to skip this condition during the first iteration.
             */
            do if (!polylines.hasNext()) break add;
            while ((next = polylines.next()) == null);
        }
        return path;
    }
 
Example 16
Source File: TestStGeomFromShape.java    From spatial-framework-for-hadoop with Apache License 2.0 4 votes vote down vote up
private static Polyline createLine() {
	Polyline line = new Polyline();
	line.startPath(createFirstLocation());
	line.lineTo(createSecondLocation());
	return line;
}