Search in sources :

Example 11 with PointImpl

use of org.locationtech.spatial4j.shape.impl.PointImpl in project ddf by codice.

the class GazetteerQueryCatalog method transformMetacardToNearbyLocation.

private NearbyLocation transformMetacardToNearbyLocation(String location, Metacard metacard) {
    String metacardLocation = getStringAttributeFromMetacard(metacard, Core.LOCATION);
    String name = getStringAttributeFromMetacard(metacard, Core.TITLE);
    if (StringUtils.isEmpty(metacardLocation) || StringUtils.isEmpty(name)) {
        LOGGER.debug("GeoEntry metacard does not contain required attribute.");
        return null;
    }
    Double lat;
    Double lon;
    PointImpl centerPoint;
    try {
        Geometry geometry = WKT_READER_THREAD_LOCAL.get().read(metacardLocation);
        Coordinate coordinate = geometry.getCoordinate();
        lat = coordinate.x;
        lon = coordinate.y;
        Point center = WKT_READER_THREAD_LOCAL.get().read(location).getCentroid();
        centerPoint = new PointImpl(center.getY(), center.getX(), SPATIAL_CONTEXT);
    } catch (org.locationtech.jts.io.ParseException e) {
        LOGGER.debug("GeoEntry metacard does not contain location attribute.");
        return null;
    }
    return new NearbyLocationImpl(centerPoint, new PointImpl(lon, lat, SPATIAL_CONTEXT), name);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) NearbyLocationImpl(org.codice.ddf.spatial.geocoding.context.impl.NearbyLocationImpl) Coordinate(org.locationtech.jts.geom.Coordinate) Point(org.locationtech.jts.geom.Point) PointImpl(org.locationtech.spatial4j.shape.impl.PointImpl)

Example 12 with PointImpl

use of org.locationtech.spatial4j.shape.impl.PointImpl in project crate by crate.

the class GeoPointTypeTest method testStreaming.

@Test
public void testStreaming() throws Throwable {
    Point p1 = new PointImpl(41.2, -37.4, JtsSpatialContext.GEO);
    BytesStreamOutput out = new BytesStreamOutput();
    DataTypes.GEO_POINT.writeValueTo(out, p1);
    StreamInput in = out.bytes().streamInput();
    Point p2 = DataTypes.GEO_POINT.readValueFrom(in);
    assertThat(p1, equalTo(p2));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) Point(org.locationtech.spatial4j.shape.Point) PointImpl(org.locationtech.spatial4j.shape.impl.PointImpl) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 13 with PointImpl

use of org.locationtech.spatial4j.shape.impl.PointImpl in project crate by crate.

the class PointType method decodeUTF8Text.

@Override
Point decodeUTF8Text(byte[] bytes) {
    String value = new String(bytes, StandardCharsets.UTF_8);
    StringTokenizer tokenizer = new StringTokenizer(value, ",()");
    double x;
    double y;
    if (tokenizer.hasMoreTokens()) {
        x = Double.parseDouble(tokenizer.nextToken());
    } else {
        throw new IllegalArgumentException("Cannot parse input as point: " + value + " expected a point in format: (x, y)");
    }
    if (tokenizer.hasMoreTokens()) {
        y = Double.parseDouble(tokenizer.nextToken());
    } else {
        throw new IllegalArgumentException("Cannot parse input as point: " + value + " expected a point in format: (x, y)");
    }
    return new PointImpl(x, y, JtsSpatialContext.GEO);
}
Also used : StringTokenizer(java.util.StringTokenizer) PointImpl(org.locationtech.spatial4j.shape.impl.PointImpl)

Aggregations

PointImpl (org.locationtech.spatial4j.shape.impl.PointImpl)13 Point (org.locationtech.spatial4j.shape.Point)6 Test (org.junit.Test)5 NearbyLocationImpl (org.codice.ddf.spatial.geocoding.context.impl.NearbyLocationImpl)4 NearbyLocation (org.codice.ddf.spatial.geocoding.context.NearbyLocation)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JSONArray (net.minidev.json.JSONArray)2 JSONObject (net.minidev.json.JSONObject)2 GeoEntryQueryException (org.codice.ddf.spatial.geocoding.GeoEntryQueryException)2 PGArray (io.crate.protocols.postgres.types.PGArray)1 UseJdbc (io.crate.testing.UseJdbc)1 ByteBuf (io.netty.buffer.ByteBuf)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URLEncoder (java.net.URLEncoder)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Array (java.sql.Array)1 Timestamp (java.sql.Timestamp)1 Collections (java.util.Collections)1