use of org.mozilla.jss.asn1.Tag in project voltdb by VoltDB.
the class VoltDBOsmSink method process.
public void process(WayContainer wayContainer) {
Way way;
List<Long> nodeIds;
way = wayContainer.getEntity();
nodeIds = new ArrayList<Long>(way.getWayNodes().size());
for (WayNode wayNode : way.getWayNodes()) {
nodeIds.add(wayNode.getNodeId());
}
// Keep invalid ways out of the database if desired by the user
if (way.getWayNodes().size() > 1 || keepInvalidWays) {
for (Tag tag : way.getTags()) {
try {
client.callProcedure(new InsertCallback(), INS_WAY_TAGS_PROC, way.getId(), tag.getKey(), tag.getValue());
} catch (NoConnectionsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
// Add these to the ways_nodes_table;
int sequence = 0;
for (Long nodeId : nodeIds) {
try {
client.callProcedure(new InsertCallback(), INS_WAYS_NODES_PROC, way.getId(), nodeId, sequence);
} catch (NoConnectionsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
sequence++;
}
StringBuffer sb = new StringBuffer();
// if the first node id == the last nodeId, we know that this is a
// closed loop.
long n0 = nodeIds.get(0);
long nn = nodeIds.get(nodeIds.size() - 1);
if (n0 == nn) {
if (enableBboxBuilder) {
Polygon pg = wayGeometryBuilder.createPolygon(way);
pg.outerWKT(sb);
}
} else {
// it's a lineString, but we don't support it yet.
if (enableLinestringBuilder) {
LineString lineString = wayGeometryBuilder.createWayLinestring(way);
lineString.outerWKT(sb);
} else {
return;
}
}
String bbox = sb.toString();
try {
client.callProcedure(new InsertCallback(), INS_WAYS_PROC, way.getId(), way.getVersion(), way.getUser().getId(), way.getTimestamp(), way.getChangesetId(), bbox);
} catch (NoConnectionsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of org.mozilla.jss.asn1.Tag in project GeoGig by boundlessgeo.
the class OSMUnmapOp method unmapWay.
private void unmapWay(SimpleFeature feature, FeatureMapFlusher flusher) {
boolean modified = false;
String id = feature.getID();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(OSMUtils.wayType());
Optional<RevFeature> rawFeature = command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + OSMUtils.WAY_TYPE_NAME + "/" + id).call(RevFeature.class);
Map<String, String> tagsMap = Maps.newHashMap();
long timestamp = System.currentTimeMillis();
int version = 1;
long changeset = -1;
String user = UNKNOWN_USER;
Collection<Tag> tags = Lists.newArrayList();
if (rawFeature.isPresent()) {
ImmutableList<Optional<Object>> values = rawFeature.get().getValues();
tags = OSMUtils.buildTagsCollectionFromString(values.get(WAY_TAGS_FIELD_INDEX).get().toString());
for (Tag tag : tags) {
tagsMap.put(tag.getKey(), tag.getValue());
}
Optional<Object> timestampOpt = values.get(WAY_TIMESTAMP_FIELD_INDEX);
if (timestampOpt.isPresent()) {
timestamp = ((Long) timestampOpt.get()).longValue();
}
Optional<Object> versionOpt = values.get(WAY_VERSION_FIELD_INDEX);
if (versionOpt.isPresent()) {
version = ((Integer) versionOpt.get()).intValue();
}
Optional<Object> changesetOpt = values.get(WAY_CHANGESET_FIELD_INDEX);
if (changesetOpt.isPresent()) {
changeset = ((Long) changesetOpt.get()).longValue();
}
Optional<Object> userOpt = values.get(WAY_USER_FIELD_INDEX);
if (userOpt.isPresent()) {
user = (String) userOpt.get();
}
}
Map<String, String> unaliased = Maps.newHashMap();
Collection<Property> properties = feature.getProperties();
for (Property property : properties) {
String name = property.getName().getLocalPart();
if (name.equals("id") || name.equals("nodes") || Geometry.class.isAssignableFrom(property.getDescriptor().getType().getBinding())) {
continue;
}
Object value = property.getValue();
if (value != null) {
String tagName = name;
if (mapping != null) {
if (unaliased.containsKey(name)) {
tagName = unaliased.get(name);
} else {
tagName = mapping.getTagNameFromAlias(path, tagName);
unaliased.put(name, tagName);
}
}
if (!DefaultField.isDefaultField(tagName)) {
if (tagsMap.containsKey(tagName)) {
if (!modified) {
String oldValue = tagsMap.get(tagName);
modified = !value.equals(oldValue);
}
} else {
modified = true;
}
tagsMap.put(tagName, value.toString());
}
}
}
if (!modified && rawFeature.isPresent()) {
// no changes after unmapping tags, so there's nothing else to do
return;
}
tags.clear();
Set<Entry<String, String>> entries = tagsMap.entrySet();
for (Entry<String, String> entry : entries) {
tags.add(new Tag(entry.getKey(), entry.getValue()));
}
Geometry geom = (Geometry) feature.getDefaultGeometry();
LineString line;
if (geom instanceof LineString) {
line = (LineString) geom;
} else {
line = gf.createLineString(geom.getCoordinates());
}
featureBuilder.set("visible", true);
featureBuilder.set("tags", OSMUtils.buildTagsString(tags));
featureBuilder.set("way", line);
featureBuilder.set("changeset", changeset);
featureBuilder.set("timestamp", timestamp);
featureBuilder.set("version", version);
featureBuilder.set("user", user);
featureBuilder.set("nodes", getNodeStringFromWay(feature, flusher));
if (rawFeature.isPresent()) {
// the feature has changed, so we cannot reuse some attributes
featureBuilder.set("timestamp", System.currentTimeMillis());
// temporary negative changeset ID
featureBuilder.set("changeset", -changeset);
// featureBuilder.set("version", version);
flusher.put("way", featureBuilder.buildFeature(id));
} else {
flusher.put("way", featureBuilder.buildFeature(id));
}
}
use of org.mozilla.jss.asn1.Tag in project GeoGig by boundlessgeo.
the class MappingRule method apply.
/**
* Returns the feature resulting from transforming a given feature using this rule. This method
* takes a collection of tags, so there is no need to compute them from the 'tags' attribute.
* This is meant as a faster alternative to the apply(Feature) method, in case the mapping
* object calling this has already computed the tags, to avoid recomputing them
*
* @param feature
* @param tags
* @return
*/
public Optional<Feature> apply(Feature feature, Collection<Tag> tags) {
if (!canBeApplied(feature, tags)) {
return Optional.absent();
}
for (AttributeDescriptor attribute : getFeatureType().getAttributeDescriptors()) {
String attrName = attribute.getName().toString();
Class<?> clazz = attribute.getType().getBinding();
if (Geometry.class.isAssignableFrom(clazz)) {
Geometry geom = prepareGeometry((Geometry) feature.getDefaultGeometryProperty().getValue());
if (geom == null) {
return Optional.absent();
}
featureBuilder.set(attrName, geom);
} else {
Object value = null;
for (Tag tag : tags) {
if (fields.containsKey(tag.getKey())) {
if (fields.get(tag.getKey()).getName().equals(attrName)) {
FieldType type = FieldType.forBinding(clazz);
value = getAttributeValue(tag.getValue(), type);
break;
}
}
}
featureBuilder.set(attribute.getName(), value);
}
}
String id = feature.getIdentifier().getID();
featureBuilder.set("id", id);
if (defaultFields != null) {
for (DefaultField df : defaultFields) {
featureBuilder.set(df.name(), feature.getProperty(df.name()).getValue());
}
}
if (!featureType.getGeometryDescriptor().getType().getBinding().equals(Point.class)) {
featureBuilder.set("nodes", feature.getProperty("nodes").getValue());
}
return Optional.of((Feature) featureBuilder.buildFeature(id));
}
use of org.mozilla.jss.asn1.Tag in project GeoGig by boundlessgeo.
the class EntityConverter method toEntity.
/**
* Converts a Feature to a OSM Entity
*
* @param feature the feature to convert
* @param replaceId. The changesetId to use in case the feature has a negative one indicating a
* temporary value
* @return
*/
public Entity toEntity(SimpleFeature feature, Long changesetId) {
Entity entity;
SimpleFeatureType type = feature.getFeatureType();
long id = Long.parseLong(feature.getID());
int version = ((Integer) feature.getAttribute("version")).intValue();
Long changeset = (Long) feature.getAttribute("changeset");
if (changesetId != null && changeset < 0) {
changeset = changesetId;
}
Long milis = (Long) feature.getAttribute("timestamp");
Date timestamp = new Date(milis);
String user = (String) feature.getAttribute("user");
String[] userTokens = user.split(":");
OsmUser osmuser;
try {
osmuser = new OsmUser(Integer.parseInt(userTokens[1]), userTokens[0]);
} catch (Exception e) {
osmuser = OsmUser.NONE;
}
String tagsString = (String) feature.getAttribute("tags");
Collection<Tag> tags = OSMUtils.buildTagsCollectionFromString(tagsString);
CommonEntityData entityData = new CommonEntityData(id, version, timestamp, osmuser, changeset, tags);
if (type.equals(OSMUtils.nodeType())) {
Point pt = (Point) feature.getDefaultGeometryProperty().getValue();
entity = new Node(entityData, pt.getY(), pt.getX());
} else {
List<WayNode> nodes = Lists.newArrayList();
String nodesString = (String) feature.getAttribute("nodes");
for (String s : nodesString.split(";")) {
nodes.add(new WayNode(Long.parseLong(s)));
}
entity = new Way(entityData, nodes);
}
return entity;
}
use of org.mozilla.jss.asn1.Tag in project GeoGig by boundlessgeo.
the class OSMUtils method buildTagsString.
/**
* @param collection
* @return
*/
@Nullable
public static String buildTagsString(Collection<Tag> collection) {
if (collection.isEmpty()) {
return null;
}
StringBuilder sb = new StringBuilder();
for (Iterator<Tag> it = collection.iterator(); it.hasNext(); ) {
Tag e = it.next();
String key = e.getKey();
if (key == null || key.isEmpty()) {
continue;
}
String value = e.getValue();
sb.append(key).append(':').append(value);
if (it.hasNext()) {
sb.append('|');
}
}
return sb.toString();
}
Aggregations