Search in sources :

Example 1 with AnyFeature

use of org.opengis.observation.AnyFeature in project geotoolkit by Geomatys.

the class XmlFeatureReader method getFeatureFromFOI.

protected final Feature getFeatureFromFOI(final AnyFeature foi) {
    if (foi instanceof SamplingFeature) {
        final SamplingFeature feature = (SamplingFeature) foi;
        final Feature f = type.newInstance();
        f.setPropertyValue(AttributeConvention.IDENTIFIER, feature.getId());
        final org.opengis.geometry.Geometry isoGeom = feature.getGeometry();
        try {
            final Geometry geom;
            if (isoGeom instanceof AbstractGeometry) {
                geom = GeometrytoJTS.toJTS((AbstractGeometry) isoGeom);
            } else {
                geom = null;
            }
            if (firstCRS && isoGeom != null) {
                // configure crs in the feature type
                final CoordinateReferenceSystem crs = ((AbstractGeometry) isoGeom).getCoordinateReferenceSystem(false);
                type = FeatureTypeExt.createSubType(type, null, crs);
                firstCRS = false;
            }
            f.setPropertyValue(ATT_DESC.toString(), feature.getDescription());
            if (feature.getName() != null) {
                f.setPropertyValue(ATT_NAME.toString(), feature.getName().toString());
            }
            f.setPropertyValue(ATT_POSITION.toString(), geom);
            final List<String> sampleds = new ArrayList<>();
            for (FeatureProperty featProp : feature.getSampledFeatures()) {
                if (featProp.getHref() != null) {
                    sampleds.add(featProp.getHref());
                }
            }
            f.setPropertyValue(ATT_SAMPLED.toString(), sampleds);
            return f;
        } catch (FactoryException ex) {
            LOGGER.log(Level.WARNING, "error while transforming GML geometry to JTS", ex);
        }
    } else {
        LOGGER.warning("unable to find a valid feature of interest in the observation");
    }
    return null;
}
Also used : AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) FactoryException(org.opengis.util.FactoryException) ArrayList(java.util.ArrayList) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) AnyFeature(org.opengis.observation.AnyFeature) Feature(org.opengis.feature.Feature) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) Geometry(org.locationtech.jts.geom.Geometry) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 2 with AnyFeature

use of org.opengis.observation.AnyFeature in project geotoolkit by Geomatys.

the class NetcdfFeatureReader method getFeatureFromFOI.

protected final Feature getFeatureFromFOI(final AnyFeature foi) {
    if (foi instanceof SamplingFeature) {
        final SamplingFeature feature = (SamplingFeature) foi;
        final org.opengis.geometry.Geometry isoGeom = feature.getGeometry();
        try {
            final Geometry geom;
            if (isoGeom instanceof AbstractGeometry) {
                geom = GeometrytoJTS.toJTS((AbstractGeometry) isoGeom, AxisResolve.STRICT);
            } else {
                geom = null;
            }
            if (firstCRS && isoGeom != null) {
                // configure crs in the feature type
                final CoordinateReferenceSystem crs = ((AbstractGeometry) isoGeom).getCoordinateReferenceSystem(false);
                type = new ReprojectMapper(type, crs).getMappedType();
                firstCRS = false;
            }
            final Feature f = type.newInstance();
            f.setPropertyValue(AttributeConvention.IDENTIFIER, feature.getId());
            f.setPropertyValue(OMFeatureTypes.ATT_DESC.toString(), feature.getDescription());
            f.setPropertyValue(OMFeatureTypes.ATT_NAME.toString(), feature.getName());
            f.setPropertyValue(OMFeatureTypes.ATT_POSITION.toString(), geom);
            final List<String> sampleds = new ArrayList<>();
            for (FeatureProperty featProp : feature.getSampledFeatures()) {
                if (featProp.getHref() != null) {
                    sampleds.add(featProp.getHref());
                }
            }
            f.setPropertyValue(OMFeatureTypes.ATT_SAMPLED.toString(), sampleds);
            return f;
        } catch (FactoryException ex) {
            LOGGER.log(Level.WARNING, "error while transforming GML geometry to JTS", ex);
        }
    } else {
        LOGGER.warning("unable to find a valid feature of interest in the observation");
    }
    return null;
}
Also used : AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) FactoryException(org.opengis.util.FactoryException) ReprojectMapper(org.geotoolkit.feature.ReprojectMapper) ArrayList(java.util.ArrayList) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) SamplingFeature(org.geotoolkit.sampling.xml.SamplingFeature) Feature(org.opengis.feature.Feature) AnyFeature(org.opengis.observation.AnyFeature) FeatureProperty(org.geotoolkit.gml.xml.FeatureProperty) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) Geometry(org.locationtech.jts.geom.Geometry) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

ArrayList (java.util.ArrayList)2 AbstractGeometry (org.geotoolkit.gml.xml.AbstractGeometry)2 FeatureProperty (org.geotoolkit.gml.xml.FeatureProperty)2 SamplingFeature (org.geotoolkit.sampling.xml.SamplingFeature)2 Geometry (org.locationtech.jts.geom.Geometry)2 Feature (org.opengis.feature.Feature)2 AnyFeature (org.opengis.observation.AnyFeature)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 FactoryException (org.opengis.util.FactoryException)2 ReprojectMapper (org.geotoolkit.feature.ReprojectMapper)1