inline void parseWay(const osmium::Way& way)
    {
        const auto& tags = way.tags();
        auto it = std::find_if(tags.begin(), tags.end(), highway_filter);
        if (it == tags.end())
        {
            return;
        }

        const osmium::NodeRef& first = way.nodes().front();
        const osmium::NodeRef& last = way.nodes().back();

        // filter out closed ways, generally this will just cause false
        // positives with round-a-abouts
        if (first == last)
        {
            return;
        }

        const char* name = tags.get_value_by_key("name", "");
        const char* ref = tags.get_value_by_key("ref", "");

        unsigned name_id = getStringID(name);
        unsigned ref_id = getStringID(ref);

        // we can't use osmium ids because MultiMap expects unsigned keys
        unsigned long firstID = static_cast<unsigned long>(first.ref());
        unsigned long lastID = static_cast<unsigned long>(last.ref());

        const unsigned wayIdx = parsed_ways->size();
        endpoint_way_map->unsorted_set(firstID, wayIdx);
        endpoint_way_map->unsorted_set(lastID,  wayIdx);

        parsed_ways->emplace_back(way.id(), firstID, lastID, name_id, ref_id);
    }
Exemplo n.º 2
0
    void create_single_way(const osmium::Way &way) {
        osmium::geom::OGRFactory<> ogr_factory;
        OGRLineString *linestring = nullptr;
        try {
            linestring = ogr_factory.create_linestring(way,
                         osmium::geom::use_nodes::unique,
                         osmium::geom::direction::forward).release();
        } catch (osmium::geometry_error) {
            insert_way_error(way);
            return;
        } catch (...) {
            cerr << "Error at way: " << way.id() << endl;
            cerr << "  Unexpected error" << endl;
            return;
        }

        try {
            ds.insert_way_feature(linestring, way, 0);
        } catch (osmium::geometry_error&) {
            cerr << "Inserting to table failed for way: "
                 << way.id() << endl;
        } catch (...) {
            cerr << "Inserting to table failed for way: "
                 << way.id() << endl;
            cerr << "  Unexpected error" << endl;
        }
        delete linestring;
    }
Exemplo n.º 3
0
                void way(const osmium::Way& way) {
                    *m_out += 'w';
                    write_meta(way);

                    *m_out += " N";

                    if (!way.nodes().empty()) {
                        auto it = way.nodes().begin();
                        if (m_options.locations_on_ways) {
                            write_field_ref(*it);
                            for (++it; it != way.nodes().end(); ++it) {
                                *m_out += ',';
                                write_field_ref(*it);
                            }
                        } else {
                            write_field_int('n', it->ref());
                            for (++it; it != way.nodes().end(); ++it) {
                                *m_out += ',';
                                write_field_int('n', it->ref());
                            }
                        }
                    }

                    *m_out += '\n';
                }
Exemplo n.º 4
0
 /**
  * Extract segments from given way and add them to the list.
  *
  * Segments connecting two nodes with the same location (ie
  * same node or different nodes with same location) are
  * removed after reporting the duplicate node.
  */
 uint32_t extract_segments_from_way(osmium::area::ProblemReporter* problem_reporter, const osmium::Way& way) {
     if (way.nodes().empty()) {
         return 0;
     }
     m_segments.reserve(way.nodes().size() - 1);
     return extract_segments_from_way_impl(problem_reporter, way, role_type::outer);
 }
Exemplo n.º 5
0
                uint32_t extract_segments_from_way_impl(osmium::area::ProblemReporter* problem_reporter, uint64_t& duplicate_nodes, const osmium::Way& way, role_type role) {
                    uint32_t invalid_locations = 0;

                    osmium::NodeRef previous_nr;
                    for (const osmium::NodeRef& nr : way.nodes()) {
                        if (!nr.location().valid()) {
                            ++invalid_locations;
                            if (problem_reporter) {
                                problem_reporter->report_invalid_location(way.id(), nr.ref());
                            }
                            continue;
                        }
                        if (previous_nr.location()) {
                            if (previous_nr.location() != nr.location()) {
                                m_segments.emplace_back(previous_nr, nr, role, &way);
                            } else {
                                ++duplicate_nodes;
                                if (problem_reporter) {
                                    problem_reporter->report_duplicate_node(previous_nr.ref(), nr.ref(), nr.location());
                                }
                            }
                        }
                        previous_nr = nr;
                    }

                    return invalid_locations;
                }
