Search in sources :

Example 6 with AttributeType

use of org.opengis.feature.type.AttributeType in project spatial-portal by AtlasOfLivingAustralia.

the class AreaUploadShapefileWizardController method loadShape.

private void loadShape(String filename) {
    CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
    try {
        FileDataStore store = FileDataStoreFinder.getDataStore(new File(filename));
        source = store.getFeatureSource();
        features = source.getFeatures();
        Listhead lhd = new Listhead();
        SimpleFeatureType schema = features.getSchema();
        Listheader lh = new Listheader(StringConstants.ID);
        lh.setParent(lhd);
        for (AttributeType at : schema.getTypes()) {
            if (schema.getDescriptor(at.getName()) == null) {
                continue;
            }
            lh = new Listheader(at.getName().toString());
            lh.setParent(lhd);
        }
        lhd.setParent(lAttributes);
        SimpleFeatureIterator fi = features.features();
        while (fi.hasNext()) {
            SimpleFeature f = fi.next();
            Listitem li = new Listitem();
            Listcell lc;
            String value;
            // add identifier
            lc = new Listcell(f.getIdentifier().getID());
            lc.setParent(li);
            for (AttributeType at : schema.getTypes()) {
                if (schema.getDescriptor(at.getName()) == null) {
                    continue;
                }
                Object obj = f.getAttribute(at.getName());
                if (obj == null) {
                    value = f.getID();
                } else {
                    value = String.valueOf(obj);
                }
                lc = new Listcell(value);
                lc.setParent(li);
            }
            li.setValue(f.getIdentifier());
            li.setParent(lAttributes);
        }
        // loadFeatures
        // check if only a single feature,
        // if so, then select it and map it automatically
        LOGGER.debug("features.size(): " + features.size());
        if (features.size() > 1) {
            executeShapeImageRenderer(null);
        } else {
            LOGGER.debug("only a single feature, bypassing wizard...");
            fi = features.features();
            Set<FeatureId> ids = new HashSet<FeatureId>();
            ids.add(fi.next().getIdentifier());
            loadOnMap(ids, filename);
            // echo detach
            Events.echoEvent("onClick$btnCancel", this, null);
        }
        try {
            fi.close();
        } catch (Exception e) {
        }
    } catch (IOException e) {
        LOGGER.debug("IO Exception ", e);
    } catch (Exception e) {
        LOGGER.debug("Generic exception", e);
    }
}
Also used : IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) ParseException(com.vividsolutions.jts.io.ParseException) IOException(java.io.IOException) FeatureId(org.opengis.filter.identity.FeatureId) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) AttributeType(org.opengis.feature.type.AttributeType) FileDataStore(org.geotools.data.FileDataStore) File(java.io.File)

Example 7 with AttributeType

use of org.opengis.feature.type.AttributeType 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 8 with AttributeType

use of org.opengis.feature.type.AttributeType 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)

Aggregations

AttributeType (org.opengis.feature.type.AttributeType)8 GeometryType (org.opengis.feature.type.GeometryType)5 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)3 Name (org.opengis.feature.type.Name)3 NameImpl (org.geotools.feature.NameImpl)2 DataSourceAttributeData (com.sldeditor.datasource.attribute.DataSourceAttributeData)1 ExampleLineInterface (com.sldeditor.datasource.example.ExampleLineInterface)1 ExamplePointInterface (com.sldeditor.datasource.example.ExamplePointInterface)1 ExamplePolygonInterface (com.sldeditor.datasource.example.ExamplePolygonInterface)1 ParseException (com.vividsolutions.jts.io.ParseException)1 File (java.io.File)1 IOException (java.io.IOException)1 QName (javax.xml.namespace.QName)1 FileDataStore (org.geotools.data.FileDataStore)1 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)1 AttributeTypeImpl (org.geotools.feature.type.AttributeTypeImpl)1 GeometryTypeImpl (org.geotools.feature.type.GeometryTypeImpl)1 Geometry (org.locationtech.jts.geom.Geometry)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1