Search in sources :

Example 1 with GeometryDescriptor

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;
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Point(com.vividsolutions.jts.geom.Point)

Example 2 with GeometryDescriptor

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;
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) GeometryAttribute(org.opengis.feature.GeometryAttribute) GeometryAttributeImpl(org.geotools.feature.GeometryAttributeImpl)

Example 3 with GeometryDescriptor

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;
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) Optional(com.google.common.base.Optional)

Example 4 with GeometryDescriptor

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);
}
Also used : GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) WKTReader2(org.geotools.geometry.jts.WKTReader2) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 5 with GeometryDescriptor

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);
            }
        }
    }
}
Also used : InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) ProgressListener(org.locationtech.geogig.api.ProgressListener) DataStore(org.geotools.data.DataStore) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) ImportOp(org.locationtech.geogig.geotools.plumbing.ImportOp) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) GeoToolsOpException(org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)

Aggregations

GeometryDescriptor (org.opengis.feature.type.GeometryDescriptor)24 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)6 WKTReader2 (org.geotools.geometry.jts.WKTReader2)5 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)5 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Test (org.junit.jupiter.api.Test)3 Filter (org.opengis.filter.Filter)3 SLDEditorMain (com.sldeditor.SLDEditorMain)2 DataSourceInterface (com.sldeditor.datasource.DataSourceInterface)2 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)2 CheckAttributeInterface (com.sldeditor.datasource.checks.CheckAttributeInterface)2 WindowEvent (java.awt.event.WindowEvent)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2