use of org.opengis.feature.type.GeometryDescriptor in project GeoGig by boundlessgeo.
the class GeogigSimpleFeature method buildAttNameToRevTypeIndex.
public static Map<String, Integer> buildAttNameToRevTypeIndex(RevFeatureType revType) {
List<PropertyDescriptor> sortedDescriptors = revType.sortedDescriptors();
Map<String, Integer> typeAttNameToRevTypeIndex = Maps.newHashMap();
final GeometryDescriptor defaultGeometry = ((SimpleFeatureType) revType.type()).getGeometryDescriptor();
for (int revFeatureIndex = 0; revFeatureIndex < sortedDescriptors.size(); revFeatureIndex++) {
PropertyDescriptor prop = sortedDescriptors.get(revFeatureIndex);
typeAttNameToRevTypeIndex.put(prop.getName().getLocalPart(), Integer.valueOf(revFeatureIndex));
if (prop.equals(defaultGeometry)) {
typeAttNameToRevTypeIndex.put(null, Integer.valueOf(revFeatureIndex));
}
}
return typeAttNameToRevTypeIndex;
}
use of org.opengis.feature.type.GeometryDescriptor in project GeoGig by boundlessgeo.
the class GeogigSimpleFeature method getDefaultGeometryProperty.
@Override
public GeometryAttribute getDefaultGeometryProperty() {
GeometryDescriptor geometryDescriptor = featureType.getGeometryDescriptor();
GeometryAttribute geometryAttribute = null;
if (geometryDescriptor != null) {
Object defaultGeometry = getDefaultGeometry();
geometryAttribute = new GeometryAttributeImpl(defaultGeometry, geometryDescriptor, null);
}
return geometryAttribute;
}
use of org.opengis.feature.type.GeometryDescriptor in project GeoGig by boundlessgeo.
the class GeogigSimpleFeature method getDefaultGeometry.
@Override
public Object getDefaultGeometry() {
// should be specified in the index as the default key (null)
Integer idx = nameToRevTypeIndex.get(null);
List<Optional<Object>> values = getValues();
Object defaultGeometry = idx != null ? values.get(idx).orNull() : null;
// not found? do we have a default geometry at all?
if (defaultGeometry == null) {
GeometryDescriptor geometryDescriptor = featureType.getGeometryDescriptor();
if (geometryDescriptor != null) {
Integer defaultGeomIndex = nameToRevTypeIndex.get(geometryDescriptor.getName().getLocalPart());
defaultGeometry = values.get(defaultGeomIndex.intValue()).get();
}
}
return defaultGeometry;
}
use of org.opengis.feature.type.GeometryDescriptor in project GeoGig by boundlessgeo.
the class RemoteRepositoryTestCase method feature.
protected Feature feature(SimpleFeatureType type, String id, Object... values) throws ParseException {
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
for (int i = 0; i < values.length; i++) {
Object value = values[i];
if (type.getDescriptor(i) instanceof GeometryDescriptor) {
if (value instanceof String) {
value = new WKTReader2().read((String) value);
}
}
builder.set(i, value);
}
return builder.buildFeature(id);
}
use of org.opengis.feature.type.GeometryDescriptor in project GeoGig by boundlessgeo.
the class GeoJsonImport method runInternal.
@Override
protected void runInternal(GeogigCLI cli) throws InvalidParameterException, CommandFailedException, IOException {
checkParameter(geoJSONList != null && !geoJSONList.isEmpty(), "No GeoJSON specified");
checkParameter(geomName == null || !geomNameAuto, "Cannot use --geom-name and --geom-name-auto at the same time");
for (String geoJSON : geoJSONList) {
DataStore dataStore = null;
try {
dataStore = getDataStore(geoJSON);
} catch (InvalidParameterException e) {
cli.getConsole().println("The GeoJSON file '" + geoJSON + "' could not be found, skipping...");
continue;
}
if (fidAttribute != null) {
AttributeDescriptor attrib = dataStore.getSchema(dataStore.getNames().get(0)).getDescriptor(fidAttribute);
if (attrib == null) {
throw new InvalidParameterException("The specified attribute does not exist in the selected GeoJSON file");
}
}
if (geomNameAuto) {
String destPath = destTable;
if (destPath == null) {
destPath = dataStore.getSchema(dataStore.getNames().get(0)).getTypeName();
}
Optional<RevFeatureType> ft = cli.getGeogig().command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + destPath).call(RevFeatureType.class);
// attribute
if (ft.isPresent()) {
GeometryDescriptor geomDescriptor = ft.get().type().getGeometryDescriptor();
if (geomDescriptor != null) {
geomName = geomDescriptor.getLocalName();
}
}
}
try {
cli.getConsole().println("Importing from GeoJSON " + geoJSON);
ProgressListener progressListener = cli.getProgressListener();
cli.getGeogig().command(ImportOp.class).setAll(true).setTable(null).setAlter(alter).setOverwrite(!add).setDestinationPath(destTable).setDataStore(dataStore).setFidAttribute(fidAttribute).setGeometryNameOverride(geomName).setAdaptToDefaultFeatureType(!forceFeatureType).setProgressListener(progressListener).call();
cli.getConsole().println(geoJSON + " imported successfully.");
} catch (GeoToolsOpException e) {
switch(e.statusCode) {
case NO_FEATURES_FOUND:
throw new CommandFailedException("No features were found in the GeoJSON file.", e);
case UNABLE_TO_GET_NAMES:
throw new CommandFailedException("Unable to get feature types from the GeoJSON file.", e);
case UNABLE_TO_GET_FEATURES:
throw new CommandFailedException("Unable to get features from the GeoJSON file.", e);
case UNABLE_TO_INSERT:
throw new CommandFailedException("Unable to insert features into the working tree.", e);
case INCOMPATIBLE_FEATURE_TYPE:
throw new CommandFailedException("The feature type of the data to import does not match the feature type of the destination tree and cannot be imported\n" + "USe the --force-featuretype switch to import using the original featuretype and crete a mixed type tree", e);
default:
throw new CommandFailedException("Import failed with exception: " + e.statusCode.name(), e);
}
}
}
}
Aggregations