use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project atlas by osmlab.
the class OsmPbfReader method processNode.
/**
* Uses the {@link Node} OSM identifier, geometry and tags to create an Atlas {@link Point}.
*
* @param entity
* The {@link Entity} that will become an Atlas {@link Point}
*/
private void processNode(final Entity entity) {
final Node node = (Node) entity;
this.builder.addPoint(padIdentifier(node.getId()), new Location(Latitude.degrees(node.getLatitude()), Longitude.degrees(node.getLongitude())), populateEntityTags(node));
this.statistics.recordCreatedPoint();
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project atlas by osmlab.
the class OsmPbfReader method process.
@Override
public void process(final EntityContainer entityContainer) {
final Entity rawEntity = entityContainer.getEntity();
if (shouldProcessEntity(this.loadingOption, rawEntity)) {
if (rawEntity instanceof Node && this.nodeIdentifiersToInclude.contains(rawEntity.getId())) {
processNode(rawEntity);
} else if (rawEntity instanceof Way && this.wayIdentifiersToInclude.contains(rawEntity.getId())) {
processWay(rawEntity);
} else if (this.loadingOption.isLoadOsmRelation() && rawEntity instanceof Relation) {
processRelation(rawEntity);
} else if (rawEntity instanceof Bound) {
logger.trace("Encountered PBF Bound {}, skipping over it.", rawEntity.getId());
}
} else {
recordNodeIdentifiersFromFilteredEntity(rawEntity);
logFilteredStatistics(rawEntity);
logger.trace("Filtering out OSM {} {} from Raw Atlas", rawEntity.getType(), rawEntity.getId());
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project atlas by osmlab.
the class CountryBoundaryMap method getCountryCodeISO3.
/**
* @param geometry
* The {@link Geometry} which we're assigning a country code to
* @param fastMode
* In fast mode, we only return the first country hit, so if a node is right on the
* border, we'll only return one country code
* @param buffer
* The buffer distance of geometry, please note that if the geometry is 0 dimension
* then a envelope expend is used instead of a rounding buffer
* @return the resulting {@link CountryCodeProperties}
*/
public CountryCodeProperties getCountryCodeISO3(final Geometry geometry, final boolean fastMode, final double buffer) {
StringList countryList = new StringList();
final Geometry target;
if (geometry.getDimension() == 0) {
final Envelope envelope = geometry.getEnvelopeInternal();
envelope.expandBy(buffer);
target = geometry.getFactory().toGeometry(envelope);
} else {
target = geometry.buffer(buffer);
}
final List<Polygon> polygons = this.query(target.getEnvelopeInternal()).stream().filter(polygon -> polygon.intersects(target)).collect(Collectors.toList());
boolean usingNearestNeighbor = false;
if (polygons.size() == 1 || isSameCountry(polygons)) {
countryList.add(getGeometryProperty(polygons.get(0), ISOCountryTag.KEY));
} else {
try {
if (fastMode) {
final Optional<String> match = polygons.stream().filter(polygon -> polygon.intersects(target)).map(polygon -> getGeometryProperty(polygon, ISOCountryTag.KEY)).findFirst();
match.ifPresent(countryList::add);
} else {
countryList = new StringList(polygons.stream().filter(polygon -> polygon.intersects(target)).map(polygon -> getGeometryProperty(polygon, ISOCountryTag.KEY)).collect(Collectors.toList()));
}
if (countryList.isEmpty()) {
// The node isn't within any country boundary - try to assign the iso_code
// based on the nearest country
final Geometry nearestGeometry = nearestNeighbour(target.getEnvelopeInternal(), target, new GeometryItemDistance());
if (nearestGeometry != null) {
usingNearestNeighbor = true;
final String nearestCountryCode = getGeometryProperty(nearestGeometry, ISOCountryTag.KEY);
countryList.add(nearestCountryCode);
} else {
countryList.add(ISOCountryTag.COUNTRY_MISSING);
}
}
} catch (final Exception e) {
logger.warn("There was exception when trying to find out country code for geometry {}, {}", geometry, e.getMessage());
countryList.add(ISOCountryTag.COUNTRY_MISSING);
}
}
return new CountryCodeProperties(this.countryListConverter.backwardConvert(countryList), usingNearestNeighbor);
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node 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 com.marcnuri.yakc.model.io.k8s.api.core.v1.Node 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);
}
Aggregations