Search in sources :

Example 1 with VertexSelectGeoObjectQuery

use of net.geoprism.registry.query.graph.VertexSelectGeoObjectQuery in project geoprism-registry by terraframe.

the class GeoObjectAtTimeShapefileExporter method features.

public FeatureCollection<SimpleFeatureType, SimpleFeature> features(SimpleFeatureType featureType) {
    final int BLOCK_SIZE = 2000;
    List<SimpleFeature> features = new ArrayList<SimpleFeature>();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
    VertexServerGeoObject prev = null;
    do {
        final VertexSelectGeoObjectQuery query = new VertexSelectGeoObjectQuery(type, this.date, prev);
        query.setLimit(BLOCK_SIZE);
        final List<VertexServerGeoObject> objects = query.getResults();
        prev = null;
        for (VertexServerGeoObject object : objects) {
            if (!object.getInvalid()) {
                builder.set(GEOM, object.getGeometry());
                this.attributes.forEach(attribute -> {
                    String name = attribute.getName();
                    String columnName = this.getColumnName(name);
                    Object value = attribute.isChangeOverTime() ? object.getValue(name, this.date) : object.getValue(name);
                    if (attribute instanceof AttributeTermType) {
                        builder.set(columnName, GeoObjectUtil.convertToTermString((AttributeTermType) attribute, value));
                    } else if (attribute instanceof AttributeClassificationType) {
                        builder.set(columnName, GeoObjectUtil.convertToTermString((AttributeClassificationType) attribute, value));
                    } else if (attribute instanceof AttributeLocalType) {
                        builder.set(columnName, ((LocalizedValue) value).getValue());
                    } else {
                        builder.set(columnName, value);
                    }
                });
                AttributeType attribute = this.getType().getAttribute(DefaultAttribute.DISPLAY_LABEL.getName()).get();
                LocalizedValue label = object.getDisplayLabel(this.date);
                builder.set(this.getColumnName(attribute.getName() + " " + MdAttributeLocalInfo.DEFAULT_LOCALE), label.getValue(LocalizedValue.DEFAULT_LOCALE));
                for (Locale locale : locales) {
                    builder.set(this.getColumnName(attribute.getName() + " " + locale.toString()), label.getValue(locale));
                }
                SimpleFeature feature = builder.buildFeature(object.getCode());
                features.add(feature);
            }
            prev = object;
            Thread.yield();
        }
    } while (prev != null);
    return new ListFeatureCollection(featureType, features);
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) AttributeClassificationType(org.commongeoregistry.adapter.metadata.AttributeClassificationType) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) SimpleFeature(org.opengis.feature.simple.SimpleFeature) AttributeLocalType(org.commongeoregistry.adapter.metadata.AttributeLocalType) LocalizedValue(org.commongeoregistry.adapter.dataaccess.LocalizedValue) AttributeType(org.commongeoregistry.adapter.metadata.AttributeType) ListFeatureCollection(org.geotools.data.collection.ListFeatureCollection) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) GeoObject(org.commongeoregistry.adapter.dataaccess.GeoObject) VertexServerGeoObject(net.geoprism.registry.model.graph.VertexServerGeoObject) AttributeTermType(org.commongeoregistry.adapter.metadata.AttributeTermType) VertexSelectGeoObjectQuery(net.geoprism.registry.query.graph.VertexSelectGeoObjectQuery) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

LineString (com.vividsolutions.jts.geom.LineString)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)1 Point (com.vividsolutions.jts.geom.Point)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 VertexServerGeoObject (net.geoprism.registry.model.graph.VertexServerGeoObject)1 VertexSelectGeoObjectQuery (net.geoprism.registry.query.graph.VertexSelectGeoObjectQuery)1 GeoObject (org.commongeoregistry.adapter.dataaccess.GeoObject)1 LocalizedValue (org.commongeoregistry.adapter.dataaccess.LocalizedValue)1 AttributeClassificationType (org.commongeoregistry.adapter.metadata.AttributeClassificationType)1 AttributeLocalType (org.commongeoregistry.adapter.metadata.AttributeLocalType)1 AttributeTermType (org.commongeoregistry.adapter.metadata.AttributeTermType)1 AttributeType (org.commongeoregistry.adapter.metadata.AttributeType)1 ListFeatureCollection (org.geotools.data.collection.ListFeatureCollection)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1