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

The following examples show how to use com.esri.core.geometry.GeometryEngine#geometryFromWkt() . 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: 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 2
Source File: PostGISReaderTest.java    From barefoot with Apache License 2.0 6 votes vote down vote up
@Test
public void testPolygon() throws IOException, JSONException {
    Properties properties = new Properties();
    properties.load(new FileInputStream("config/oberbayern.properties"));
    RoadReader reader = Loader.reader(properties);
    Polygon polygon = (Polygon) GeometryEngine.geometryFromWkt(
            "POLYGON ((11.40848 47.93157, 11.45109 47.93157,11.45109 47.89296,11.40848 47.89296,11.40848 47.93157))",
            WktImportFlags.wktImportDefaults, Type.Polygon);
    BaseRoad road = null;

    reader.open(polygon, null);
    int count = 0;

    while ((road = reader.next()) != null) {
        assertTrue(
                GeometryEngine.overlaps(polygon, road.geometry(), SpatialReference.create(4326))
                        || GeometryEngine.contains(polygon, road.geometry(),
                                SpatialReference.create(4326)));
        count += 1;
    }

    reader.close();
    assertTrue(count > 0);
}
 
Example 3
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 4
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 5
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 6
Source File: MatcherSample.java    From barefoot with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link MatcherSample} object from its JSON representation.
 *
 * @param json JSON representation of {@link MatcherSample} object. JSONException thrown on JSON
 *        extraction or parsing error.
 * @throws JSONException thrown on JSON parse error.
 */
public MatcherSample(JSONObject json) throws JSONException {
    super(json);
    id = json.getString("id");
    String wkt = json.getString("point");
    point = (Point) GeometryEngine.geometryFromWkt(wkt, WktImportFlags.wktImportDefaults,
            Type.Point);
    if (json.has("azimuth")) {
        azimuth = norm(json.getDouble("azimuth"));
    } else {
        azimuth = Double.NaN;
    }
}
 
Example 7
Source File: GeoFunctions.java    From Quicksql with MIT License 4 votes vote down vote up
public static Geom ST_PointFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.Point);
  return bind(g, srid);
}
 
Example 8
Source File: GeoFunctions.java    From calcite with Apache License 2.0 4 votes vote down vote up
public static Geom ST_GeomFromText(String s, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(s,
      WktImportFlags.wktImportDefaults, Geometry.Type.Unknown);
  return bind(g, srid);
}
 
Example 9
Source File: GeoFunctions.java    From calcite with Apache License 2.0 4 votes vote down vote up
public static Geom ST_PointFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.Point);
  return bind(g, srid);
}
 
Example 10
Source File: GeoFunctions.java    From Quicksql with MIT License 4 votes vote down vote up
public static Geom ST_MLineFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.Unknown); // NOTE: there is no Geometry.Type.MultiLine
  return bind(g, srid);
}
 
Example 11
Source File: GeoFunctions.java    From Quicksql with MIT License 4 votes vote down vote up
public static Geom ST_PolyFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.Polygon);
  return bind(g, srid);
}
 
Example 12
Source File: GeoFunctions.java    From Bats with Apache License 2.0 4 votes vote down vote up
public static Geom ST_GeomFromText(String s, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(s,
      WktImportFlags.wktImportDefaults, Geometry.Type.Unknown);
  return bind(g, srid);
}
 
Example 13
Source File: GeoFunctions.java    From Quicksql with MIT License 4 votes vote down vote up
public static Geom ST_MPointFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.MultiPoint);
  return bind(g, srid);
}
 
Example 14
Source File: GeoFunctions.java    From calcite with Apache License 2.0 4 votes vote down vote up
public static Geom ST_MPointFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.MultiPoint);
  return bind(g, srid);
}
 
Example 15
Source File: GeoFunctions.java    From calcite with Apache License 2.0 4 votes vote down vote up
public static Geom ST_MLineFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.Unknown); // NOTE: there is no Geometry.Type.MultiLine
  return bind(g, srid);
}
 
Example 16
Source File: GeoFunctions.java    From Bats with Apache License 2.0 4 votes vote down vote up
public static Geom ST_MPolyFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.Unknown); // NOTE: there is no Geometry.Type.MultiPolygon
  return bind(g, srid);
}
 
Example 17
Source File: RouteTest.java    From barefoot with Apache License 2.0 4 votes vote down vote up
@Test
public void testJSON() throws JSONException {
    SpatialOperator spatial = new Geography();

    /*
     * (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";

    Polyline geometry1 =
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p1 + "," + p2 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline);
    Polyline geometry2 =
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p3 + "," + p1 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline);
    Polyline geometry3 =
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p4 + "," + p1 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline);
    Polyline geometry4 =
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p1 + "," + p5 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline);
    Polyline geometry5 =
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p2 + "," + p4 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline);
    Polyline geometry6 =
            (Polyline) GeometryEngine.geometryFromWkt("LINESTRING(" + p5 + "," + p3 + ")",
                    WktImportFlags.wktImportDefaults, Geometry.Type.Polyline);

    List<BaseRoad> osm = new LinkedList<>();
    osm.add(new BaseRoad(1L, 1L, 2L, 1L, false, (short) 1, 1F, 60F, 60F,
            (float) spatial.length(geometry1), geometry1));
    osm.add(new BaseRoad(2L, 3L, 1L, 2L, false, (short) 1, 1F, 60F, 60F,
            (float) spatial.length(geometry2), geometry2));
    osm.add(new BaseRoad(3L, 4L, 1L, 3L, false, (short) 1, 1F, 60F, 60F,
            (float) spatial.length(geometry3), geometry3));
    osm.add(new BaseRoad(4L, 1L, 5L, 4L, false, (short) 1, 1F, 60F, 60F,
            (float) spatial.length(geometry4), geometry4));
    osm.add(new BaseRoad(5L, 2L, 4L, 5L, false, (short) 1, 1F, 60F, 60F,
            (float) spatial.length(geometry5), geometry5));
    osm.add(new BaseRoad(6L, 5L, 3L, 6L, false, (short) 1, 1F, 60F, 60F,
            (float) spatial.length(geometry6), geometry6));


    RoadMap map = new RoadMap();
    for (BaseRoad road : osm) {
        map.add(new Road(road, Heading.forward));
        map.add(new Road(road, Heading.backward));
    }
    map.construct();

    RoadPoint point1 = new RoadPoint(map.get(2), 0.7);
    RoadPoint point2 = new RoadPoint(map.get(10), 0.3);
    List<Road> path = new LinkedList<>(Arrays.asList(map.get(2), map.get(10)));
    Route route = new Route(point1, point2, path);

    String json = route.toJSON().toString();
    Route route2 = Route.fromJSON(new JSONObject(json), map);

    assertEquals(route.size(), route2.size());

    for (int i = 0; i < route.size(); ++i) {
        assertEquals(route.get(i), route2.get(i));
    }
}
 
Example 18
Source File: GeoFunctions.java    From calcite with Apache License 2.0 4 votes vote down vote up
public static Geom ST_LineFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.Line);
  return bind(g, srid);
}
 
Example 19
Source File: GeoFunctions.java    From Bats with Apache License 2.0 4 votes vote down vote up
public static Geom ST_PointFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.Point);
  return bind(g, srid);
}
 
Example 20
Source File: GeoFunctions.java    From Bats with Apache License 2.0 4 votes vote down vote up
public static Geom ST_LineFromText(String wkt, int srid) {
  final Geometry g = GeometryEngine.geometryFromWkt(wkt,
      WktImportFlags.wktImportDefaults,
      Geometry.Type.Line);
  return bind(g, srid);
}