Search in sources :

Example 1 with PropertyType

use of org.opengis.feature.type.PropertyType in project GeoGig by boundlessgeo.

the class Show method printRaw.

private void printRaw(GeogigCLI cli) throws IOException {
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    for (String ref : refs) {
        Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
        if (!obj.isPresent()) {
            ref = getFullRef(ref);
            obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
        }
        checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
        RevObject revObject = obj.get();
        if (revObject instanceof RevFeature) {
            Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class).setRefSpec(ref).call();
            if (opt.isPresent()) {
                RevFeatureType ft = opt.get();
                ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
                RevFeature feature = (RevFeature) revObject;
                Ansi ansi = super.newAnsi(console.getTerminal());
                ansi.a(ref).newline();
                ansi.a(feature.getId().toString()).newline();
                ImmutableList<Optional<Object>> values = feature.getValues();
                int i = 0;
                for (Optional<Object> value : values) {
                    PropertyDescriptor attrib = attribs.get(i);
                    ansi.a(attrib.getName()).newline();
                    PropertyType attrType = attrib.getType();
                    String typeName = FieldType.forBinding(attrType.getBinding()).name();
                    if (attrType instanceof GeometryType) {
                        GeometryType gt = (GeometryType) attrType;
                        CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
                        String crsText = CrsTextSerializer.serialize(crs);
                        ansi.a(typeName).a(" ").a(crsText).newline();
                    } else {
                        ansi.a(typeName).newline();
                    }
                    ansi.a(value.or("[NULL]").toString()).newline();
                    i++;
                }
                console.println(ansi.toString());
            } else {
                CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
                console.println(s);
            }
        } else {
            CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
            console.println(s);
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) RevObject(org.locationtech.geogig.api.RevObject) PropertyType(org.opengis.feature.type.PropertyType) GeometryType(org.opengis.feature.type.GeometryType) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) CatObject(org.locationtech.geogig.api.plumbing.CatObject) RevObject(org.locationtech.geogig.api.RevObject) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Ansi(org.fusesource.jansi.Ansi) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 2 with PropertyType

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

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

use of org.opengis.feature.type.PropertyType in project GeoGig by boundlessgeo.

the class ResponseWriter method writeFeatureType.

public void writeFeatureType(RevFeatureType featureType, String tag) throws XMLStreamException {
    out.writeStartElement(tag);
    writeElement("id", featureType.getId().toString());
    writeElement("name", featureType.getName().toString());
    ImmutableList<PropertyDescriptor> descriptors = featureType.sortedDescriptors();
    for (PropertyDescriptor descriptor : descriptors) {
        out.writeStartElement("attribute");
        writeElement("name", descriptor.getName().toString());
        writeElement("type", FieldType.forBinding(descriptor.getType().getBinding()).name());
        writeElement("minoccurs", Integer.toString(descriptor.getMinOccurs()));
        writeElement("maxoccurs", Integer.toString(descriptor.getMaxOccurs()));
        writeElement("nillable", Boolean.toString(descriptor.isNillable()));
        PropertyType attrType = descriptor.getType();
        if (attrType instanceof GeometryType) {
            GeometryType gt = (GeometryType) attrType;
            CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
            String crsText = CrsTextSerializer.serialize(crs);
            writeElement("crs", crsText);
        }
        out.writeEndElement();
    }
    out.writeEndElement();
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) PropertyType(org.opengis.feature.type.PropertyType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 5 with PropertyType

use of org.opengis.feature.type.PropertyType in project GeoGig by boundlessgeo.

the class ResponseWriter method writeGeometryChanges.

/**
     * Writes the response for a set of diffs while also supplying the geometry.
     * 
     * @param geogig - a CommandLocator to call commands from
     * @param diff - a DiffEntry iterator to build the response from
     * @throws XMLStreamException
     */
public void writeGeometryChanges(final Context geogig, Iterator<DiffEntry> diff, int page, int elementsPerPage) throws XMLStreamException {
    Iterators.advance(diff, page * elementsPerPage);
    int counter = 0;
    Iterator<GeometryChange> changeIterator = Iterators.transform(diff, new Function<DiffEntry, GeometryChange>() {

        @Override
        public GeometryChange apply(DiffEntry input) {
            Optional<RevObject> feature = Optional.absent();
            Optional<RevObject> type = Optional.absent();
            String path = null;
            String crsCode = null;
            GeometryChange change = null;
            if (input.changeType() == ChangeType.ADDED || input.changeType() == ChangeType.MODIFIED) {
                feature = geogig.command(RevObjectParse.class).setObjectId(input.newObjectId()).call();
                type = geogig.command(RevObjectParse.class).setObjectId(input.getNewObject().getMetadataId()).call();
                path = input.getNewObject().path();
            } else if (input.changeType() == ChangeType.REMOVED) {
                feature = geogig.command(RevObjectParse.class).setObjectId(input.oldObjectId()).call();
                type = geogig.command(RevObjectParse.class).setObjectId(input.getOldObject().getMetadataId()).call();
                path = input.getOldObject().path();
            }
            if (feature.isPresent() && feature.get() instanceof RevFeature && type.isPresent() && type.get() instanceof RevFeatureType) {
                RevFeatureType featureType = (RevFeatureType) type.get();
                Collection<PropertyDescriptor> attribs = featureType.type().getDescriptors();
                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;
                    }
                }
                RevFeature revFeature = (RevFeature) feature.get();
                FeatureBuilder builder = new FeatureBuilder(featureType);
                GeogigSimpleFeature simpleFeature = (GeogigSimpleFeature) builder.build(revFeature.getId().toString(), revFeature);
                change = new GeometryChange(simpleFeature, input.changeType(), path, crsCode);
            }
            return change;
        }
    });
    while (changeIterator.hasNext() && (elementsPerPage == 0 || counter < elementsPerPage)) {
        GeometryChange next = changeIterator.next();
        if (next != null) {
            GeogigSimpleFeature feature = next.getFeature();
            ChangeType change = next.getChangeType();
            out.writeStartElement("Feature");
            writeElement("change", change.toString());
            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();
            counter++;
        }
    }
    if (changeIterator.hasNext()) {
        writeElement("nextPage", "true");
    }
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) RevFeatureBuilder(org.locationtech.geogig.api.RevFeatureBuilder) Optional(com.google.common.base.Optional) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) FactoryException(org.opengis.referencing.FactoryException) PropertyType(org.opengis.feature.type.PropertyType) Geometry(com.vividsolutions.jts.geom.Geometry) GeometryType(org.opengis.feature.type.GeometryType) ChangeType(org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType) RevFeature(org.locationtech.geogig.api.RevFeature) Collection(java.util.Collection) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevObject(org.locationtech.geogig.api.RevObject) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeogigSimpleFeature(org.locationtech.geogig.api.GeogigSimpleFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

GeometryType (org.opengis.feature.type.GeometryType)6 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)6 PropertyType (org.opengis.feature.type.PropertyType)6 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)6 RevFeature (org.locationtech.geogig.api.RevFeature)4 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)4 RevObject (org.locationtech.geogig.api.RevObject)4 FactoryException (org.opengis.referencing.FactoryException)4 Optional (com.google.common.base.Optional)3 Geometry (com.vividsolutions.jts.geom.Geometry)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 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)2 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 ConsoleReader (jline.console.ConsoleReader)1