std::vector<time_t> *forWay(const Osmium::OSM::WayNodeList &nodes, time_t from, time_t to) {
        std::vector<time_t> *minor_times = new std::vector<time_t>();

        for(Osmium::OSM::WayNodeList::const_iterator nodeit = nodes.begin(); nodeit != nodes.end(); nodeit++) {
            osm_object_id_t id = nodeit->ref();

            bool found = false;
            Nodestore::timemap_ptr tmap = m_nodestore->lookup(id, found);
            if(!found) {
                continue;
            }

            Nodestore::timemap_cit lower = tmap->lower_bound(from);
            Nodestore::timemap_cit upper = to == 0 ? tmap->end() : tmap->upper_bound(to);
            for(Nodestore::timemap_cit it = lower; it != upper; it++) {
                /*
                 * lower_bound returns elements *not lower then* from, so it can return times == from
                 * this results in minor with timestamps and information equal to the original way
                 */
                if(it->first == from) continue;
                minor_times->push_back(it->first);
            }
        }

        std::sort(minor_times->begin(), minor_times->end());
        minor_times->erase(std::unique(minor_times->begin(), minor_times->end()), minor_times->end());

        return minor_times;
    }
Exemplo n.º 2
0
            void way(const shared_ptr<const OSM::Way> &way)
            {
                Osmium::OSM::TagList::const_iterator tagIt;
                for(tagIt = way->tags().begin();
                    tagIt != way->tags().end(); ++tagIt)
                {
                    std::string sKey(tagIt->key());
                    std::string sVal(tagIt->value());

                    if(sKey.compare("natural") == 0)   {
                        if(sVal.compare("coastline") == 0)   {

                            Osmium::OSM::WayNodeList::const_iterator nodeIt;
                            for(nodeIt = way->nodes().begin();
                                nodeIt != way->nodes().end(); ++nodeIt)
                            {
                                std::unordered_map<size_t,Node>::iterator findIt;
                                size_t findId = nodeIt->ref();
                                findIt = m_listNodes.find(findId);
                                if(findIt == m_listNodes.end())
                                {   return;   }     // way pointing to node not in data set

                                std::cout << std::fixed << std::setprecision(7)
                                          << findIt->second.lon << ","
                                          << std::fixed << std::setprecision(7)
                                          << findIt->second.lat << "," << 0 << "\n";
                            }
                        }
                    }
                }
            }
Exemplo n.º 3
0
 void way(const shared_ptr<Osmium::OSM::Way const>& way) const {
     m_output_stream << "way:\n";
     print_meta(way);
     m_output_stream << "  node_count=" << way->nodes().size() << "\n";
     m_output_stream << "  nodes:\n";
     Osmium::OSM::WayNodeList::const_iterator end = way->nodes().end();
     for (Osmium::OSM::WayNodeList::const_iterator it = way->nodes().begin(); it != end; ++it) {
         m_output_stream << "    ref=" << it->ref() << "\n";
     }
 }
Exemplo n.º 4
0
            inline double distance(const Osmium::OSM::WayNodeList& wnl) {
                double sum_length=0;

                if (wnl.size() < 2) {
                    return 0.0;
                }

                for (Osmium::OSM::WayNodeList::const_iterator it = wnl.begin(); it != wnl.end()-1; ++it) {
                    sum_length += Osmium::Geometry::Haversine::distance(it->position(), (it+1)->position());
                }

                return sum_length;
            }
Exemplo n.º 5
0
    geos::geom::Geometry* forWay(const Osmium::OSM::WayNodeList &nodes, time_t t, bool looksLikePolygon) {
        // shorthand to the geometry factory
        geos::geom::GeometryFactory *f = Osmium::Geometry::geos_geometry_factory();

        // pointer to coordinate vector
        std::vector<geos::geom::Coordinate> *c = new std::vector<geos::geom::Coordinate>();

        // iterate over all nodes
        Osmium::OSM::WayNodeList::const_iterator end = nodes.end();
        for(Osmium::OSM::WayNodeList::const_iterator it = nodes.begin(); it != end; ++it) {
            // the id
            osm_object_id_t id = it->ref();

            // was the node found in the store?
            bool found;
            Nodestore::Nodeinfo info = m_nodestore->lookup(id, t, found);

            // a missing node can just be skipped
            if(!found)
                continue;

            double lon = info.lon, lat = info.lat;

            if(m_debug) {
                std::cerr << "node #" << id << " at tstamp " << t << " references node at POINT(" << std::setprecision(8) << lon << ' ' << lat << ')' << std::endl;
            }

            // create a coordinate-object and add it to the vector
            if(!m_keepLatLng) {
                if(!Project::toMercator(&lon, &lat))
                    continue;
            }
            c->push_back(geos::geom::Coordinate(lon, lat, DoubleNotANumber));
        }

        // if less then 2 nodes could be found in the store, no valid way
        // can be assembled and we need to skip it
        if(c->size() < 2) {
            if(m_showerrors) {
                std::cerr << "found only " << c->size() << " valid coordinates, skipping way" << std::endl;
            }
            delete c;
            return NULL;
        }

        // the resulting geometry
        geos::geom::Geometry* geom;

        // geos throws exception on bad geometries and such
        try {
            // tags say it could be a polygon, the way is closed and has
            // at least 3 *different* coordinates
            if(looksLikePolygon && c->front() == c->back() && c->size() >= 4) {
                // build a polygon
                geom = f->createPolygon(
                    f->createLinearRing(
                        f->getCoordinateSequenceFactory()->create(c)
                    ),
                    NULL
                );
            } else {
                // build a linestring
                geom = f->createLineString(
                    f->getCoordinateSequenceFactory()->create(c)
                );
            }
        } catch(geos::util::GEOSException e) {
            if(m_showerrors) {
                std::cerr << "error creating polygon: " << e.what() << std::endl;
            }
            delete c;
            return NULL;
        }

        // enforce srid
        if(geom) {
            geom->setSRID(900913);
        }

        return geom;
    }