Exemplo n.º 6
0
 /***
  * Insert error node into nodes table: way contains of one
  * coordinate.
  */
 void insert_way_error(const osmium::Way &way) {
     ErrorSum *sum = new ErrorSum();
     sum->set_way_error();
     ds.insert_node_feature(way.nodes().begin()->location(),
                            way.nodes().begin()->ref(), sum);
     delete sum;
 }
Exemplo n.º 7
0
 polygon_type create_polygon(const osmium::Way& way, use_nodes un=use_nodes::unique, direction dir = direction::forward) {
     try {
         return create_polygon(way.nodes(), un, dir);
     } catch (osmium::geometry_error& e) {
         e.set_id("way", way.id());
         throw;
     }
 }
 void way(const osmium::Way& way) {
     try {
         gdalcpp::Feature feature{m_layer_linestring, m_factory.create_linestring(way)};
         feature.set_field("id", int32_t(way.id()));
         add_feature(feature, way);
     } catch (const osmium::geometry_error&) {
         std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n";
     }
 }
Exemplo n.º 9
0
        void way(const osmium::Way& way) {
            if (m_max_relation_id > 0) {
                throw std::runtime_error("Found a way after a relation.");
            }

            if (m_max_way_id >= way.id()) {
                throw std::runtime_error("Way IDs out of order.");
            }
            m_max_way_id = way.id();
        }
 // - walk over all way-versions
 //   - walk over all bboxes
 //     - if the way-id is recorded in the bboxes way-trackers
 //       - send the way to the bboxes writer
 void way(const osmium::Way& way) {
     if (debug) {
         std::cerr << "cut_administrative way " << way.id() << " v" << way.version() << "\n";
     }
     for (const auto& extract : info->extracts) {
         if (extract->way_tracker.get(way.id())){
             extract->write(way);
         }
     }
 }
Exemplo n.º 11
0
 void eway(extract_data& e, const osmium::Way& way) {
     for (const auto& nr : way.nodes()) {
         if (e.node_ids.get(nr.positive_ref())) {
             e.way_ids.set(way.positive_id());
             for (const auto& nr : way.nodes()) {
                 e.extra_node_ids.set(nr.ref());
             }
             return;
         }
     }
 }
Exemplo n.º 12
0
    // The way handler is called for each node in the input data.
    void way(const osmium::Way& way) {
        {
            osmium::builder::WayBuilder builder{m_buffer};
            copy_attributes(builder, way);
            copy_tags(builder, way.tags());

            // Copy the node list over to the new way.
            builder.add_item(way.nodes());
        }
        m_buffer.commit();
    }
Exemplo n.º 13
0
 void way(const osmium::Way& way) {
     ++ways;
     if (!matches_user_filter(way)) return;
     ++uways;
     for (const auto& node : way.nodes()) {
         m_nodefile <<
             way.id() << "\t" <<
             way.version() << "\t" <<
             node.ref() << std::endl;
     }
 }
 /**
  * This is called when a way is not in any multipolygon
  * relation.
  *
  * Overwritten from the base class.
  */
 void way_not_in_any_relation(const osmium::Way& way) {
     if (way.nodes().size() > 3 && way.ends_have_same_location()) {
         // way is closed and has enough nodes, build simple multipolygon
         try {
             TAssembler assembler(m_assembler_config);
             assembler(way, m_output_buffer);
             possibly_flush_output_buffer();
         } catch (osmium::invalid_location&) {
             // XXX ignore
         }
     }
 }
