Search in sources :

Example 16 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project GeoGig by boundlessgeo.

the class ResponseWriter method writeMerged.

/**
     * Writes the response for a set of merged features while also supplying the geometry.
     * 
     * @param geogig - a CommandLocator to call commands from
     * @param features - a FeatureInfo iterator to build the response from
     * @throws XMLStreamException
     */
public void writeMerged(final Context geogig, Iterator<FeatureInfo> features) throws XMLStreamException {
    Iterator<GeometryChange> changeIterator = Iterators.transform(features, new Function<FeatureInfo, GeometryChange>() {

        @Override
        public GeometryChange apply(FeatureInfo input) {
            GeometryChange change = null;
            RevFeature revFeature = RevFeatureBuilder.build(input.getFeature());
            RevFeatureType featureType = input.getFeatureType();
            Collection<PropertyDescriptor> attribs = featureType.type().getDescriptors();
            String crsCode = null;
            for (PropertyDescriptor attrib : attribs) {
                PropertyType attrType = attrib.getType();
                if (attrType instanceof GeometryType) {
                    GeometryType gt = (GeometryType) attrType;
                    CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
                    if (crs != null) {
                        try {
                            crsCode = CRS.lookupIdentifier(Citations.EPSG, crs, false);
                        } catch (FactoryException e) {
                            crsCode = null;
                        }
                        if (crsCode != null) {
                            crsCode = "EPSG:" + crsCode;
                        }
                    }
                    break;
                }
            }
            FeatureBuilder builder = new FeatureBuilder(featureType);
            GeogigSimpleFeature simpleFeature = (GeogigSimpleFeature) builder.build(revFeature.getId().toString(), revFeature);
            change = new GeometryChange(simpleFeature, ChangeType.MODIFIED, input.getPath(), crsCode);
            return change;
        }
    });
    while (changeIterator.hasNext()) {
        GeometryChange next = changeIterator.next();
        if (next != null) {
            GeogigSimpleFeature feature = next.getFeature();
            out.writeStartElement("Feature");
            writeElement("change", "MERGED");
            writeElement("id", next.getPath());
            List<Object> attributes = feature.getAttributes();
            for (Object attribute : attributes) {
                if (attribute instanceof Geometry) {
                    writeElement("geometry", ((Geometry) attribute).toText());
                    break;
                }
            }
            if (next.getCRS() != null) {
                writeElement("crs", next.getCRS());
            }
            out.writeEndElement();
        }
    }
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) RevFeatureBuilder(org.locationtech.geogig.api.RevFeatureBuilder) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) FactoryException(org.opengis.referencing.FactoryException) FeatureInfo(org.locationtech.geogig.api.FeatureInfo) PropertyType(org.opengis.feature.type.PropertyType) Geometry(com.vividsolutions.jts.geom.Geometry) GeometryType(org.opengis.feature.type.GeometryType) RevFeature(org.locationtech.geogig.api.RevFeature) Collection(java.util.Collection) RevObject(org.locationtech.geogig.api.RevObject) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeogigSimpleFeature(org.locationtech.geogig.api.GeogigSimpleFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 17 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project GeoGig by boundlessgeo.

the class ResponseWriter method writeFeatureDiffResponse.

/**
     * Writes a set of feature diffs to the stream.
     * 
     * @param diffs a map of {@link PropertyDescriptor} to {@link AttributeDiffs} that specify the
     *        difference between two features
     * @throws XMLStreamException
     */
public void writeFeatureDiffResponse(Map<PropertyDescriptor, AttributeDiff> diffs) throws XMLStreamException {
    Set<Entry<PropertyDescriptor, AttributeDiff>> entries = diffs.entrySet();
    Iterator<Entry<PropertyDescriptor, AttributeDiff>> iter = entries.iterator();
    while (iter.hasNext()) {
        Entry<PropertyDescriptor, AttributeDiff> entry = iter.next();
        out.writeStartElement("diff");
        PropertyType attrType = entry.getKey().getType();
        if (attrType instanceof GeometryType) {
            writeElement("geometry", "true");
            GeometryType gt = (GeometryType) attrType;
            CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
            if (crs != null) {
                String crsCode = null;
                try {
                    crsCode = CRS.lookupIdentifier(Citations.EPSG, crs, false);
                } catch (FactoryException e) {
                    crsCode = null;
                }
                if (crsCode != null) {
                    writeElement("crs", "EPSG:" + crsCode);
                }
            }
        }
        writeElement("attributename", entry.getKey().getName().toString());
        writeElement("changetype", entry.getValue().getType().toString());
        if (entry.getValue().getOldValue() != null && entry.getValue().getOldValue().isPresent()) {
            writeElement("oldvalue", entry.getValue().getOldValue().get().toString());
        }
        if (entry.getValue().getNewValue() != null && entry.getValue().getNewValue().isPresent() && !entry.getValue().getType().equals(TYPE.NO_CHANGE)) {
            writeElement("newvalue", entry.getValue().getNewValue().get().toString());
        }
        out.writeEndElement();
    }
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Entry(java.util.Map.Entry) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) FactoryException(org.opengis.referencing.FactoryException) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) PropertyType(org.opengis.feature.type.PropertyType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 18 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project GeoGig by boundlessgeo.

the class OSMUtils method nodeType.

public static synchronized SimpleFeatureType nodeType() {
    if (NodeType == null) {
        String typeSpec = "visible:Boolean,version:Integer,timestamp:java.lang.Long,tags:String," + "changeset:java.lang.Long,user:String,location:Point:srid=4326";
        try {
            SimpleFeatureType type = DataUtilities.createType(NAMESPACE, OSMUtils.NODE_TYPE_NAME, typeSpec);
            boolean longitudeFirst = true;
            CoordinateReferenceSystem forceLonLat = CRS.decode("EPSG:4326", longitudeFirst);
            NodeType = DataUtilities.createSubType(type, null, forceLonLat);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
    return NodeType;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 19 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project GeoGig by boundlessgeo.

the class OSMUtils method wayType.

public static synchronized SimpleFeatureType wayType() {
    if (WayType == null) {
        String typeSpec = "visible:Boolean,version:Integer,timestamp:java.lang.Long,tags:String," + "changeset:java.lang.Long,user:String,nodes:String,way:LineString:srid=4326";
        try {
            SimpleFeatureType type = DataUtilities.createType(NAMESPACE, OSMUtils.WAY_TYPE_NAME, typeSpec);
            boolean longitudeFirst = true;
            CoordinateReferenceSystem forceLonLat = CRS.decode("EPSG:4326", longitudeFirst);
            WayType = DataUtilities.createSubType(type, null, forceLonLat);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
    return WayType;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 20 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project GeoGig by boundlessgeo.

the class BoundsFilteringDiffConsumer method createProjectedFilter.

private ReferencedEnvelope createProjectedFilter(ObjectId metadataId) {
    final ReferencedEnvelope boundsFilter = this.boundsFilter;
    RevFeatureType featureType = ftypeSource.getFeatureType(metadataId);
    CoordinateReferenceSystem nativeCrs = featureType.type().getCoordinateReferenceSystem();
    if (null == nativeCrs || nativeCrs instanceof DefaultEngineeringCRS) {
        return boundsFilter;
    }
    ReferencedEnvelope transformedFilter;
    try {
        transformedFilter = boundsFilter.transform(nativeCrs, true);
    } catch (TransformException | FactoryException e) {
        throw Throwables.propagate(e);
    }
    return transformedFilter;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DefaultEngineeringCRS(org.geotools.referencing.crs.DefaultEngineeringCRS)

Aggregations

CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)210 Test (org.junit.Test)80 MathTransform (org.opengis.referencing.operation.MathTransform)32 FactoryException (org.opengis.referencing.FactoryException)25 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)24 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)23 Geometry (com.vividsolutions.jts.geom.Geometry)21 TransformException (org.opengis.referencing.operation.TransformException)21 DependsOnMethod (org.apache.sis.test.DependsOnMethod)19 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)13 Geometry (org.locationtech.jts.geom.Geometry)11 FactoryException (org.opengis.util.FactoryException)11 SimpleFeature (org.opengis.feature.simple.SimpleFeature)9 DirectPosition (org.opengis.geometry.DirectPosition)9 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)9 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)9 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)9 ArrayList (java.util.ArrayList)8 GeometryType (org.opengis.feature.type.GeometryType)8 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)7