Search in sources :

Example 11 with GeometryType

use of org.opengis.feature.type.GeometryType in project activityinfo by bedatadriven.

the class ImportView method updateGeometry.

private void updateGeometry(GeoAdminClient client, Map<ResourceId, ResourceId> idMap) throws IOException {
    FeatureSourceStorageProvider catalog = new FeatureSourceStorageProvider();
    FeatureSourceStorage formStorage = (FeatureSourceStorage) catalog.getForm(getModel().getSourceFormId().get()).get();
    ResourceId targetFormId = getModel().getTargetFormId().get();
    FieldProfile targetField = getTargetProfile().get().getGeometryField();
    if (targetField == null) {
        System.err.println("No geometry field to update.");
        return;
    }
    int sourceIndex = formStorage.getGeometryAttributeIndex();
    if (sourceIndex == -1) {
        System.err.println("No source geometry field.");
        return;
    }
    SimpleFeatureSource featureSource = formStorage.getFeatureSource();
    GeometryType geometryType = (GeometryType) featureSource.getSchema().getDescriptor(sourceIndex).getType();
    GeometryConverter converter = new GeometryConverter(geometryType);
    SimpleFeatureIterator it = featureSource.getFeatures().features();
    while (it.hasNext()) {
        SimpleFeature feature = it.next();
        ResourceId sourceId = ResourceId.valueOf(feature.getID());
        ResourceId targetId = idMap.get(sourceId);
        if (targetId != null) {
            Geometry geometry = converter.toWgs84(feature.getAttribute(sourceIndex));
            System.out.print("Updating geometry for " + targetId + " [" + geometry.getGeometryType() + "] ... ");
            try {
                client.updateGeometry(targetFormId, targetId, targetField.getId(), geometry);
                System.out.println("OK");
            } catch (Exception e) {
                System.out.println("ERROR: " + e.getMessage());
            }
        }
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FeatureSourceStorage(org.activityinfo.geoadmin.source.FeatureSourceStorage) GeometryType(org.opengis.feature.type.GeometryType) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) ResourceId(org.activityinfo.model.resource.ResourceId) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) FieldProfile(org.activityinfo.geoadmin.merge2.view.profile.FieldProfile) GeometryConverter(org.activityinfo.geoadmin.source.GeometryConverter) FeatureSourceStorageProvider(org.activityinfo.geoadmin.source.FeatureSourceStorageProvider) SimpleFeature(org.opengis.feature.simple.SimpleFeature) IOException(java.io.IOException)

Example 12 with GeometryType

use of org.opengis.feature.type.GeometryType in project sldeditor by robward-scisys.

the class ExtendedSimpleFeatureTypeBuilder method createAttributeDescriptor.

/**
 * Creates the attribute descriptor.
 *
 * @param name the name
 * @param binding the binding
 * @return the attribute descriptor
 */
public AttributeDescriptor createAttributeDescriptor(String name, Class<?> binding) {
    AttributeDescriptor descriptor = null;
    attributeBuilder.setBinding(binding);
    attributeBuilder.setName(name);
    // 
    if ((defaultGeometry != null && defaultGeometry.equals(name)) || Geometry.class.isAssignableFrom(binding)) {
        // if no crs was set, set to defaultCRS
        if (!attributeBuilder.isCRSSet()) {
            if (defaultCrs == null && !defaultCrsSet) {
                String message = String.format("Creating %s with null CoordinateReferenceSystem - did you mean to setCRS?", name);
                LOGGER.fine(message);
            }
            attributeBuilder.setCRS(defaultCrs);
        }
        GeometryType type = attributeBuilder.buildGeometryType();
        descriptor = attributeBuilder.buildDescriptor(name, type);
    } else {
        AttributeType type = attributeBuilder.buildType();
        descriptor = attributeBuilder.buildDescriptor(name, type);
    }
    return (descriptor);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryType(org.opengis.feature.type.GeometryType) AttributeType(org.opengis.feature.type.AttributeType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor)

Example 13 with GeometryType

use of org.opengis.feature.type.GeometryType in project sldeditor by robward-scisys.

the class SLDEditorBufferedImageLegendGraphicBuilder method cloneWithDimensionality.

/**
 * Clones the given schema, changing the geometry attribute to match the given dimensionality.
 *
 * @param schema schema to clone
 * @param dimensionality dimensionality for the geometry 1= points, 2= lines, 3= polygons
 */
private FeatureType cloneWithDimensionality(FeatureType schema, int dimensionality) {
    SimpleFeatureType simpleFt = (SimpleFeatureType) schema;
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName(schema.getName());
    builder.setCRS(schema.getCoordinateReferenceSystem());
    for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) {
        if (isMixedGeometry(desc)) {
            GeometryDescriptor geomDescriptor = (GeometryDescriptor) desc;
            GeometryType geomType = geomDescriptor.getType();
            Class<?> geometryClass = getGeometryForDimensionality(dimensionality);
            GeometryType gt = new GeometryTypeImpl(geomType.getName(), geometryClass, geomType.getCoordinateReferenceSystem(), geomType.isIdentified(), geomType.isAbstract(), geomType.getRestrictions(), geomType.getSuper(), geomType.getDescription());
            builder.add(new GeometryDescriptorImpl(gt, geomDescriptor.getName(), geomDescriptor.getMinOccurs(), geomDescriptor.getMaxOccurs(), geomDescriptor.isNillable(), geomDescriptor.getDefaultValue()));
        } else {
            builder.add(desc);
        }
    }
    schema = builder.buildFeatureType();
    return schema;
}
Also used : GeometryDescriptorImpl(org.geotools.feature.type.GeometryDescriptorImpl) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) GeometryType(org.opengis.feature.type.GeometryType) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) GeometryTypeImpl(org.geotools.feature.type.GeometryTypeImpl)

