Search in sources :

Example 11 with SpatialContext

use of org.locationtech.spatial4j.context.SpatialContext in project lucene-solr by apache.

the class GeoJSONWriter method write.

@Override
public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
    String geofield = req.getParams().get(FIELD, null);
    if (geofield == null || geofield.length() == 0) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "GeoJSON.  Missing parameter: '" + FIELD + "'");
    }
    SchemaField sf = req.getSchema().getFieldOrNull(geofield);
    if (sf == null) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "GeoJSON.  Unknown field: '" + FIELD + "'=" + geofield);
    }
    SupportedFormats formats = null;
    if (sf.getType() instanceof AbstractSpatialFieldType) {
        SpatialContext ctx = ((AbstractSpatialFieldType) sf.getType()).getSpatialContext();
        formats = ctx.getFormats();
    }
    JSONWriter w = new GeoJSONWriter(writer, req, rsp, geofield, formats);
    try {
        w.writeResponse();
    } finally {
        w.close();
    }
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) SpatialContext(org.locationtech.spatial4j.context.SpatialContext) AbstractSpatialFieldType(org.apache.solr.schema.AbstractSpatialFieldType) SolrException(org.apache.solr.common.SolrException) SupportedFormats(org.locationtech.spatial4j.io.SupportedFormats)

Example 12 with SpatialContext

use of org.locationtech.spatial4j.context.SpatialContext in project ddf by codice.

the class GeoNamesWebService method createPointFromWkt.

Point createPointFromWkt(String wkt) {
    try {
        JtsSpatialContextFactory contextFactory = new JtsSpatialContextFactory();
        contextFactory.allowMultiOverlap = true;
        SpatialContext spatialContext = contextFactory.newSpatialContext();
        Shape shape = (Shape) spatialContext.readShapeFromWkt(wkt);
        Point center = shape.getCenter();
        return center;
    } catch (java.text.ParseException parseException) {
        LOGGER.debug(parseException.getMessage(), parseException);
    }
    return null;
}
Also used : SpatialContext(org.locationtech.spatial4j.context.SpatialContext) Shape(org.locationtech.spatial4j.shape.Shape) Point(org.locationtech.spatial4j.shape.Point) SpatialContext(org.locationtech.spatial4j.context.SpatialContext) JtsSpatialContextFactory(org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory)

Aggregations

SpatialContext (org.locationtech.spatial4j.context.SpatialContext)12 QuadPrefixTree (org.apache.lucene.spatial.prefix.tree.QuadPrefixTree)4 Shape (org.locationtech.spatial4j.shape.Shape)4 ArrayList (java.util.ArrayList)3 GeohashPrefixTree (org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)3 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)3 Test (org.junit.Test)3 Point (org.locationtech.spatial4j.shape.Point)3 Rectangle (org.locationtech.spatial4j.shape.Rectangle)3 ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)2 RecursivePrefixTreeStrategy (org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy)2 TermQueryPrefixTreeStrategy (org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy)2 Cell (org.apache.lucene.spatial.prefix.tree.Cell)2 SpatialArgsParser (org.apache.lucene.spatial.query.SpatialArgsParser)2 SolrException (org.apache.solr.common.SolrException)2 SchemaField (org.apache.solr.schema.SchemaField)2 InputStream (java.io.InputStream)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1