use of org.openstreetmap.osmosis.core.domain.v0_6.OsmUser 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;
}
Aggregations