Java Code Examples for com.esri.core.geometry.Polyline

The following examples show how to use com.esri.core.geometry.Polyline. These examples are extracted from open source projects. 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 Project: Bats   Author: lealone   File: GeoFunctions.java    License: Apache License 2.0 6 votes vote down vote up
/** Returns the OGC type of a geometry. */
private static Type type(Geometry g) {
  switch (g.getType()) {
  case Point:
    return Type.POINT;
  case Polyline:
    return Type.LINESTRING;
  case Polygon:
    return Type.POLYGON;
  case MultiPoint:
    return Type.MULTIPOINT;
  case Envelope:
    return Type.POLYGON;
  case Line:
    return Type.LINESTRING;
  case Unknown:
    return Type.Geometry;
  default:
    throw new AssertionError(g);
  }
}
 
Example #2
Source Project: presto   Author: prestosql   File: GeoFunctions.java    License: Apache License 2.0 6 votes vote down vote up
private static Point computeLineCentroid(Polyline polyline)
{
    double xSum = 0;
    double ySum = 0;
    double weightSum = 0;
    for (int i = 0; i < polyline.getPathCount(); i++) {
        Point startPoint = polyline.getPoint(polyline.getPathStart(i));
        Point endPoint = polyline.getPoint(polyline.getPathEnd(i) - 1);
        double dx = endPoint.getX() - startPoint.getX();
        double dy = endPoint.getY() - startPoint.getY();
        double length = sqrt(dx * dx + dy * dy);
        weightSum += length;
        xSum += (startPoint.getX() + endPoint.getX()) * length / 2;
        ySum += (startPoint.getY() + endPoint.getY()) * length / 2;
    }
    return new Point(xSum / weightSum, ySum / weightSum);
}
 
Example #3
Source Project: Quicksql   Author: Qihoo360   File: GeoFunctions.java    License: MIT License 6 votes vote down vote up
/** Returns the OGC type of a geometry. */
private static Type type(Geometry g) {
  switch (g.getType()) {
  case Point:
    return Type.POINT;
  case Polyline:
    return Type.LINESTRING;
  case Polygon:
    return Type.POLYGON;
  case MultiPoint:
    return Type.MULTIPOINT;
  case Envelope:
    return Type.POLYGON;
  case Line:
    return Type.LINESTRING;
  case Unknown:
    return Type.Geometry;
  default:
    throw new AssertionError(g);
  }
}
 
Example #4
Source Project: barefoot   Author: bmwcarit   File: BaseRoad.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs {@link BaseRoad} object.
 *
 * @param id Unique road identifier.
 * @param source Source vertex identifier (in road topology representation).
 * @param target Target vertex identifier (in road topology representation).
 * @param refid Identifier of road referring to some source data.
 * @param oneway Indicator if this road is a one-way road.
 * @param type Identifier of this road's type.
 * @param priority Road priority factor, which is greater or equal than one.
 * @param maxspeedForward Maximum speed limit for passing this road from source to target.
 * @param maxspeedBackward Maximum speed limit for passing this road from target to source.
 * @param length Length of road geometry in meters.
 * @param geometry Road's geometry from source to target as {@link Polyline} object.
 */
public BaseRoad(long id, long source, long target, long refid, boolean oneway, short type,
        float priority, float maxspeedForward, float maxspeedBackward, float length,
        Polyline geometry) {
    this.id = id;
    this.source = source;
    this.target = target;
    this.refid = refid;
    this.oneway = oneway;
    this.type = type;
    this.priority = priority;
    this.maxspeedForward = maxspeedForward;
    this.maxspeedBackward = maxspeedBackward;
    this.length = length;
    this.geometry = OperatorExportToWkb.local()
            .execute(WkbExportFlags.wkbExportLineString, geometry, null).array();
}
 