Exemplo n.º 15
0
void parse_osmium_t::way(osmium::Way& way)
{
    if (way.deleted()) {
        m_data->way_delete(way.id());
    } else {
        if (m_append) {
            m_data->way_modify(way);
        } else {
            m_data->way_add(way);
        }
    }
    m_stats.add_way(way.id());
}
Exemplo n.º 16
0
     void way(osmium::Way& w) {
          ++utak;
          osmium::WayNodeList& wnl = w.nodes();
          std::vector<osmium::unsigned_object_id_type> nds;

          for( osmium::NodeRef& n : wnl )
          {
               nds.emplace_back(n.ref());
          }

          way_node_map[w.id()] = nds;
          nds.clear();
     }
Exemplo n.º 17
0
            void way(const osmium::Way& way) {
                if (m_max_relation_id > std::numeric_limits<osmium::object_id_type>::min()) {
                    throw out_of_order_error{"Found a way after a relation.", way.id()};
                }

                if (m_max_way_id == way.id()) {
                    throw out_of_order_error{"Way ID twice in input. Maybe you are using a history or change file?", way.id()};
                }
                if (id_order{}(way.id(), m_max_way_id)) {
                    throw out_of_order_error{"Way IDs out of order.", way.id()};
                }
                m_max_way_id = way.id();
            }
Exemplo n.º 18
0
  double getNodeDistance(osmium::Way& w)
  {
    const char* way = w.tags() ["highway"];
    const char* maxspeed = w.tags() ["maxspeed"];
    double nodeDistance;
                                                                        // std::cout<<way<<std::endl;
    if(!maxspeed)
    {
    if(!strcmp (way, "primary")
    || !strcmp (way, "secondary")
    || !strcmp (way,"tertiary")
    || !strcmp (way, "unclassified")
    || !strcmp (way ,"road")
    || !strcmp (way, "primary_link")  
    || !strcmp (way, "secondary_link"))
    {
      maxspeed = "90";
    }

    if(!strcmp(way,"trunk")
    || !strcmp(way,"trunk_link"))
    {
      maxspeed = "110";
    }

    if(!strcmp(way, "motorway"))
    {
      maxspeed = "130";
    }

    if(!strcmp (way, "residential")
    || !strcmp (way, "track"))
    {
      maxspeed = "50";
    }
    
    if(!strcmp (way, "platform")
    || !strcmp (way, "service")
    || !strcmp (way, "path")
    || !strcmp (way, "living_street"))
    {
      maxspeed = "20";
    }
       }
       else
        maxspeed = "30";

      nodeDistance = atoi(maxspeed) * 0.2 / 3.6;
    return nodeDistance;
  }
 // - walk over all way-versions
 //   - walk over all bboxes
 //     - if the way-id is recorded in the bboxes way-trackers
 //       - send the way to the bboxes writer
 void way(const osmium::Way& way) {
     if (debug) {
         std::cerr << "cut_administrative way " << way.id() << " v" << way.version() << "\n";
     }
     for (const auto& extract : info->extracts) {
         if (extract->way_tracker.get(way.id())){
             for (const auto& node_ref : way.nodes()) {
                 if (!extract->node_tracker.get(node_ref.ref())) {
                     extract->node_tracker.set(node_ref.ref());
                 }
             }
         }
     }
 }
Exemplo n.º 20
0
 // Many pubs are mapped as a way (often tagged as building=yes too).
 // Potentially a pub could be mapped as just building=pub - but this is exceedingly rare, so it is not tested here
 void way(const osmium::Way& way) {
     const char* amenity = way.tags().get_value_by_key("amenity");
     if (amenity && !strcmp(amenity, "pub")) {
         // For such buildings one may want to confirm the way is closed before doing more processing eg:
         //if (!way.is_closed()) {
         //  return;
         //}
         // However for just listing names, the above check is not really necessary
         const char* name = way.tags().get_value_by_key("name");
         if (name) {
             std::cout << name << std::endl;
         }
     }
 }
