Search in sources :

Example 16 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project hibernate-orm by hibernate.

the class MySQLGeometryEquality method testVerticesEquality.

private boolean testVerticesEquality(Geometry geom1, Geometry geom2) {
    if (geom1.getNumPoints() != geom2.getNumPoints()) {
        return false;
    }
    for (int i = 0; i < geom1.getNumPoints(); i++) {
        Coordinate cn1 = geom1.getCoordinates()[i];
        Coordinate cn2 = geom2.getCoordinates()[i];
        if (!cn1.equals2D(cn2)) {
            return false;
        }
    }
    return true;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 17 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.

the class GeoShapeQueryTests method testIndexPointsFilterRectangle.

public void testIndexPointsFilterRectangle() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("location").field("type", "geo_shape").field("tree", "quadtree").endObject().endObject().endObject().endObject().string();
    client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).execute().actionGet();
    ensureGreen();
    client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("name", "Document 1").startObject("location").field("type", "point").startArray("coordinates").value(-30).value(-30).endArray().endObject().endObject()).setRefreshPolicy(IMMEDIATE).get();
    client().prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject().field("name", "Document 2").startObject("location").field("type", "point").startArray("coordinates").value(-45).value(-50).endArray().endObject().endObject()).setRefreshPolicy(IMMEDIATE).get();
    ShapeBuilder shape = ShapeBuilders.newEnvelope(new Coordinate(-45, 45), new Coordinate(45, -45));
    SearchResponse searchResponse = client().prepareSearch("test").setTypes("type1").setQuery(geoIntersectionQuery("location", shape)).execute().actionGet();
    assertSearchResponse(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
    assertThat(searchResponse.getHits().getHits().length, equalTo(1));
    assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1"));
    searchResponse = client().prepareSearch("test").setTypes("type1").setQuery(geoShapeQuery("location", shape)).execute().actionGet();
    assertSearchResponse(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
    assertThat(searchResponse.getHits().getHits().length, equalTo(1));
    assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1"));
}
Also used : ShapeBuilder(org.elasticsearch.common.geo.builders.ShapeBuilder) Coordinate(com.vividsolutions.jts.geom.Coordinate) Matchers.containsString(org.hamcrest.Matchers.containsString) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 18 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project elasticsearch by elastic.

the class GeoShapeQueryTests method testEdgeCases.

public void testEdgeCases() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("location").field("type", "geo_shape").field("tree", "quadtree").endObject().endObject().endObject().endObject().string();
    client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).execute().actionGet();
    ensureGreen();
    client().prepareIndex("test", "type1", "blakely").setSource(jsonBuilder().startObject().field("name", "Blakely Island").startObject("location").field("type", "polygon").startArray("coordinates").startArray().startArray().value(-122.83).value(48.57).endArray().startArray().value(-122.77).value(48.56).endArray().startArray().value(-122.79).value(48.53).endArray().startArray().value(-122.83).value(48.57).endArray().endArray().endArray().endObject().endObject()).setRefreshPolicy(IMMEDIATE).get();
    ShapeBuilder query = ShapeBuilders.newEnvelope(new Coordinate(-122.88, 48.62), new Coordinate(-122.82, 48.54));
    // This search would fail if both geoshape indexing and geoshape filtering
    // used the bottom-level optimization in SpatialPrefixTree#recursiveGetNodes.
    SearchResponse searchResponse = client().prepareSearch("test").setTypes("type1").setQuery(geoIntersectionQuery("location", query)).execute().actionGet();
    assertSearchResponse(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
    assertThat(searchResponse.getHits().getHits().length, equalTo(1));
    assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("blakely"));
}
Also used : ShapeBuilder(org.elasticsearch.common.geo.builders.ShapeBuilder) Coordinate(com.vividsolutions.jts.geom.Coordinate) Matchers.containsString(org.hamcrest.Matchers.containsString) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 19 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project series-rest-api by 52North.

the class HighchartFormatter method formatSeries.

private List<Number[]> formatSeries(QuantityData timeseries) {
    List<Number[]> series = new ArrayList<>();
    for (QuantityValue currentValue : timeseries.getValues()) {
        List<Number> list = new ArrayList<>();
        list.add(currentValue.getTimestamp());
        list.add(currentValue.getValue());
        if (currentValue.isSetGeometry()) {
            Coordinate coordinate = currentValue.getGeometry().getCoordinate();
            list.add(coordinate.x);
            list.add(coordinate.y);
            if (!Double.isNaN(coordinate.z)) {
                list.add(coordinate.z);
            }
        }
        series.add(list.toArray(new Number[0]));
    }
    return series;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) QuantityValue(org.n52.io.response.dataset.quantity.QuantityValue) ArrayList(java.util.ArrayList)

Example 20 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project series-rest-api by 52North.

the class FlotFormatter method formatSeries.

private List<Number[]> formatSeries(QuantityData timeseries) {
    List<Number[]> series = new ArrayList<>();
    for (QuantityValue currentValue : timeseries.getValues()) {
        List<Number> list = new ArrayList<>();
        list.add(currentValue.getTimestamp());
        list.add(currentValue.getValue());
        if (currentValue.isSetGeometry()) {
            Coordinate coordinate = currentValue.getGeometry().getCoordinate();
            list.add(coordinate.x);
            list.add(coordinate.y);
            if (!Double.isNaN(coordinate.z)) {
                list.add(coordinate.z);
            }
        }
        series.add(list.toArray(new Number[0]));
    }
    return series;
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) QuantityValue(org.n52.io.response.dataset.quantity.QuantityValue) ArrayList(java.util.ArrayList)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)336 LineString (com.vividsolutions.jts.geom.LineString)70 Geometry (com.vividsolutions.jts.geom.Geometry)67 ArrayList (java.util.ArrayList)65 Test (org.junit.Test)60 Point (com.vividsolutions.jts.geom.Point)52 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)48 Polygon (com.vividsolutions.jts.geom.Polygon)30 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)27 SimpleFeature (org.opengis.feature.simple.SimpleFeature)23 LinearRing (com.vividsolutions.jts.geom.LinearRing)22 Vertex (org.opentripplanner.routing.graph.Vertex)22 Envelope (com.vividsolutions.jts.geom.Envelope)21 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)20 Edge (org.opentripplanner.routing.graph.Edge)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 File (java.io.File)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)11