Search in sources :

Example 41 with Node

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();
}
Also used : WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) Location(org.openstreetmap.atlas.geography.Location)

Example 42 with Node

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());
    }
}
Also used : AtlasEntity(org.openstreetmap.atlas.geography.atlas.items.AtlasEntity) Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) Bound(org.openstreetmap.osmosis.core.domain.v0_6.Bound) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way)

Example 43 with Node

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);
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) JtsPointConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPointConverter) WKTReader(org.locationtech.jts.io.WKTReader) FileDataStore(org.geotools.data.FileDataStore) ComplexBoundary(org.openstreetmap.atlas.geography.atlas.items.complex.boundaries.ComplexBoundary) LoggerFactory(org.slf4j.LoggerFactory) GeometryPrecisionReducer(org.locationtech.jts.precision.GeometryPrecisionReducer) AtlasEntity(org.openstreetmap.atlas.geography.atlas.items.AtlasEntity) WKTWriter(org.locationtech.jts.io.WKTWriter) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Map(java.util.Map) GeoJsonType(org.openstreetmap.atlas.geography.geojson.GeoJsonType) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) FeatureIterator(org.geotools.feature.FeatureIterator) Feature(org.opengis.feature.Feature) WritableResource(org.openstreetmap.atlas.streaming.resource.WritableResource) ItemBoundable(org.locationtech.jts.index.strtree.ItemBoundable) Predicate(java.util.function.Predicate) Collection(java.util.Collection) CoreException(org.openstreetmap.atlas.exception.CoreException) Location(org.openstreetmap.atlas.geography.Location) Set(java.util.Set) Collectors(java.util.stream.Collectors) CountryCodeProperties(org.openstreetmap.atlas.geography.atlas.raw.slicing.CountryCodeProperties) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) Property(org.opengis.feature.Property) Objects(java.util.Objects) CountryListTwoWayStringConverter(org.openstreetmap.atlas.geography.boundary.converters.CountryListTwoWayStringConverter) List(java.util.List) AbstractNode(org.locationtech.jts.index.strtree.AbstractNode) Stream(java.util.stream.Stream) ParseException(org.locationtech.jts.io.ParseException) Polygon(org.locationtech.jts.geom.Polygon) Optional(java.util.Optional) Geometry(org.locationtech.jts.geom.Geometry) Distance(org.openstreetmap.atlas.utilities.scalars.Distance) Rectangle(org.openstreetmap.atlas.geography.Rectangle) STRtree(org.locationtech.jts.index.strtree.STRtree) IntStream(java.util.stream.IntStream) ComplexBoundaryFinder(org.openstreetmap.atlas.geography.atlas.items.complex.boundaries.ComplexBoundaryFinder) CountryBoundaryMapGeoJsonConverter(org.openstreetmap.atlas.geography.boundary.converters.CountryBoundaryMapGeoJsonConverter) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) HashMap(java.util.HashMap) Longitude(org.geotools.measure.Longitude) Supplier(java.util.function.Supplier) JtsMultiPolygonToMultiPolygonConverter(org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonToMultiPolygonConverter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) JtsPrecisionManager(org.openstreetmap.atlas.geography.converters.jts.JtsPrecisionManager) GeoJson(org.openstreetmap.atlas.geography.geojson.GeoJson) Lists(com.google.common.collect.Lists) StringTokenizer(java.util.StringTokenizer) GeometryItemDistance(org.locationtech.jts.index.strtree.GeometryItemDistance) OutputStreamWriter(java.io.OutputStreamWriter) JtsMultiPolygonConverter(org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter) MultiMap(org.openstreetmap.atlas.utilities.maps.MultiMap) Logger(org.slf4j.Logger) Resource(org.openstreetmap.atlas.streaming.resource.Resource) PolyLine(org.openstreetmap.atlas.geography.PolyLine) BufferedWriter(java.io.BufferedWriter) IOException(java.io.IOException) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) File(java.io.File) ISOCountryTag(org.openstreetmap.atlas.tags.ISOCountryTag) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) JtsPolyLineConverter(org.openstreetmap.atlas.geography.converters.jts.JtsPolyLineConverter) FileDataStoreFinder(org.geotools.data.FileDataStoreFinder) StringList(org.openstreetmap.atlas.utilities.collections.StringList) Collections(java.util.Collections) Envelope(org.locationtech.jts.geom.Envelope) ItemDistance(org.locationtech.jts.index.strtree.ItemDistance) StringList(org.openstreetmap.atlas.utilities.collections.StringList) CountryCodeProperties(org.openstreetmap.atlas.geography.atlas.raw.slicing.CountryCodeProperties) Envelope(org.locationtech.jts.geom.Envelope) CoreException(org.openstreetmap.atlas.exception.CoreException) ParseException(org.locationtech.jts.io.ParseException) IOException(java.io.IOException) Geometry(org.locationtech.jts.geom.Geometry) GeometryItemDistance(org.locationtech.jts.index.strtree.GeometryItemDistance) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) Polygon(org.locationtech.jts.geom.Polygon)

Example 44 with Node

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();
        }
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) TimestampType(org.voltdb.types.TimestampType) LineString(org.postgis.LineString) IOException(java.io.IOException) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 45 with Node

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);
}
Also used : EntityConverter(org.locationtech.geogig.osm.internal.EntityConverter) Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) EntityContainer(org.openstreetmap.osmosis.core.container.v0_6.EntityContainer) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) Envelope(com.vividsolutions.jts.geom.Envelope) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) Predicate(com.google.common.base.Predicate) NodeRef(org.locationtech.geogig.api.NodeRef) Function(com.google.common.base.Function) Bounded(org.locationtech.geogig.api.Bounded) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) Nullable(javax.annotation.Nullable) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Aggregations

Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)52 Test (org.junit.Test)27 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)26 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)21 Date (java.util.Date)18 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)17 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)16 Node (org.flyte.api.v1.Node)15 Test (org.junit.jupiter.api.Test)15 ArrayList (java.util.ArrayList)14 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)14 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)13 TaskNode (org.flyte.api.v1.TaskNode)10 Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)10 List (java.util.List)9 Map (java.util.Map)9 Node (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node)9 Node (org.openhab.binding.mqtt.homie.internal.homie300.Node)9 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)9 Node (ch.ethz.globis.phtree.v16.Node)8