Exemplo n.º 1
0
    /***
     * Iterate through members. Create linestrings of each. First as GEOS
     * linestring to union them later. Then as ORG linestring to insert
     * them into table ways.
     */
    void create_ways(const osmium::Relation &relation,
                     const osmium::object_id_type relation_id,
                     bool &contains_nowaterway_ways,
                     vector<geos::geom::Geometry *> *linestrings) {
        
        for (auto& member : relation.members()) {
            if (member_is_valid(member)) {
                const osmium::Way& way = way_from(member);
                linestring_type *linestr = nullptr;
                try {
                    linestr = osmium_geos_factory.create_linestring(way,
                            osmium::geom::use_nodes::unique,
                            osmium::geom::direction::forward).release();
                } catch (osmium::geometry_error) {
                    insert_way_error(way);
                    continue;
                } catch (...) {
                    cerr << "Error at way: " << way.id() << endl;
                    cerr << "  Unexpected error" << endl;
                    continue;
                }
                if (linestr) {
                    linestrings->push_back(linestr);
                } else {
                    continue;
                }

                if (TagCheck::has_waterway_tag(way)) {
                    contains_nowaterway_ways = true;
                }

                OGRGeometry *ogr_linestring = nullptr;
                ogr_linestring = geos2ogr(linestr);

                try {
                    ds.insert_way_feature(ogr_linestring, way, relation_id);
                } 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;
                }
                OGRGeometryFactory::destroyGeometry(ogr_linestring);
            }
        }
    }