use of org.mozilla.jss.asn1.Tag in project OSMWrangle by SLIPO-EU.
the class OsmPbfParser method process.
/**
* Processes an OSM element (node, way, or relation).
* @param entityContainer Container of an OSM node, way, or relation.
*/
@Override
public void process(EntityContainer entityContainer) {
// Will become true only if a tag related to user-specified filters is found for the current OSM element
keepIndexed = false;
if ((!scanWays) && (!scanRelations) && (entityContainer instanceof NodeContainer)) {
// Create a new OSM node object and populate it with the appropriate values
// Mark position of the parser
inNode = true;
inWay = false;
inRelation = false;
numNodes++;
Node myNode = ((NodeContainer) entityContainer).getEntity();
nodeTmp = new OSMNode();
nodeTmp.setID("" + myNode.getId());
// Collect tags associated with this OSM element
for (Tag myTag : myNode.getTags()) {
nodeTmp.setTagKeyValue(myTag.getKey(), myChecker.removeIllegalChars(myTag.getValue()));
if ((tags == null) || (tags.contains(myTag.getKey()))) {
// CAUTION! Filter out any OSM elements not related to tags specified by the user
// In case of no tags specified for filtering, index all nodes
keepIndexed = true;
}
}
// Create geometry object with original WGS84 coordinates
Geometry geom = geometryFactory.createPoint(new Coordinate(myNode.getLongitude(), myNode.getLatitude()));
nodeTmp.setGeometry(geom);
// Convert entity
if (keepIndexed) {
if (keepUnnamed)
myConverter.parse(recBuilder.createOSMRecord(nodeTmp), classification, reproject, targetSRID);
else if (nodeTmp.getTagKeyValue().containsKey("name")) {
// CAUTION! Only named entities will be transformed
myConverter.parse(recBuilder.createOSMRecord(nodeTmp), classification, reproject, targetSRID);
numNamedEntities++;
}
}
if (recBuilder.nodeIndex.containsKey(nodeTmp.getID()))
// Keep a dictionary of node geometries, only if referenced by OSM ways
recBuilder.nodeIndex.put(nodeTmp.getID(), nodeTmp.getGeometry());
nodeTmp = null;
} else if ((!scanRelations) && (entityContainer instanceof WayContainer)) {
// Create a new OSM way object and populate it with the appropriate values
Way myWay = ((WayContainer) entityContainer).getEntity();
for (Tag myTag : myWay.getTags()) {
if ((tags == null) || (tags.contains(myTag.getKey()))) {
// CAUTION! Filter out any OSM elements not related to tags specified by the user
// In case of no tags specified for filtering, index all ways
keepIndexed = true;
break;
}
}
if (scanWays) {
// Either this OSM way is filtered or referenced by a relation, so its nodes should be kept in the index
if ((keepIndexed) || (recBuilder.wayIndex.containsKey("" + myWay.getId()))) {
for (WayNode entry : myWay.getWayNodes()) {
// ...initially with NULL geometry, to be replaced once nodes will be parsed
recBuilder.nodeIndex.put("" + entry.getNodeId(), null);
}
}
} else {
if (inNode)
System.out.println("\nFinished parsing OSM nodes.");
// Mark position of the parser
inNode = false;
inWay = true;
inRelation = false;
numWays++;
// Skip parsing if this way is filtered out or not referenced by other relations
if ((!keepIndexed) && (!recBuilder.wayIndex.containsKey("" + myWay.getId())))
return;
wayTmp = new OSMWay();
wayTmp.setID("" + myWay.getId());
// Collect tags associated with this OSM element
for (Tag myTag : myWay.getTags()) {
wayTmp.setTagKeyValue(myTag.getKey(), myChecker.removeIllegalChars(myTag.getValue()));
}
for (WayNode entry : myWay.getWayNodes()) {
if (recBuilder.nodeIndex.containsKey("" + entry.getNodeId())) {
// get the geometry of the node with ID=entry
Geometry geometry = recBuilder.nodeIndex.get("" + entry.getNodeId());
// add the node geometry in this way
wayTmp.addNodeGeometry(geometry);
} else
System.out.println("Missing node " + entry.getNodeId() + " in referencing way " + wayTmp.getID());
}
Geometry geom = geometryFactory.buildGeometry(wayTmp.getNodeGeometries());
// These nodes must be more than 3, because JTS does not allow construction of a linear ring with less than 3 points
if ((closedRings2Polygons) && (wayTmp.getNodeGeometries().size() > 3) && wayTmp.getNodeGeometries().get(0).equals(wayTmp.getNodeGeometries().get(wayTmp.getNodeGeometries().size() - 1))) {
// Always construct a polygon when a linear ring is detected
LinearRing linear = geometryFactory.createLinearRing(geom.getCoordinates());
Polygon poly = new Polygon(linear, null, geometryFactory);
wayTmp.setGeometry(poly);
/**
***********************************************
* //OPTION NOT USED: Construct a linear ring geometry when this feature is either a barrier or a road
* if (!((wayTmp.getTagKeyValue().containsKey("barrier")) || wayTmp.getTagKeyValue().containsKey("highway"))){
* //this is not a barrier nor a road, so construct a polygon geometry
*
* LinearRing linear = geometryFactory.createLinearRing(geom.getCoordinates());
* Polygon poly = new Polygon(linear, null, geometryFactory);
* wayTmp.setGeometry(poly);
* }
* else { //it is either a barrier or a road, so construct a linear ring geometry
* LinearRing linear = geometryFactory.createLinearRing(geom.getCoordinates());
* wayTmp.setGeometry(linear);
* }
*************************************************
*/
} else if (wayTmp.getNodeGeometries().size() > 1) {
// it is an open geometry with more than one nodes, make it linestring
LineString lineString = geometryFactory.createLineString(geom.getCoordinates());
wayTmp.setGeometry(lineString);
} else {
// we assume that any other geometries are points
// some ways happen to have only one point. Construct a Point.
Point point = geometryFactory.createPoint(geom.getCoordinate());
wayTmp.setGeometry(point);
}
// Convert this entity
if (keepIndexed) {
if (keepUnnamed)
myConverter.parse(recBuilder.createOSMRecord(wayTmp), classification, reproject, targetSRID);
else if (wayTmp.getTagKeyValue().containsKey("name")) {
// CAUTION! Only named entities will be transformed
myConverter.parse(recBuilder.createOSMRecord(wayTmp), classification, reproject, targetSRID);
numNamedEntities++;
}
}
if (recBuilder.wayIndex.containsKey(wayTmp.getID()))
// Keep a dictionary of way geometries, only for those referenced by OSM relations
recBuilder.wayIndex.put(wayTmp.getID(), wayTmp.getGeometry());
wayTmp = null;
}
} else if ((!scanWays) && (entityContainer instanceof RelationContainer)) {
// Create a new OSM relation object and populate it with the appropriate values
Relation myRelation = ((RelationContainer) entityContainer).getEntity();
for (Tag myTag : myRelation.getTags()) {
if ((tags == null) || (tags.contains(myTag.getKey()))) {
// CAUTION! Filter out any OSM elements not related to tags specified by the user
// In case of no tags specified for filtering, index all nodes
keepIndexed = true;
break;
}
}
if (scanRelations) {
// Either only filtered relations will be indexed or those referenced by other relations
if ((keepIndexed) || (recBuilder.relationIndex.containsKey("" + myRelation.getId()))) {
for (RelationMember m : myRelation.getMembers()) {
if (m.getMemberType().name().equalsIgnoreCase("node"))
// This node is referenced by a relation; keep it in the index, and its geometry will be filled in when parsing the nodes
recBuilder.nodeIndex.put("" + m.getMemberId(), null);
else if (m.getMemberType().name().equalsIgnoreCase("way"))
// This way is referenced by a relation; keep it in the index, and its geometry will be filled in when parsing the ways
recBuilder.wayIndex.put("" + m.getMemberId(), null);
else if (m.getMemberType().name().equalsIgnoreCase("relation")) {
// This relation is referenced by another relation; keep it in the index, and its geometry will be filled in when parsing the relations
recBuilder.relationIndex.put("" + m.getMemberId(), null);
// Relations need to be scanned once more, as they reference other relations
rescanRelations = true;
}
}
}
} else {
if (inWay)
System.out.println("\nFinished parsing OSM ways.");
// Mark position of the parser
inNode = false;
inWay = false;
inRelation = true;
numRelations++;
// Skip parsing if this relation is filtered out or not referenced by others
if ((!keepIndexed) && (!recBuilder.relationIndex.containsKey("" + myRelation.getId())))
return;
relationTmp = new OSMRelation();
relationTmp.setID("" + myRelation.getId());
// Collect tags associated with this OSM element
for (Tag myTag : myRelation.getTags()) {
relationTmp.setTagKeyValue(myTag.getKey(), myChecker.removeIllegalChars(myTag.getValue()));
}
// System.out.println("Relation " + myRelation.getId() + " Number of members: " + myRelation.getMembers().size());
for (RelationMember m : myRelation.getMembers()) relationTmp.addMemberReference("" + m.getMemberId(), m.getMemberType().name(), m.getMemberRole());
OSMRecord rec = recBuilder.createOSMRecord(relationTmp);
if (// No records created for incomplete relations during the first pass
rec != null) {
// Convert entity
if (keepIndexed) {
if (keepUnnamed)
myConverter.parse(rec, classification, reproject, targetSRID);
else if (relationTmp.getTagKeyValue().containsKey("name")) {
// CAUTION! Only named entities will be transformed
myConverter.parse(rec, classification, reproject, targetSRID);
numNamedEntities++;
}
}
if (recBuilder.relationIndex.containsKey(relationTmp.getID()))
// Keep a dictionary of relation geometries, only for those referenced by other OSM relations
recBuilder.relationIndex.put(relationTmp.getID(), rec.getGeometry());
}
relationTmp = null;
}
}
}
use of org.mozilla.jss.asn1.Tag in project voltdb by VoltDB.
the class VoltDBOsmSink method process.
/**
* {@inheritDoc}
*/
public void process(RelationContainer relationContainer) {
Relation relation;
int memberSequenceId;
relation = relationContainer.getEntity();
try {
client.callProcedure(new InsertCallback(), INS_RELATIONS_PROC, relation.getId(), relation.getVersion(), relation.getUser().getId(), relation.getTimestamp(), relation.getChangesetId());
} catch (NoConnectionsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
memberSequenceId = 0;
for (RelationMember member : relation.getMembers()) {
try {
client.callProcedure(new InsertCallback(), INS_RELATIONS_MEMBER_PROC, relation.getId(), member.getMemberId(), member.getMemberType().ordinal(), member.getMemberRole(), memberSequenceId);
} catch (NoConnectionsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
memberSequenceId++;
}
for (Tag tag : relation.getTags()) {
try {
client.callProcedure(new InsertCallback(), INS_RELATION_TAGS_PROC, relation.getId(), tag.getKey(), tag.getValue());
} catch (NoConnectionsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of org.mozilla.jss.asn1.Tag in project voltdb by VoltDB.
the class VoltDBOsmSink method process.
public void process(NodeContainer nodeContainer) {
Node node;
node = nodeContainer.getEntity();
double lat = node.getLatitude();
double lng = node.getLongitude();
String pointText = "POINT(" + lng + " " + lat + ")";
// keep track of the nodes so we can build polygons later
if (enableBboxBuilder || enableLinestringBuilder) {
wayGeometryBuilder.addNodeLocation(node);
}
try {
client.callProcedure(new InsertCallback(), INS_NODE_PROC, node.getId(), node.getVersion(), node.getUser().getId(), new TimestampType(node.getTimestamp().getTime()), node.getChangesetId(), pointText);
} catch (NoConnectionsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Collection<Tag> tags = node.getTags();
for (Tag tag : tags) {
// System.out.println(INS_NODE_TAG_PROC+","+node.getId()+","+tag.getKey()+","+tag.getValue());
try {
client.callProcedure(new InsertCallback(), INS_NODE_TAG_PROC, node.getId(), tag.getKey(), tag.getValue());
} 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 unmapNode.
private void unmapNode(SimpleFeature feature, FeatureMapFlusher mapFlusher) {
boolean modified = false;
String id = feature.getID();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(OSMUtils.nodeType());
Optional<RevFeature> rawFeature = command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + OSMUtils.NODE_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(NODE_TAGS_FIELD_INDEX).get().toString());
for (Tag tag : tags) {
tagsMap.put(tag.getKey(), tag.getValue());
}
Optional<Object> timestampOpt = values.get(NODE_TIMESTAMP_FIELD_INDEX);
if (timestampOpt.isPresent()) {
timestamp = ((Long) timestampOpt.get()).longValue();
}
Optional<Object> versionOpt = values.get(NODE_VERSION_FIELD_INDEX);
if (versionOpt.isPresent()) {
version = ((Integer) versionOpt.get()).intValue();
}
Optional<Object> changesetOpt = values.get(NODE_CHANGESET_FIELD_INDEX);
if (changesetOpt.isPresent()) {
changeset = ((Long) changesetOpt.get()).longValue();
}
Optional<Object> userOpt = values.get(NODE_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") || 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;
}
Collection<Tag> newTags = Lists.newArrayList();
Set<Entry<String, String>> entries = tagsMap.entrySet();
for (Entry<String, String> entry : entries) {
newTags.add(new Tag(entry.getKey(), entry.getValue()));
}
featureBuilder.set("tags", OSMUtils.buildTagsString(newTags));
featureBuilder.set("location", feature.getDefaultGeometry());
featureBuilder.set("changeset", changeset);
featureBuilder.set("timestamp", timestamp);
featureBuilder.set("version", version);
featureBuilder.set("user", user);
featureBuilder.set("visible", true);
if (rawFeature.isPresent()) {
// the feature has changed, so we cannot reuse some attributes.
// We reconstruct the feature and insert it
featureBuilder.set("timestamp", System.currentTimeMillis());
featureBuilder.set("changeset", null);
featureBuilder.set("version", null);
featureBuilder.set("visible", true);
mapFlusher.put("node", featureBuilder.buildFeature(id));
} else {
// The feature didn't exist, so we have to add it
mapFlusher.put("node", featureBuilder.buildFeature(id));
}
}
use of org.mozilla.jss.asn1.Tag in project GeoGig by boundlessgeo.
the class MappingRule method hasCorrectTags.
private boolean hasCorrectTags(Feature feature, Collection<Tag> tags) {
if (filter.isEmpty() || (filter.size() == 1 && filter.containsKey("geom")) && (exclude == null || exclude.isEmpty())) {
return true;
}
boolean ret = false;
ArrayList<String> tagNames = Lists.newArrayList();
for (Tag tag : tags) {
tagNames.add(tag.getKey());
if (exclude != null && exclude.keySet().contains(tag.getKey())) {
List<String> values = exclude.get(tag.getKey());
if (values != null) {
if (values.isEmpty() || values.contains(tag.getValue())) {
return false;
}
}
}
if (filter.keySet().contains(tag.getKey())) {
List<String> values = filter.get(tag.getKey());
if (values.isEmpty() || values.contains(tag.getValue())) {
ret = true;
}
}
}
if (ret) {
for (String mandatory : getMandatoryTags()) {
if (!tagNames.contains(mandatory)) {
return false;
}
}
}
return ret;
}
Aggregations