Exemplo n.º 21
0
 /***
  * Iterate through all nodes of waterways in pass 3 if way is coastline
  * or riverbank. Otherwise iterate just through the nodes between
  * firstnode and lastnode.
  */
 void way(const osmium::Way& way) {
     if (is_valid(way)) {
         if (check_all_nodes(way)) {
             for (auto node : way.nodes()) {
                 check_node(node);
             }
         } else {
             if (way.nodes().size() > 2) {
                 for (auto node = way.nodes().begin() + 1;
                         node != way.nodes().end() - 1; ++node) {
                     check_node(*node);
                 }
             }
         }
     }
 }
Exemplo n.º 22
0
int osmdata_t::way_modify(osmium::Way const &way)
{
    idlist_t nodes(way.nodes());
    slim_middle_t *slim = dynamic_cast<slim_middle_t *>(mid.get());

    slim->ways_delete(way.id());
    slim->ways_set(way);

    int status = 0;
    for (auto& out: outs) {
        status |= out->way_modify(way);
    }

    slim->way_changed(way.id());

    return status;
}
Exemplo n.º 23
0
    void way(const osmium::Way& way) {
        // detect a new way
        if (current_way_id != 0 && current_way_id != way.positive_id()) {
            write_way_extra_nodes();
            current_way_nodes.clear();
        }
        current_way_id = way.positive_id();

        if (debug) {
            std::cerr << "softcut way " << way.positive_id() << " v" << way.version() << "\n";
        }

        for (const auto& node_ref : way.nodes()) {
            current_way_nodes.insert(node_ref.positive_ref());
        }

        for (const auto& extract : info->extracts) {
            for (const auto& node_ref : way.nodes()) {
                if (extract->node_tracker.get(node_ref.positive_ref())) {
                    if (debug) {
                        std::cerr << "way has a node (" << node_ref.positive_ref() << ") inside extract, recording in way_tracker\n";
                    }
                    extract->way_tracker.set(way.positive_id());
                    break;
                }
            }
        }
    }
Exemplo n.º 24
0
void output_pgsql_t::pgsql_out_way(osmium::Way const &way, taglist_t *tags,
                                   bool polygon, bool roads)
{
    if (polygon && way.is_closed()) {
        auto wkb = m_builder.get_wkb_polygon(way);
        if (!wkb.empty()) {
            expire.from_wkb(wkb.c_str(), way.id());
            if (m_enable_way_area) {
                char tmp[32];
                auto const area =
                    m_options.reproject_area
                        ? ewkb::parser_t(wkb).get_area<reprojection>(
                              m_options.projection.get())
                        : ewkb::parser_t(wkb)
                              .get_area<osmium::geom::IdentityProjection>();
                snprintf(tmp, sizeof(tmp), "%g", area);
                tags->push_override(tag_t("way_area", tmp));
            }
            m_tables[t_poly]->write_row(way.id(), *tags, wkb);
        }
    } else {
        double const split_at = m_options.projection->target_latlon() ? 1 : 100 * 1000;
        for (auto const &wkb : m_builder.get_wkb_line(way.nodes(), split_at)) {
            expire.from_wkb(wkb.c_str(), way.id());
            m_tables[t_line]->write_row(way.id(), *tags, wkb);
            if (roads) {
                m_tables[t_roads]->write_row(way.id(), *tags, wkb);
            }
        }

    }
}
Exemplo n.º 25
0
 /**
  * Add way to collection. A new CoastlineRing will be created for the way
  * or it will be joined to an existing CoastlineRing.
  */
 void add_way(const osmium::Way& way) {
     m_ways++;
     if (way.is_closed()) {
         m_rings_from_single_way++;
         m_list.push_back(std::make_shared<CoastlineRing>(way));
     } else {
         add_partial_ring(way);
     }
 }