Example #5
Source Project: barefoot   Author: bmwcarit   File: MatcherKState.java    License: 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 #6
Source Project: barefoot   Author: bmwcarit   File: GeographyTest.java    License: 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 #7
Source Project: barefoot   Author: bmwcarit   File: RoadPointTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJSON() throws JSONException {
    String wkt = "LINESTRING(11.3136273 48.0972002,11.3138846 48.0972999)";
    BaseRoad osm = new BaseRoad(0L, 1L, 2L, 4L, true, (short) 5, 5.1F, 6.1F, 6.2F, 7.1F,
            (Polyline) GeometryEngine.geometryFromWkt(wkt, WktImportFlags.wktImportDefaults,
                    Geometry.Type.Polyline));

    RoadMap map = new RoadMap();
    map.add(new Road(osm, Heading.forward));

    RoadPoint point1 = new RoadPoint(map.get(0L), 0.2);

    String json = point1.toJSON().toString();
    RoadPoint point2 = RoadPoint.fromJSON(new JSONObject(json), map);

    assertEquals(point1.edge().id(), point2.edge().id());
    assertEquals(point1.fraction(), point2.fraction(), 1E-6);
    assertEquals(point1.edge().source(), point2.edge().source());
    assertEquals(point1.edge().target(), point2.edge().target());
}
 
Example #8
Source Project: barefoot   Author: bmwcarit   File: RoadTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testJSON() throws JSONException {
    String wkt = "LINESTRING(11.3136273 48.0972002,11.3138846 48.0972999)";
    BaseRoad osm = new BaseRoad(0L, 1L, 2L, 4L, true, (short) 5, 5.1F, 6.1F, 6.2F, 7.1F,
            (Polyline) GeometryEngine.geometryFromWkt(wkt, WktImportFlags.wktImportDefaults,
                    Geometry.Type.Polyline));

    Road road = new Road(osm, Heading.forward);
    RoadMap map = new RoadMap();
    map.add(road);

    String json = road.toJSON().toString();
    Road road2 = Road.fromJSON(new JSONObject(json), map);

    assertEquals(road, road2);
}
 
Example #9
Source Project: calcite   Author: apache   File: GeoFunctions.java    License: Apache License 2.0 6 votes vote down vote up
/** Returns the OGC type of a geometry. */
private static Type type(Geometry g) {
  switch (g.getType()) {
  case Point:
    return Type.POINT;
  case Polyline:
    return Type.LINESTRING;
  case Polygon:
    return Type.POLYGON;
  case MultiPoint:
    return Type.MULTIPOINT;
  case Envelope:
    return Type.POLYGON;
  case Line:
    return Type.LINESTRING;
  case Unknown:
    return Type.Geometry;
  default:
    throw new AssertionError(g);
  }
}
 
Example #10
Source Project: spatial-framework-for-hadoop   Author: Esri   File: ST_LineString.java    License: 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 #11
Source Project: spatial-framework-for-hadoop   Author: Esri   File: ST_LineString.java    License: 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 #12
Source Project: spatial-framework-for-hadoop   Author: Esri   File: TestStGeomFromShape.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGeomFromLineShape() throws UDFArgumentException {
	Polyline line = createLine();
	byte[] esriShape = GeometryEngine.geometryToEsriShape(line);
	assertNotNull("The shape must not be null!", esriShape);

	BytesWritable shapeAsWritable = new BytesWritable(esriShape);
	assertNotNull("The shape writable must not be null!", shapeAsWritable);

	final int wkid = 4326;
	ST_GeomFromShape fromShape = new ST_GeomFromShape();
	BytesWritable geometryAsWritable = fromShape.evaluate(shapeAsWritable, wkid);
	assertNotNull("The geometry writable must not be null!", geometryAsWritable);

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geometryAsWritable);
	assertNotNull("The OGC geometry must not be null!", ogcGeometry);

	Geometry esriGeometry = ogcGeometry.getEsriGeometry();
	assertNotNull("The Esri geometry must not be null!", esriGeometry);
	assertTrue("The geometries are different!",
			GeometryEngine.equals(line, esriGeometry, SpatialReference.create(wkid)));
}
 
Example #13
Source Project: spatial-framework-for-hadoop   Author: Esri   File: TestStGeomFromShape.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGeomFromPolylineShape() throws UDFArgumentException {
	Polyline line = createPolyline();
	byte[] esriShape = GeometryEngine.geometryToEsriShape(line);
	assertNotNull("The shape must not be null!", esriShape);

	BytesWritable shapeAsWritable = new BytesWritable(esriShape);
	assertNotNull("The shape writable must not be null!", shapeAsWritable);

	final int wkid = 4326;
	ST_GeomFromShape fromShape = new ST_GeomFromShape();
	BytesWritable geometryAsWritable = fromShape.evaluate(shapeAsWritable, wkid);
	assertNotNull("The geometry writable must not be null!", geometryAsWritable);

	OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geometryAsWritable);
	assertNotNull("The OGC geometry must not be null!", ogcGeometry);

	Geometry esriGeometry = ogcGeometry.getEsriGeometry();
	assertNotNull("The Esri geometry must not be null!", esriGeometry);
	assertTrue("The geometries are different!",
			GeometryEngine.equals(line, esriGeometry, SpatialReference.create(wkid)));
}
 
Example #14
Source Project: arcgis-runtime-demo-java   Author: Esri   File: GeoJsonParser.java    License: 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 #15
Source Project: sis   Author: apache   File: StoreTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that the property of the given name in the given feature has expected information.
 */
private void assertPropertyEquals(final AbstractFeature f, final String mfidref,
        final String startTime, final String endTime, final double[] trajectory,
        final Object state, final Object typeCode)
{
    assertEquals("mfidref",   mfidref,            f.getPropertyValue("mfidref"));
    assertEquals("startTime", instant(startTime), f.getPropertyValue("startTime"));
    assertEquals("endTime",   instant(endTime),   f.getPropertyValue("endTime"));
    assertEquals("state",     state,              f.getPropertyValue("state"));
    assertEquals("typeCode",  typeCode,           f.getPropertyValue("\"type\" code"));
    if (isMovingFeature) {
        assertPolylineEquals(trajectory, (Polyline) f.getPropertyValue("trajectory"));
    } else {
        assertArrayEquals("trajectory", trajectory, (double[]) f.getPropertyValue("trajectory"), STRICT);
    }
}
 
Example #16
Source Project: presto   Author: prestosql   File: GeoFunctions.java    License: Apache License 2.0 5 votes vote down vote up
@Description("Returns a LineString from an array of points")
@ScalarFunction("ST_LineString")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stLineString(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input)
{
    MultiPath multipath = new Polyline();
    OGCPoint previousPoint = null;
    for (int i = 0; i < input.getPositionCount(); i++) {
        Slice slice = GEOMETRY.getSlice(input, i);

        if (slice.getInput().available() == 0) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_LineString: null point at index %s", i + 1));
        }

        OGCGeometry geometry = deserialize(slice);
        if (!(geometry instanceof OGCPoint)) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("ST_LineString takes only an array of valid points, %s was passed", geometry.geometryType()));
        }
        OGCPoint point = (OGCPoint) geometry;

        if (point.isEmpty()) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_LineString: empty point at index %s", i + 1));
        }

        if (previousPoint == null) {
            multipath.startPath(point.X(), point.Y());
        }
        else {
            if (point.Equals(previousPoint)) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT,
                        format("Invalid input to ST_LineString: consecutive duplicate points at index %s", i + 1));
            }
            multipath.lineTo(point.X(), point.Y());
        }
        previousPoint = point;
    }
    OGCLineString linestring = new OGCLineString(multipath, 0, null);
    return serialize(linestring);
}
 
Example #17
Source Project: presto   Author: prestosql   File: GeoFunctions.java    License: Apache License 2.0 5 votes vote down vote up
@Description("Returns the Point value that is the mathematical centroid of a Geometry")
@ScalarFunction("ST_Centroid")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stCentroid(@SqlType(GEOMETRY_TYPE_NAME) Slice input)
{
    OGCGeometry geometry = deserialize(input);
    validateType("ST_Centroid", geometry, EnumSet.of(POINT, MULTI_POINT, LINE_STRING, MULTI_LINE_STRING, POLYGON, MULTI_POLYGON));
    GeometryType geometryType = GeometryType.getForEsriGeometryType(geometry.geometryType());
    if (geometryType == GeometryType.POINT) {
        return input;
    }

    int pointCount = ((MultiVertexGeometry) geometry.getEsriGeometry()).getPointCount();
    if (pointCount == 0) {
        return serialize(createFromEsriGeometry(new Point(), geometry.getEsriSpatialReference()));
    }

    Point centroid;
    switch (geometryType) {
        case MULTI_POINT:
            centroid = computePointsCentroid((MultiVertexGeometry) geometry.getEsriGeometry());
            break;
        case LINE_STRING:
        case MULTI_LINE_STRING:
            centroid = computeLineCentroid((Polyline) geometry.getEsriGeometry());
            break;
        case POLYGON:
            centroid = computePolygonCentroid((Polygon) geometry.getEsriGeometry());
            break;
        case MULTI_POLYGON:
            centroid = computeMultiPolygonCentroid((OGCMultiPolygon) geometry);
            break;
        default:
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Unexpected geometry type: " + geometryType);
    }
    return serialize(createFromEsriGeometry(centroid, geometry.getEsriSpatialReference()));
}
 
Example #18
Source Project: presto   Author: prestosql   File: GeoFunctions.java    License: Apache License 2.0 5 votes vote down vote up
@Description("Returns the Geometry value that represents the point set intersection of two Geometries")
@ScalarFunction("ST_Intersection")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stIntersection(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right)
{
    if (deserializeType(left) == GeometrySerializationType.ENVELOPE && deserializeType(right) == GeometrySerializationType.ENVELOPE) {
        Envelope leftEnvelope = deserializeEnvelope(left);
        Envelope rightEnvelope = deserializeEnvelope(right);

        // Envelope#intersect updates leftEnvelope to the intersection of the two envelopes
        if (!leftEnvelope.intersect(rightEnvelope)) {
            return EMPTY_POLYGON;
        }

        Envelope intersection = leftEnvelope;
        if (intersection.getXMin() == intersection.getXMax()) {
            if (intersection.getYMin() == intersection.getYMax()) {
                return serialize(createFromEsriGeometry(new Point(intersection.getXMin(), intersection.getXMax()), null));
            }
            return serialize(createFromEsriGeometry(new Polyline(new Point(intersection.getXMin(), intersection.getYMin()), new Point(intersection.getXMin(), intersection.getYMax())), null));
        }

        if (intersection.getYMin() == intersection.getYMax()) {
            return serialize(createFromEsriGeometry(new Polyline(new Point(intersection.getXMin(), intersection.getYMin()), new Point(intersection.getXMax(), intersection.getYMin())), null));
        }

        return serialize(intersection);
    }

    OGCGeometry leftGeometry = deserialize(left);
    OGCGeometry rightGeometry = deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return serialize(leftGeometry.intersection(rightGeometry));
}
 
Example #19
Source Project: presto   Author: prestosql   File: GeoFunctions.java    License: 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 #20
Source Project: presto   Author: prestosql   File: GeometrySerde.java    License: Apache License 2.0 5 votes vote down vote up
private static OGCGeometry createFromEsriGeometry(Geometry geometry, boolean multiType)
{
    Geometry.Type type = geometry.getType();
    switch (type) {
        case Polygon: {
            if (!multiType && ((Polygon) geometry).getExteriorRingCount() <= 1) {
                return new OGCPolygon((Polygon) geometry, null);
            }
            return new OGCMultiPolygon((Polygon) geometry, null);
        }
        case Polyline: {
            if (!multiType && ((Polyline) geometry).getPathCount() <= 1) {
                return new OGCLineString((Polyline) geometry, 0, null);
            }
            return new OGCMultiLineString((Polyline) geometry, null);
        }
        case MultiPoint: {
            if (!multiType && ((MultiPoint) geometry).getPointCount() <= 1) {
                if (geometry.isEmpty()) {
                    return new OGCPoint(new Point(), null);
                }
                return new OGCPoint(((MultiPoint) geometry).getPoint(0), null);
            }
            return new OGCMultiPoint((MultiPoint) geometry, null);
        }
        case Point: {
            if (!multiType) {
                return new OGCPoint((Point) geometry, null);
            }
            return new OGCMultiPoint((Point) geometry, null);
        }
        case Envelope: {
            Polygon polygon = new Polygon();
            polygon.addEnvelope((Envelope) geometry, false);
            return new OGCPolygon(polygon, null);
        }
        default:
            throw new IllegalArgumentException("Unexpected geometry type: " + type);
    }
}
 
Example #21
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: Line2PtProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private Point getEndPoint(Polyline polyln)
{
	try {
		int pathCount = polyln.getPathCount();
		int endIndex = polyln.getPathEnd(pathCount - 1);
		return polyln.getPoint(endIndex-1);
	} catch (Exception e) {
		LOGGER.error(e.getMessage());
		throw (e);
	}
}
 
