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();
}
}
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;
}
Aggregations