NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hi,

I have to extract all street names with all boundaries that its belong to. I found webpage https://osm-boundaries.com/ where you can select a lot of boundaries. eg. Germany -> Baden-Wurttemberg -> Regierungsbezirk -> Freiburg im Breisgau -> Altstadt -> Altstadt-Mitte Now im in the point that i can extract all street names (Type=Way, contain tag highway, contain name) Is it possible to extract all boundary names for each street ?

asked 29 Dec '20, 12:42

HubDac's gravatar image

HubDac
11112
accept rate: 0%

Using OsmSharp i wrote some code but it seems to not working as i expected :( But i dont know why :(

The funniest part is that there are some relations that eg.

<waynode> <city/> <name>Otto-Reutter-Straße</name> <type>residential</type> <areas> <arearelation> <nodeid>430112483</nodeid> <name>Dotzheim</name> <type>boundary</type> <boundary>administrative</boundary> <adminlevel>9</adminlevel> </arearelation> <arearelation> <nodeid>430112483</nodeid> <name>Schierstein</name> <type>boundary</type> <boundary>administrative</boundary> <adminlevel>9</adminlevel> </arearelation> </areas> </waynode>

but i most cases (output xml contains 16.868.559 lines of text) Ways(count 3.369.198) are not connected in Relation(count 2.818) whole file contain: Nodes: 331.798.468 Ways: 54.132.981 Relations: 666.231 and i dont use Node's at all at current implementation.

using (var fileStream = File.OpenRead(@".\germany-latest.osm.pbf"))
        {
            // create source stream.
            var source = new PBFOsmStreamSource(fileStream);

            var relationNodes = source
                .Where(w => 
                    w.Type == OsmGeoType.Relation
                    && w.Tags.ContainsKey("boundary")
                    && w.Tags.ContainsKey("admin_level"))
                .SelectMany(s => (s as Relation)?.Members
                            .Where(wm => wm.Type == OsmGeoType.Way)
                            .Select(sm => new AreaRelation()
                            {
                                NodeId = sm.Id,
                                Name = s.Tags.GetValue("name"),
                                Type = s.Tags.GetValue("type"),
                                Boundary = s.Tags.GetValue("boundary"),
                                AdminLevel = s.Tags.GetValue("admin_level")
                            })
                            .OrderBy(o => o.AdminLevel))
                .ToList();

            var relationNodesGroupedByNodeId = relationNodes.GroupBy(k => k.NodeId, v => v).ToDictionary(k => k.Key, v => v);

            var wayNodes = source
                .Where(w =>
                    w.Type == OsmGeoType.Way
                    && w.Tags.ContainsKey("highway")
                    && w.Tags.ContainsKey("name"))
                .Select(s =>
                    new WayNode()
                    {
                        City = s.Tags.GetValue("is_in:city"),
                        Name = s.Tags.GetValue("name"),
                        Type = s.Tags.GetValue("highway"),
                        Areas = (s.Id.HasValue && relationNodesGroupedByNodeId.ContainsKey(s.Id.Value)) 
                            ? relationNodesGroupedByNodeId[s.Id.Value].ToList() 
                            : null
                    })
                .Distinct().ToList();

            XmlSerializer x = new XmlSerializer(wayNodes.GetType());

            var path = @".\GermanyWays2.xml";
            FileStream file = System.IO.File.Create(path);

            x.Serialize(file, wayNodes);
            file.Close();
}
(30 Dec '20, 08:09) HubDac
1

What are you actually trying to accomplish?

(30 Dec '20, 13:39) InsertUser

I have to extract all streets for Germany with their administration bouderies. So if street is in Berlin i have to get street name and collection of areas e.g. level 2: Germany level 4: Berlin level 9: Mitte level 10: Moabit (i took areas names and leves from www.osm-boundaries.com)

(04 Jan '21, 08:05) HubDac

When I have a relation that includes the tags "boundary" and "admin_level", do the members of that relationship form a polygon? and everything inside that polygon should basically be treated as if it had these markers?

EDIT

I also noticed that there are relation members of type "Node" with Id that does not exists. The Id of node from relation member does not exists as id of any Node :(

permanent link

answered 30 Dec '20, 09:34

HubDac's gravatar image

HubDac
11112
accept rate: 0%

edited 30 Dec '20, 10:42

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×129
×111
×92
×12

question asked: 29 Dec '20, 12:42

question was seen: 2,257 times

last updated: 04 Jan '21, 08:05

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum