com.esri.core.geometry.Polyline Java Examples

The following examples show how to use com.esri.core.geometry.Polyline. 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: TestStGeomFromShape.java    From spatial-framework-for-hadoop with 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 #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: RoadPointTest.java    From barefoot with 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 #4
Source File: RoadTest.java    From barefoot with 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 #5
Source File: GeoFunctions.java    From calcite with 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 #6
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 #7
Source File: BaseRoad.java    From barefoot with 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 #8
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 #9
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 #10
Source File: TestStGeomFromShape.java    From spatial-framework-for-hadoop with 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 #11
Source File: GeoFunctions.java    From Quicksql with 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 #12
Source File: GeoFunctions.java    From Bats with 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 #13
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 #14
Source File: GeoFunctions.java    From presto with 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 #15
Source File: StoreTest.java    From sis with 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 File: ReaderTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies property values for the given route.
 *
 * @param  f         the route to verify.
 * @param  v11       {@code true} for GPX 1.1, or {@code false} for GPX 1.0.
 * @param  numLinks  expected number of links.
 */
@SuppressWarnings("fallthrough")
private static void verifyRoute(final AbstractFeature f, final boolean v11, final int numLinks) {
    assertEquals("name",       "Route name",          f.getPropertyValue("name"));
    assertEquals("cmt",        "Route comment",       f.getPropertyValue("cmt"));
    assertEquals("desc",       "Route description",   f.getPropertyValue("desc"));
    assertEquals("src",        "Route source",        f.getPropertyValue("src"));
    assertEquals("type", v11 ? "Route type" : null,   f.getPropertyValue("type"));
    assertEquals("number",      7,                    f.getPropertyValue("number"));

    final List<?> links = (List<?>) f.getPropertyValue("link");
    assertEquals("links.size()", numLinks, links.size());
    switch (numLinks) {
        default: // Fallthrough everywhere.
        case 3:  assertStringEquals("http://route-address3.org", links.get(2));
        case 2:  assertStringEquals("http://route-address2.org", links.get(1));
        case 1:  assertStringEquals("http://route-address1.org", links.get(0));
        case 0:  break;
    }

    final List<?> points = (List<?>) f.getPropertyValue("rtept");
    assertEquals("points.size()", 3, points.size());
    verifyPoint((AbstractFeature) points.get(0), 0, v11);
    verifyPoint((AbstractFeature) points.get(1), 1, v11);
    verifyPoint((AbstractFeature) points.get(2), 2, v11);

    final Polyline p = (Polyline) f.getPropertyValue("sis:geometry");
    assertEquals("pointCount", 3, p.getPointCount());
    assertEquals("point(0)", new Point(15, 10), p.getPoint(0));
    assertEquals("point(1)", new Point(25, 20), p.getPoint(1));
    assertEquals("point(2)", new Point(35, 30), p.getPoint(2));
    assertEnvelopeEquals(15, 35, 10, 30, (Envelope) f.getPropertyValue("sis:envelope"));
}
 
Example #17
Source File: RoadMapTest.java    From barefoot with Apache License 2.0 5 votes vote down vote up
private static List<BaseRoad> osmroads() {
    /*
     * (p2) (p3) ----- (e1) : (p1) -> (p2) ----------------------------------------------------
     * - \ / --------- (e2) : (p3) -> (p1) ----------------------------------------------------
     * | (p1) | ------ (e3) : (p4) -> (p1) ----------------------------------------------------
     * - / \ --------- (e4) : (p1) -> (p5) ----------------------------------------------------
     * (p4) (p5) ----- (e5) : (p2) -> (p4) ----------------------------------------------------
     * --------------- (e6) : (p5) -> (p3) ----------------------------------------------------
     */
    String p1 = "11.3441505 48.0839963";
    String p2 = "11.3421209 48.0850624";
    String p3 = "11.3460348 48.0850108";
    String p4 = "11.3427522 48.0832129";
    String p5 = "11.3469701 48.0825356";

    List<BaseRoad> osm = new LinkedList<>();
    osm.add(new BaseRoad(1L, 1L, 2L, 1L, true, (short) 1, 1F, 60F, 60F, 100F,
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p1 + "," + p2 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline)));
    osm.add(new BaseRoad(2L, 3L, 1L, 2L, false, (short) 1, 1F, 60F, 60F, 100F,
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p3 + "," + p1 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline)));
    osm.add(new BaseRoad(3L, 4L, 1L, 3L, true, (short) 1, 1F, 60F, 60F, 100F,
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p4 + "," + p1 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline)));
    osm.add(new BaseRoad(4L, 1L, 5L, 4L, false, (short) 1, 1F, 60F, 60F, 100F,
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p1 + "," + p5 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline)));
    osm.add(new BaseRoad(5L, 2L, 4L, 5L, false, (short) 1, 1F, 60F, 60F, 100F,
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p2 + "," + p4 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline)));
    osm.add(new BaseRoad(6L, 5L, 3L, 6L, false, (short) 1, 1F, 60F, 60F, 100F,
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p5 + "," + p3 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline)));

    return osm;
}
 
Example #18
Source File: ReaderTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies property values for the given track.
 *
 * @param  f         the track to verify.
 * @param  v11       {@code true} for GPX 1.1, or {@code false} for GPX 1.0.
 * @param  numLinks  expected number of links.
 */
@SuppressWarnings("fallthrough")
private static void verifyTrack(final AbstractFeature f, final boolean v11, final int numLinks) {
    assertEquals("name",       "Track name",          f.getPropertyValue("name"));
    assertEquals("cmt",        "Track comment",       f.getPropertyValue("cmt"));
    assertEquals("desc",       "Track description",   f.getPropertyValue("desc"));
    assertEquals("src",        "Track source",        f.getPropertyValue("src"));
    assertEquals("type", v11 ? "Track type" : null,   f.getPropertyValue("type"));
    assertEquals("number",      7,                    f.getPropertyValue("number"));

    final List<?> links = (List<?>) f.getPropertyValue("link");
    assertEquals("links.size()", numLinks, links.size());
    switch (numLinks) {
        default: // Fallthrough everywhere.
        case 3:  assertStringEquals("http://track-address3.org", links.get(2));
        case 2:  assertStringEquals("http://track-address2.org", links.get(1));
        case 1:  assertStringEquals("http://track-address1.org", links.get(0));
        case 0:  break;
    }

    final List<?> segments = (List<?>) f.getPropertyValue("trkseg");
    assertEquals("segments.size()", 2, segments.size());
    final AbstractFeature seg1 = (AbstractFeature) segments.get(0);
    final AbstractFeature seg2 = (AbstractFeature) segments.get(1);
    final List<?> points = (List<?>) seg1.getPropertyValue("trkpt");
    assertEquals("points.size()", 3, points.size());
    verifyPoint((AbstractFeature) points.get(0), 0, v11);
    verifyPoint((AbstractFeature) points.get(1), 1, v11);
    verifyPoint((AbstractFeature) points.get(2), 2, v11);
    assertTrue(((Collection<?>) seg2.getPropertyValue("trkpt")).isEmpty());

    final Polyline p = (Polyline) f.getPropertyValue("sis:geometry");
    assertEquals("pointCount", 3, p.getPointCount());
    assertEquals("point(0)", new Point(15, 10), p.getPoint(0));
    assertEquals("point(1)", new Point(25, 20), p.getPoint(1));
    assertEquals("point(2)", new Point(35, 30), p.getPoint(2));
    assertEnvelopeEquals(15, 35, 10, 30, (Envelope) f.getPropertyValue("sis:envelope"));
}
 
Example #19
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 #20
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 #21
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 #22
Source File: StoreTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that the given polyline contains the expected coordinate values.
 */
private static void assertPolylineEquals(final double[] trajectory, final Polyline polyline) {
    assertEquals("pointCount", trajectory.length / 2, polyline.getPointCount());
    for (int i=0; i < trajectory.length;) {
        final Point2D xy = polyline.getXY(i / 2);
        assertEquals("x", trajectory[i++], xy.x, STRICT);
        assertEquals("y", trajectory[i++], xy.y, STRICT);
    }
}
 
Example #23
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 #24
Source File: MatcherKStateTest.java    From barefoot with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws SourceException {
    if (roads.isEmpty()) {
        for (Entry entry : entries) {
            Polyline geometry = (Polyline) GeometryEngine.geometryFromWkt(entry.five(),
                    WktImportFlags.wktImportDefaults, Type.Polyline);
            roads.add(new BaseRoad(entry.one(), entry.two(), entry.three(), entry.one(),
                    entry.four(), (short) 0, 1.0f, 100.0f, 100.0f,
                    (float) spatial.length(geometry), geometry));
        }
    }

    iterator = roads.iterator();
}
 
Example #25
Source File: MatcherTest.java    From barefoot with Apache License 2.0 5 votes vote down vote up
private void assertCandidate(Tuple<MatcherCandidate, Double> candidate, Point sample) {
    Polyline polyline = map.get(candidate.one().point().edge().id()).geometry();
    double f = spatial.intercept(polyline, sample);
    Point i = spatial.interpolate(polyline, f);
    double l = spatial.distance(i, sample);
    double sig2 = Math.pow(10d, 2);
    double sqrt_2pi_sig2 = Math.sqrt(2d * Math.PI * sig2);
    double p = 1 / sqrt_2pi_sig2 * Math.exp((-1) * l * l / (2 * sig2));

    assertEquals(f, candidate.one().point().fraction(), 10E-6);
    assertEquals(p, candidate.two(), 10E-6);
}
 
Example #26
Source File: MatcherTest.java    From barefoot with Apache License 2.0 5 votes vote down vote up
@Override
public void open() throws SourceException {
    if (roads.isEmpty()) {
        for (Entry entry : entries) {
            Polyline geometry = (Polyline) GeometryEngine.geometryFromWkt(entry.five(),
                    WktImportFlags.wktImportDefaults, Type.Polyline);
            roads.add(new BaseRoad(entry.one(), entry.two(), entry.three(), entry.one(),
                    entry.four(), (short) 0, 1.0f, 100.0f, 100.0f,
                    (float) spatial.length(geometry), geometry));
        }
    }

    iterator = roads.iterator();
}
 
Example #27
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 #28
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 #29
Source File: ESRITest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link ESRI#createPolyline(int, Vector...)}.
 */
@Test
@Override
public void testCreatePolyline() {
    super.testCreatePolyline();
    final Polyline poly = (Polyline) geometry;
    assertEquals("pathCount", 2, poly.getPathCount());
}
 
Example #30
Source File: ESRITest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link Geometries#tryMergePolylines(Object, Iterator)}.
 */
@Test
@Override
public void testTryMergePolylines() {
    super.testTryMergePolylines();
    final Polyline poly = (Polyline) geometry;
    assertEquals("pathCount", 3, poly.getPathCount());
}