use of org.geotools.feature.AttributeTypeBuilder in project core-geonetwork by geonetwork.
the class GeonetTestFixture method registerServiceConfigAndInitDatastoreTable.
protected ServiceConfig registerServiceConfigAndInitDatastoreTable(AbstractCoreIntegrationTest test) throws IOException {
final ArrayList<Element> params = test.getServiceConfigParameterElements();
final ServiceConfig serviceConfig = new ServiceConfig(params);
final String initializedString = "initialized";
try {
_applicationContext.getBean(initializedString);
} catch (NoSuchBeanDefinitionException e) {
_applicationContext.getBeanFactory().registerSingleton("serviceConfig", serviceConfig);
_applicationContext.getBeanFactory().registerSingleton(initializedString, initializedString);
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
AttributeDescriptor geomDescriptor = new AttributeTypeBuilder().crs(DefaultGeographicCRS.WGS84).binding(MultiPolygon.class).buildDescriptor("the_geom");
builder.setName("spatialIndex");
builder.add(geomDescriptor);
builder.add(SpatialIndexWriter._IDS_ATTRIBUTE_NAME, String.class);
this.dataStore.createSchema(builder.buildFeatureType());
}
return serviceConfig;
}
use of org.geotools.feature.AttributeTypeBuilder in project geonetwork by georchestra.
the class OgcGenericFilters method reprojectGeometryType.
private static SimpleFeatureType reprojectGeometryType(Name geometryAttName) {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
AttributeTypeBuilder attBuilder = new AttributeTypeBuilder();
attBuilder.crs(DefaultGeographicCRS.WGS84);
attBuilder.binding(MultiPolygon.class);
GeometryDescriptor geomDescriptor = attBuilder.buildDescriptor(geometryAttName, attBuilder.buildGeometryType());
builder.setName("dummy");
builder.setCRS(DefaultGeographicCRS.WGS84);
builder.add(geomDescriptor);
return builder.buildFeatureType();
}
use of org.geotools.feature.AttributeTypeBuilder in project geo-platform by geosdi.
the class ShapeAppender method buildSchemaAttribute.
/**
* Builds a single attribute for the output Feature schema. By default it
* uses the original source attribute definition, if not overridden by
* configuration.
*
* @param attributeName
* @param crs crs to use for geometric attributes
* @param schema
* @return
*/
private AttributeDescriptor buildSchemaAttribute(String attributeName, SimpleFeatureType schema, CoordinateReferenceSystem crs) {
AttributeDescriptor attr;
if (configuration.getAttributeMappings().containsKey(attributeName) && !isExpression(configuration.getAttributeMappings().get(attributeName).toString())) {
attr = schema.getDescriptor(configuration.getAttributeMappings().get(attributeName).toString());
} else {
attr = schema.getDescriptor(attributeName);
}
AttributeTypeBuilder builder = new AttributeTypeBuilder();
builder.setName(attr.getLocalName());
builder.setBinding(attr.getType().getBinding());
if (attr instanceof GeometryDescriptor) {
if (crs == null) {
crs = ((GeometryDescriptor) attr).getCoordinateReferenceSystem();
}
builder.setCRS(crs);
}
// set descriptor information
builder.setMinOccurs(attr.getMinOccurs());
builder.setMaxOccurs(attr.getMaxOccurs());
builder.setNillable(attr.isNillable());
return builder.buildDescriptor(attributeName);
}
use of org.geotools.feature.AttributeTypeBuilder in project geowave by locationtech.
the class KMeansUtils method writeClusterHulls.
public static DataTypeAdapter writeClusterHulls(final JavaRDD<Vector> inputCentroids, final KMeansModel clusterModel, final DataStorePluginOptions outputDataStore, final String hullAdapterName, final boolean computeMetadata) {
final JavaPairRDD<Integer, Iterable<Vector>> groupByRdd = KMeansHullGenerator.groupByIndex(inputCentroids, clusterModel);
final JavaPairRDD<Integer, Geometry> hullRdd = KMeansHullGenerator.generateHullsRDD(groupByRdd);
final SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
typeBuilder.setName(hullAdapterName);
typeBuilder.setNamespaceURI(BasicFeatureTypes.DEFAULT_NAMESPACE);
try {
typeBuilder.setCRS(CRS.decode("EPSG:4326", true));
} catch (final FactoryException e) {
LOGGER.error(e.getMessage(), e);
}
final AttributeTypeBuilder attrBuilder = new AttributeTypeBuilder();
typeBuilder.add(attrBuilder.binding(Geometry.class).nillable(false).buildDescriptor(Geometry.class.getName().toString()));
typeBuilder.add(attrBuilder.binding(Integer.class).nillable(false).buildDescriptor("ClusterIndex"));
typeBuilder.add(attrBuilder.binding(Integer.class).nillable(false).buildDescriptor("Count"));
typeBuilder.add(attrBuilder.binding(Double.class).nillable(false).buildDescriptor("Area"));
typeBuilder.add(attrBuilder.binding(Double.class).nillable(false).buildDescriptor("Density"));
final SimpleFeatureType sfType = typeBuilder.buildFeatureType();
final SimpleFeatureBuilder sfBuilder = new SimpleFeatureBuilder(sfType);
final FeatureDataAdapter featureAdapter = new FeatureDataAdapter(sfType);
final DataStore featureStore = outputDataStore.createDataStore();
final Index featureIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
final PolygonAreaCalculator polyCalc = (computeMetadata ? new PolygonAreaCalculator() : null);
featureStore.addType(featureAdapter, featureIndex);
try (Writer writer = featureStore.createWriter(featureAdapter.getTypeName())) {
for (final Tuple2<Integer, Geometry> hull : hullRdd.collect()) {
final Integer index = hull._1;
final Geometry geom = hull._2;
sfBuilder.set(Geometry.class.getName(), geom);
sfBuilder.set("ClusterIndex", index);
int count = 0;
double area = 0.0;
double density = 0.0;
if (computeMetadata) {
for (final Iterable<Vector> points : groupByRdd.lookup(index)) {
final Vector[] pointVec = Iterables.toArray(points, Vector.class);
count += pointVec.length;
}
try {
// HP Fortify "NULL Pointer Dereference" false positive
// Exception handling will catch if polyCalc is null
area = polyCalc.getAreaDensify(geom);
density = count / area;
} catch (final Exception e) {
LOGGER.error("Problem computing polygon area: " + e.getMessage());
}
}
sfBuilder.set("Count", count);
sfBuilder.set("Area", area);
sfBuilder.set("Density", density);
final SimpleFeature sf = sfBuilder.buildFeature("Hull-" + index);
writer.write(sf);
}
}
return featureAdapter;
}
use of org.geotools.feature.AttributeTypeBuilder in project geowave by locationtech.
the class SpatialBinningAggregationExample method getSimpleFeatureType.
/**
* A helper that constructs the SimpleFeatureType used in this example.
*/
private static SimpleFeatureType getSimpleFeatureType() {
final String name = "ExampleSimpleFeatureType";
final SimpleFeatureTypeBuilder sftBuilder = new SimpleFeatureTypeBuilder();
final AttributeTypeBuilder atBuilder = new AttributeTypeBuilder();
sftBuilder.setName(name);
// the location name isn't used in this example, its just here for show!
sftBuilder.add(atBuilder.binding(String.class).nillable(false).buildDescriptor("locationName"));
// this is used for the grouping (the `.bin` call).
sftBuilder.add(atBuilder.binding(Geometry.class).nillable(false).buildDescriptor("geometry"));
// this is the field that is summed in each group, as defined by the `.aggregate` call.
sftBuilder.add(atBuilder.binding(Integer.class).nillable(false).buildDescriptor("population"));
return sftBuilder.buildFeatureType();
}
Aggregations