Search in sources :

Example 1 with AbstractGeometry

use of datawave.data.type.util.AbstractGeometry in project datawave by NationalSecurityAgency.

the class GeoWaveFunctions method getGeometryFromFieldValue.

private static Geometry getGeometryFromFieldValue(Object fieldValue) {
    Geometry geometry = null;
    if (fieldValue instanceof Geometry) {
        geometry = (Geometry) fieldValue;
    } else if (fieldValue instanceof GeoNormalizer.GeoPoint) {
        geometry = geoPointToGeometry((GeoNormalizer.GeoPoint) fieldValue);
    } else if (fieldValue instanceof String) {
        geometry = parseGeometry((String) fieldValue);
    } else if (fieldValue instanceof ValueTuple) {
        ValueTuple t = (ValueTuple) fieldValue;
        Object o = t.second();
        if (o instanceof AbstractGeometryType) {
            AbstractGeometryType<?> gt = (AbstractGeometryType<?>) o;
            geometry = ((AbstractGeometry<?>) gt.getDelegate()).getJTSGeometry();
        } else if (o instanceof GeoType) {
            geometry = parseGeometryFromGeoType(ValueTuple.getNormalizedStringValue(fieldValue));
        }
    } else if (fieldValue instanceof FunctionalSet) {
        FunctionalSet<?> funcSet = (FunctionalSet<?>) fieldValue;
        Geometry[] geometries = funcSet.stream().map(GeoWaveFunctions::getGeometryFromFieldValue).toArray(Geometry[]::new);
        geometry = new GeometryCollection(geometries, geometryFactory);
    }
    if (geometry == null) {
        throw new IllegalArgumentException("Field Value:" + fieldValue + " cannot be recognized as a geometry");
    }
    return geometry;
}
Also used : FunctionalSet(datawave.query.collections.FunctionalSet) AbstractGeometry(datawave.data.type.util.AbstractGeometry) AbstractGeometryType(datawave.data.type.AbstractGeometryType) GeoNormalizer(datawave.data.normalizer.GeoNormalizer) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(datawave.data.type.util.AbstractGeometry) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) GeoType(datawave.data.type.GeoType) ValueTuple(datawave.query.attributes.ValueTuple)

Aggregations

GeoNormalizer (datawave.data.normalizer.GeoNormalizer)1 AbstractGeometryType (datawave.data.type.AbstractGeometryType)1 GeoType (datawave.data.type.GeoType)1 AbstractGeometry (datawave.data.type.util.AbstractGeometry)1 ValueTuple (datawave.query.attributes.ValueTuple)1 FunctionalSet (datawave.query.collections.FunctionalSet)1 Geometry (org.locationtech.jts.geom.Geometry)1 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)1