use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class Show method printFeatureType.
private void printFeatureType(Ansi ansi, RevFeatureType ft, boolean useDefaultKeyword) {
ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
ansi.fg(Color.YELLOW).a(useDefaultKeyword ? "DEFAULT " : "").a("FEATURE TYPE ID: ").reset().a(ft.getId().toString()).newline().newline();
ansi.a(useDefaultKeyword ? "DEFAULT " : "").a("FEATURE TYPE ATTRIBUTES").newline();
for (PropertyDescriptor attrib : attribs) {
ansi.fg(Color.YELLOW).a(attrib.getName() + ": ").reset().a("<" + FieldType.forBinding(attrib.getType().getBinding()) + ">").newline();
}
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class OSMExport method getFeatures.
private Iterator<EntityContainer> getFeatures(String ref) {
Optional<ObjectId> id = geogig.command(RevParse.class).setRefSpec(ref).call();
if (!id.isPresent()) {
return Iterators.emptyIterator();
}
LsTreeOp op = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).setReference(ref);
if (bbox != null) {
final Envelope env;
try {
env = new Envelope(Double.parseDouble(bbox.get(0)), Double.parseDouble(bbox.get(2)), Double.parseDouble(bbox.get(1)), Double.parseDouble(bbox.get(3)));
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Wrong bbox definition");
}
Predicate<Bounded> filter = new Predicate<Bounded>() {
@Override
public boolean apply(final Bounded bounded) {
boolean intersects = bounded.intersects(env);
return intersects;
}
};
op.setBoundsFilter(filter);
}
Iterator<NodeRef> iterator = op.call();
final EntityConverter converter = new EntityConverter();
Function<NodeRef, EntityContainer> function = new Function<NodeRef, EntityContainer>() {
@Override
@Nullable
public EntityContainer apply(@Nullable NodeRef ref) {
RevFeature revFeature = geogig.command(RevObjectParse.class).setObjectId(ref.objectId()).call(RevFeature.class).get();
SimpleFeatureType featureType;
if (ref.path().startsWith(OSMUtils.NODE_TYPE_NAME)) {
featureType = OSMUtils.nodeType();
} else {
featureType = OSMUtils.wayType();
}
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
ImmutableList<Optional<Object>> values = revFeature.getValues();
for (int i = 0; i < descriptors.size(); i++) {
PropertyDescriptor descriptor = descriptors.get(i);
Optional<Object> value = values.get(i);
featureBuilder.set(descriptor.getName(), value.orNull());
}
SimpleFeature feature = featureBuilder.buildFeature(ref.name());
Entity entity = converter.toEntity(feature, null);
EntityContainer container;
if (entity instanceof Node) {
container = new NodeContainer((Node) entity);
} else {
container = new WayContainer((Way) entity);
}
return container;
}
};
return Iterators.transform(iterator, function);
}
use of org.opengis.feature.type.PropertyDescriptor in project GeoGig by boundlessgeo.
the class Log method writeCSV.
private void writeCSV(GeoGIG geogig, Writer out, Iterator<RevCommit> log) throws Exception {
String response = "ChangeType,FeatureId,CommitId,Parent CommitIds,Author Name,Author Email,Author Commit Time,Committer Name,Committer Email,Committer Commit Time,Commit Message";
out.write(response);
response = "";
String path = paths.get(0);
// This is the feature type object
Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(path).setParent(geogig.getRepository().workingTree().getTree()).call();
Optional<RevObject> type = Optional.absent();
if (ref.isPresent()) {
type = geogig.command(RevObjectParse.class).setRefSpec(ref.get().getMetadataId().toString()).call();
} else {
throw new CommandSpecException("Couldn't resolve the given path.");
}
if (type.isPresent() && type.get() instanceof RevFeatureType) {
RevFeatureType featureType = (RevFeatureType) type.get();
Collection<PropertyDescriptor> attribs = featureType.type().getDescriptors();
int attributeLength = attribs.size();
for (PropertyDescriptor attrib : attribs) {
response += "," + escapeCsv(attrib.getName().toString());
}
response += '\n';
out.write(response);
response = "";
RevCommit commit = null;
while (log.hasNext()) {
commit = log.next();
String parentId = commit.getParentIds().size() >= 1 ? commit.getParentIds().get(0).toString() : ObjectId.NULL.toString();
Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId).setNewVersion(commit.getId().toString()).setFilter(path).call();
while (diff.hasNext()) {
DiffEntry entry = diff.next();
response += entry.changeType().toString() + ",";
String fid = "";
if (entry.newPath() != null) {
if (entry.oldPath() != null) {
fid = entry.oldPath() + " -> " + entry.newPath();
} else {
fid = entry.newPath();
}
} else if (entry.oldPath() != null) {
fid = entry.oldPath();
}
response += fid + ",";
response += commit.getId().toString() + ",";
response += parentId;
if (commit.getParentIds().size() > 1) {
for (int index = 1; index < commit.getParentIds().size(); index++) {
response += " " + commit.getParentIds().get(index).toString();
}
}
response += ",";
if (commit.getAuthor().getName().isPresent()) {
response += escapeCsv(commit.getAuthor().getName().get());
}
response += ",";
if (commit.getAuthor().getEmail().isPresent()) {
response += escapeCsv(commit.getAuthor().getEmail().get());
}
response += "," + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format(new Date(commit.getAuthor().getTimestamp())) + ",";
if (commit.getCommitter().getName().isPresent()) {
response += escapeCsv(commit.getCommitter().getName().get());
}
response += ",";
if (commit.getCommitter().getEmail().isPresent()) {
response += escapeCsv(commit.getCommitter().getEmail().get());
}
response += "," + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format(new Date(commit.getCommitter().getTimestamp())) + ",";
String message = escapeCsv(commit.getMessage());
response += message;
if (entry.newObjectId() == ObjectId.NULL) {
// Feature was removed so we need to fill out blank attribute values
for (int index = 0; index < attributeLength; index++) {
response += ",";
}
} else {
// Feature was added or modified so we need to write out the
// attribute
// values from the feature
Optional<RevObject> feature = geogig.command(RevObjectParse.class).setObjectId(entry.newObjectId()).call();
RevFeature revFeature = (RevFeature) feature.get();
List<Optional<Object>> values = revFeature.getValues();
for (int index = 0; index < values.size(); index++) {
Optional<Object> value = values.get(index);
PropertyDescriptor attrib = (PropertyDescriptor) attribs.toArray()[index];
String stringValue = "";
if (value.isPresent()) {
FieldType attributeType = FieldType.forBinding(attrib.getType().getBinding());
switch(attributeType) {
case DATE:
stringValue = new SimpleDateFormat("MM/dd/yyyy z").format((java.sql.Date) value.get());
break;
case DATETIME:
stringValue = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format((Date) value.get());
break;
case TIME:
stringValue = new SimpleDateFormat("HH:mm:ss z").format((Time) value.get());
break;
case TIMESTAMP:
stringValue = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format((Timestamp) value.get());
break;
default:
stringValue = escapeCsv(value.get().toString());
}
response += "," + stringValue;
} else {
response += ",";
}
}
}
response += '\n';
out.write(response);
response = "";
}
}
} else {
// Couldn't resolve FeatureType
throw new CommandSpecException("Couldn't resolve the given path to a feature type.");
}
}
use of org.opengis.feature.type.PropertyDescriptor 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();
}
}
}
use of org.opengis.feature.type.PropertyDescriptor 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();
}
}
Aggregations