Exemplo n.º 26
0
 /**
  * Extract segments from given way and add them to the list.
  *
  * Segments connecting two nodes with the same location (ie same
  * node or different node with same location) are removed.
  *
  * XXX should two nodes with same location be reported?
  */
 void extract_segments_from_way(const osmium::Way& way, const char* role) {
     osmium::NodeRef last_nr;
     for (const osmium::NodeRef& nr : way.nodes()) {
         if (last_nr.location() && last_nr.location() != nr.location()) {
             m_segments.emplace_back(last_nr, nr, role, &way);
         }
         last_nr = nr;
     }
 }
Exemplo n.º 27
0
    void way(const osmium::Way& way) {
        try {
            std::unique_ptr<OGRLineString> ogr_linestring = m_ogr_factory.create_linestring(way);
            OGRFeature* feature = OGRFeature::CreateFeature(m_layer_linestring->GetLayerDefn());
            feature->SetGeometry(ogr_linestring.get());
            feature->SetField("id", static_cast<double>(way.id()));
            feature->SetField("type", way.tags().get_value_by_key("type"));

            if (m_layer_linestring->CreateFeature(feature) != OGRERR_NONE) {
                std::cerr << "Failed to create feature.\n";
                exit(1);
            }

            OGRFeature::DestroyFeature(feature);
        } catch (osmium::geometry_error&) {
            std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n";
        }
    }
void CreateGraph::way(const osmium::Way& way)
{
  const char* highway = way.get_value_by_key("highway");
  if (!highway || !strcmp(highway, "footway"))
  {
    return;
  }

  vertex_type u = -1;
  for (const auto& node_ref : way.nodes())
  {
    node_id_map_type::iterator pos;
    bool inserted;
    boost::tie(pos, inserted) = node_id_map.emplace(node_ref.positive_ref(), vertex_type());

    if (inserted)
    {
      double x = osmium::geom::detail::lon_to_x(node_ref.lon());
      double y = osmium::geom::detail::lat_to_y(node_ref.lat());
      Location loc(x, y);

      pos->second = boost::add_vertex(vertex_property(loc), graph);
    }

    const vertex_type v = pos->second;

    if (u+1)
    {
      const char* street_name = way.get_value_by_key("name", "");

      const Location& a = boost::get(boost::vertex_name, graph, u);
      const Location& b = boost::get(boost::vertex_name, graph, v);
      const double length = dist(a, b);

      edge_property prop;
      boost::get_property_value(prop, boost::edge_name) = street_name;
      boost::get_property_value(prop, boost::edge_weight) = length;

      boost::add_edge(u, v, prop, graph);
    }

    u = v;
  }
}
Exemplo n.º 29
0
 /**
  * This is called when a way is not in any multipolygon
  * relation.
  *
  * Overwritten from the base class.
  */
 void way_not_in_any_relation(const osmium::Way& way) {
     // you need at least 4 nodes to make up a polygon
     if (way.nodes().size() <= 3) {
         return;
     }
     try {
         if (!way.nodes().front().location() || !way.nodes().back().location()) {
             throw osmium::invalid_location("invalid location");
         }
         if (way.ends_have_same_location()) {
             // way is closed and has enough nodes, build simple multipolygon
             TAssembler assembler(m_assembler_config);
             assembler(way, m_output_buffer);
             possibly_flush_output_buffer();
         }
     } catch (osmium::invalid_location&) {
         // XXX ignore
     }
 }
 /**
  * This is called when a way is not in any multipolygon
  * relation.
  */
 void way_not_in_any_relation(const osmium::Way& way) {
     // you need at least 4 nodes to make up a polygon
     if (way.nodes().size() <= 3) {
         return;
     }
     try {
         if (!way.nodes().front().location() || !way.nodes().back().location()) {
             throw osmium::invalid_location{"invalid location"};
         }
         if (way.ends_have_same_location()) {
             // way is closed and has enough nodes, build simple multipolygon
             TAssembler assembler{m_assembler_config};
             assembler(way, this->buffer());
             m_stats += assembler.stats();
         }
     } catch (const osmium::invalid_location&) {
         // XXX ignore
     }
 }