Example 14 with GeometryType

use of org.opengis.feature.type.GeometryType in project sldeditor by robward-scisys.

the class DataSourceInfo method getPropertyDescriptorList.

/**
 * Gets the property descriptor list.
 *
 * @return the property descriptor list
 */
public Collection<PropertyDescriptor> getPropertyDescriptorList() {
    if (schema != null) {
        return schema.getDescriptors();
    } else {
        if (geometryType == GeometryTypeEnum.RASTER) {
            if (rasterPropertyDescriptorList == null) {
                rasterPropertyDescriptorList = new ArrayList<>();
                CoordinateReferenceSystem crs = null;
                boolean isIdentifiable = false;
                boolean isAbstract = false;
                List<Filter> restrictions = null;
                AttributeType superType = null;
                InternationalString description = null;
                GeometryType type = featureTypeFactory.createGeometryType(new NameImpl(RASTER_GEOMETRY_FIELD), GridCoverage2D.class, crs, isIdentifiable, isAbstract, restrictions, superType, description);
                GeometryDescriptor descriptor = featureTypeFactory.createGeometryDescriptor(type, new NameImpl(RASTER_GEOMETRY_FIELD), 0, 1, false, null);
                rasterPropertyDescriptorList.add(descriptor);
            }
            return rasterPropertyDescriptorList;
        }
    }
    return null;
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) NameImpl(org.geotools.feature.NameImpl) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) Filter(org.opengis.filter.Filter) InternationalString(org.opengis.util.InternationalString) AttributeType(org.opengis.feature.type.AttributeType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 15 with GeometryType

use of org.opengis.feature.type.GeometryType in project sldeditor by robward-scisys.

the class VectorReader method createSLDData.

/**
 * Creates the SLD data.
 *
 * @param map the map
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createSLDData(Map<String, Object> map, String featureClass) {
    StyledLayerDescriptor sld = null;
    DataStore dataStore = null;
    try {
        dataStore = DataStoreFinder.getDataStore(map);
    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
        return null;
    }
    if (dataStore != null) {
        // Try connecting to a vector data source
        String typeName;
        GeometryTypeEnum geometryTypeEnum = GeometryTypeEnum.UNKNOWN;
        try {
            if (featureClass == null) {
                typeName = dataStore.getTypeNames()[0];
            } else {
                typeName = featureClass;
            }
            SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
            SimpleFeatureType schema = source.getSchema();
            GeometryType geometryType = schema.getGeometryDescriptor().getType();
            Class<?> bindingType = geometryType.getBinding();
            geometryTypeEnum = GeometryTypeMapping.getGeometryType(bindingType);
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
            return null;
        } finally {
            dataStore.dispose();
        }
        switch(geometryTypeEnum) {
            case POINT:
                sld = DefaultSymbols.createNewPoint();
                break;
            case LINE:
                sld = DefaultSymbols.createNewLine();
                break;
            case POLYGON:
                sld = DefaultSymbols.createNewPolygon();
                break;
            default:
                break;
        }
    }
    return sld;
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeatureSource(org.geotools.data.simple.SimpleFeatureSource) DataStore(org.geotools.data.DataStore) IOException(java.io.IOException) GeometryTypeEnum(com.sldeditor.datasource.impl.GeometryTypeEnum)

Aggregations

GeometryType (org.opengis.feature.type.GeometryType)15 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)8 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)6 PropertyType (org.opengis.feature.type.PropertyType)6 AttributeType (org.opengis.feature.type.AttributeType)5 FactoryException (org.opengis.referencing.FactoryException)5 Geometry (com.vividsolutions.jts.geom.Geometry)4 RevFeature (org.locationtech.geogig.api.RevFeature)4 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)4 RevObject (org.locationtech.geogig.api.RevObject)4 Optional (com.google.common.base.Optional)3 Collection (java.util.Collection)3 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)3 GeogigSimpleFeature (org.locationtech.geogig.api.GeogigSimpleFeature)3 RevFeatureBuilder (org.locationtech.geogig.api.RevFeatureBuilder)3 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)3 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)3 IOException (java.io.IOException)2 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)2 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)2