Example #22
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: BearingProcessor.java    License: 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 #23
Source Project: defense-solutions-proofs-of-concept   Author: Esri   File: BearingProcessor.java    License: 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 #24
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 #25
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 #26
Source Project: barefoot   Author: bmwcarit   File: MatcherKState.java    License: Apache License 2.0 5 votes vote down vote up
public JSONObject toMonitorJSON() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("time", sample().time());
    json.put("point", GeometryEngine.geometryToWkt(estimate().point().geometry(),
            WktExportFlags.wktExportPoint));
    Polyline routes = monitorRoute(estimate());
    if (routes.getPathCount() > 0) {
        json.put("route",
                GeometryEngine.geometryToWkt(routes, WktExportFlags.wktExportMultiLineString));
    }

    JSONArray candidates = new JSONArray();
    for (MatcherCandidate candidate : vector()) {
        JSONObject jsoncandidate = new JSONObject();
        jsoncandidate.put("point", GeometryEngine.geometryToWkt(candidate.point().geometry(),
                WktExportFlags.wktExportPoint));
        jsoncandidate.put("prob",
                Double.isInfinite(candidate.filtprob()) ? "Infinity" : candidate.filtprob());

        routes = monitorRoute(candidate);
        if (routes.getPathCount() > 0) {
            jsoncandidate.put("route", GeometryEngine.geometryToWkt(routes,
                    WktExportFlags.wktExportMultiLineString));
        }
        candidates.put(jsoncandidate);
    }
    json.put("candidates", candidates);
    return json;
}
 
Example #27
Source Project: barefoot   Author: bmwcarit   File: Geography.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public double length(Polyline p) {
    double d = 0;

    for (int i = 1; i < p.getPointCount(); ++i) {
        d += distance(p.getPoint(i - 1), p.getPoint(i));
    }

    return d;
}
 
Example #28
Source Project: barefoot   Author: bmwcarit   File: Geography.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public double intercept(Polyline p, Point c) {
    double d = Double.MAX_VALUE;
    Point a = p.getPoint(0);
    double s = 0, sf = 0, ds = 0;

    for (int i = 1; i < p.getPointCount(); ++i) {
        Point b = p.getPoint(i);

        ds = distance(a, b);

        double f_ = intercept(a, b, c);
        f_ = (f_ > 1) ? 1 : (f_ < 0) ? 0 : f_;
        Point x = interpolate(a, b, f_);
        double d_ = distance(c, x);

        if (d_ < d) {
            sf = (f_ * ds) + s;
            d = d_;
        }

        s = s + ds;
        a = b;
    }

    return s == 0 ? 0 : sf / s;
}
 
Example #29
Source Project: barefoot   Author: bmwcarit   File: Geography.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Point interpolate(Polyline p, double l, double f) {
    assert (f >= 0 && f <= 1);

    Point a = p.getPoint(0);
    double d = l * f;
    double s = 0, ds = 0;

    if (f < 0 + 1E-10) {
        return p.getPoint(0);
    }

    if (f > 1 - 1E-10) {
        return p.getPoint(p.getPointCount() - 1);
    }

    for (int i = 1; i < p.getPointCount(); ++i) {
        Point b = p.getPoint(i);
        ds = distance(a, b);

        if ((s + ds) >= d) {
            return interpolate(a, b, (d - s) / ds);
        }

        s = s + ds;
        a = b;
    }

    return null;
}
 
Example #30
Source Project: barefoot   Author: bmwcarit   File: Geography.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public double azimuth(Polyline p, double l, double f) {
    assert (f >= 0 && f <= 1);

    Point a = p.getPoint(0);
    double d = l * f;
    double s = 0, ds = 0;

    if (f < 0 + 1E-10) {
        return azimuth(p.getPoint(0), p.getPoint(1), 0);
    }

    if (f > 1 - 1E-10) {
        return azimuth(p.getPoint(p.getPointCount() - 2), p.getPoint(p.getPointCount() - 1), f);
    }

    for (int i = 1; i < p.getPointCount(); ++i) {
        Point b = p.getPoint(i);
        ds = distance(a, b);

        if ((s + ds) >= d) {
            return azimuth(a, b, (d - s) / ds);
        }

        s = s + ds;
        a = b;
    }

    return Double.NaN;
}