Search in sources :

Example 1 with WriteableGeoJSON

use of org.apache.solr.response.transform.WriteableGeoJSON in project lucene-solr by apache.

the class GeoJSONWriter method writeGeo.

protected void writeGeo(Object geo) throws IOException {
    Shape shape = null;
    String str = null;
    if (geo instanceof Shape) {
        shape = (Shape) geo;
    } else if (geo instanceof IndexableField) {
        str = ((IndexableField) geo).stringValue();
    } else if (geo instanceof WriteableGeoJSON) {
        shape = ((WriteableGeoJSON) geo).shape;
    } else {
        str = geo.toString();
    }
    if (str != null) {
        // Assume it is well formed JSON
        if (str.startsWith("{") && str.endsWith("}")) {
            writer.write(str);
            return;
        }
        if (formats == null) {
            // *stored* values for the field look like JSON until we actually try to read them
            throw new SolrException(ErrorCode.BAD_REQUEST, "GeoJSON unable to write field: '&" + GeoJSONResponseWriter.FIELD + "=" + geofield + "' (" + str + ")");
        }
        shape = formats.read(str);
    }
    if (geowriter == null) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "GeoJSON unable to write field: '&" + GeoJSONResponseWriter.FIELD + "=" + geofield + "'");
    }
    if (shape != null) {
        geowriter.write(writer, shape);
    }
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) WriteableGeoJSON(org.apache.solr.response.transform.WriteableGeoJSON) Shape(org.locationtech.spatial4j.shape.Shape) SolrException(org.apache.solr.common.SolrException)

Aggregations

IndexableField (org.apache.lucene.index.IndexableField)1 SolrException (org.apache.solr.common.SolrException)1 WriteableGeoJSON (org.apache.solr.response.transform.WriteableGeoJSON)1 Shape (org.locationtech.spatial4j.shape.Shape)1