vvoovv / blosm

Blosm addon for Blender. A few clicks import of Google 3D cities, OpenStreetMap, terrain. Global coverage. Source code is in the branch 'release'.
1.55k stars 183 forks source link

[Feature Request] Downloading administratory borders #230

Open Mi-Pe opened 3 years ago

Mi-Pe commented 3 years ago

[Feature Request] Hello! Is it possible to download administratory borders with this plugin? I mean city, municipality, district, land, voivodeship etc. borders. If not, could it be added in the future as an option? They are normally available from OSM.

vvoovv commented 3 years ago

Did you mean if it's possible to display the borders in Blender?

Mi-Pe commented 3 years ago

Yes, I mean get them from OSM and display as an object, like roads, lands, buildings etc. :)

vvoovv commented 3 years ago

I need more time to think about it. There are some tricky issues.

Mi-Pe commented 3 years ago

I can wait if there is a chance you can add it :D

Mi-Pe commented 3 years ago

Perhaps you could use BlenderGIS source code as an example because the author already implemented this feature. Still, I prefer your addon because it lets me import far larger area and is technically not problematic, while I had issues with BlenderGIS.

vvoovv commented 3 years ago

I can wait if there is a chance you can add it :D

I hope so.

vvoovv commented 3 years ago

You mentioned voivodeships... Here they are:

image

Details will follow.

Mi-Pe commented 3 years ago

Looks cool! I'm mostly interested in cities, districts and municipalities/ counties.

vvoovv commented 3 years ago

I'm mostly interested in cities, districts and municipalities/ counties.

In Poland?

Mi-Pe commented 3 years ago

Yes, in Poland mainly but I thought it could be done as a universal feature that future users from all round the world will be able to use. I don't want to waste your time for simply getting some piece of data for me. I'd prefer "a rod than a fish", as they say ;)

Ok, only now I realized that each country has probably its own system for administratory borders in OSM. But I think there is a common definition of all administratory borders for the entire world, called "boundaries: administrative". I'm referring to this resource: wiki.openstreetmap.org/wiki/Map_Features "An administrative boundary. Subdivisions of areas/territories/jurisdictions recognised by governments or other organisations for administrative purposes. These range from large groups of nation states right down to small administrative districts and suburbs, as indicated by the 'admin_level=*' combo tag. "

vvoovv commented 3 years ago

I am ready to describe the solution. It requires a manual download of OSM data. But I think it isn't that difficult.

vvoovv commented 3 years ago

Download and install the latest version (2.4.28 or above) of the addon.

Switch to the 3D simple mode in the addon panel

Uncheck all OpenStreetMap "layers" (buildings, roads, water, etc) since they aren't available in the OSM data sets to be downloaded.

Set the value of the Import from option to file.

Uncheck the option Import as a single object.

Download the setup script base_borders.py and set the path to it in the field Setup script.

Note that the default geographical projection used by the addon (transverse Mercator) is good to import cities, towns and other inhabited dwellings. Administrative borders may span a huge area and a different geographical projection might be appropriate for you case. See here how to use a custom geographical projection with the Blender-OSM addon.

vvoovv commented 3 years ago

Administrative borders are typically mapped with the tags boundary=administrative and admin_level. It's importand to understand them. It's also important to know which admin_level is appropriate for you case.

Many administrative borders are also mapped with the tag place. For some cities, towns and other inhabited dwellings it's the only tag used to mark the their borders.

vvoovv commented 3 years ago

Polish administrative border will be used as an example.

Poland is divided into a number of voivodeship (an equivalent of province). Each voivodeship is divided into a number of counties.

vvoovv commented 3 years ago

Task 1. Import administrative boundaries of all polish voivodeships (provinces).

First we need to get the OpenStreetMap id of the country border of Poland. It's needed to limit the query within Poland.

Type Poland in the search box at osm.org and press Enter. Find the entry for the country boundary of Poland in the search result list and press it. You should see the text Relation: Poland (49715) on the left top corner of the resulting page with the address https://www.openstreetmap.org/relation/49715.

49715 is the OpenStreetMap id of the country border of Poland. It will be needed in the next step.

Open the page http://overpass-turbo.eu.

Paste the text request to the field on the left side:

[out:xml];
relation(area:3600000000)["boundary"="administrative"]["admin_level"="4"];
(._;>;);
out meta;

Note that admin_level=4 is used for the borders of provinces.

Replace the number 3600000000 for the sum of 3600000000 and the boundaries id. In our example the boundaries id is 49715, then the sum would be 3600049715 and the resulting request would be

[out:xml];
relation(area:3600049715)["boundary"="administrative"]["admin_level"="4"];
(._;>;);
out meta;

Now execute the resulting request. Press Export -> Data -> raw data directly from Overpass API -> done

Save the file with the extension .osm.

Now you can import the file into Blender with the help of Blender-OSM addon.

vvoovv commented 3 years ago

Task 2. Import administrative boundaries of a specific polish voivodeship (province)

Lublin Voivodeship will be used as an example.

The borders can be queried by the value of the OpenStreetMap tag name. Type Lublin Voivodeship in the search box at osm.org and press Enter. Find the entry for the state boundary of Lublin Voivodeship and press it. Find a row for the tag name in the table Tags in the resulting page https://www.openstreetmap.org/relation/130919.

The value of the tag name is województwo lubelskie. It will be needed in the next step.

Open the page http://overpass-turbo.eu.

Paste the text request to the field on the left side:

[out:xml];
relation["boundary"="administrative"]["admin_level"="4"]["name"="województwo lubelskie"];
(._;>;);
out meta;

Note that admin_level=4 is used for the borders of provinces.

Now execute the resulting request. Press Export -> Data -> raw data directly from Overpass API -> done

Save the file with the extension .osm.

Now you can import the file into Blender with the help of Blender-OSM addon.

vvoovv commented 3 years ago

Task 3. Import administrative boundaries of all counties within a specific polish voivodeship (province)

Borders of all counties within Lublin Voivodeship will be imported in the example below.

First we need to get the OpenStreetMap id of the state border of Lublin Voivodeship. It's needed to limit the query within Lublin Voivodeship.

Type Lublin Voivodeship in the search box at osm.org and press Enter. Find the entry for the state boundary of Lublin Voivodeship and press it. You should see the text Relation: Lublin Voivodeship (130919) on the left top corner of the resulting page with the address https://www.openstreetmap.org/relation/130919.

130919 is the OpenStreetMap id of the state border of Lublin Voivodeship. It will be needed in the next step.

Open the page http://overpass-turbo.eu.

Paste the text request to the field on the left side:

[out:xml];
relation(area:3600000000)["boundary"="administrative"]["admin_level"="6"];
(._;>;);
out meta;

Note that admin_level=6 is used for the borders of counties.

Replace the number 3600000000 for the sum of 3600000000 and the boundaries id. In our example the boundaries id is 130919, then the sum would be 3600130919 and the resulting request would be

[out:xml];
relation(area:3600130919)["boundary"="administrative"]["admin_level"="6"];
(._;>;);
out meta;

Now execute the resulting request. Press Export -> Data -> raw data directly from Overpass API -> done

Save the file with the extension .osm.

Now you can import the file into Blender with the help of Blender-OSM addon.

vvoovv commented 3 years ago

Task 4. Import of the borders of New York City

If the name of a city is unique in the world, its borders can be simply queried by the value of the OpenStreetMap tag name.

Open the page http://overpass-turbo.eu.

Paste the text request to the field on the left side:

[out:xml];
relation["place"="city"]["name"="New York"];
(._;>;);
out meta;

Now execute the resulting request. Press Export -> Data -> raw data directly from Overpass API -> done

Save the file with the extension .osm.

Now you can import the file into Blender with the help of Blender-OSM addon.

Mi-Pe commented 3 years ago

Thank you for the instructions but I didn't succeed. I downloaded the "Raw data directly from Overpass API" and it got saved as a file without extension. I added ".osm" extension and tried to import it after setting your addon as you instructed but I'm getting this error:

" Traceback (most recent call last): File "C:\Users\Dell\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\blender-osm__init.py", line 188, in execute return self.importOsm(context) File "C:\Users\Dell\AppData\Roaming\Blender Foundation\Blender\2.90\scripts\addons\blender-osm\init__.py", line 282, in importOsm self.setCenterLatLon(context, osm.lat, osm.lon) AttributeError: 'Osm' object has no attribute 'lat'

location: :-1 "

Well, I'm still seeking for a simple way of downloading boundaries as just another layer next to: buildings, water objects, forests etc. Perfectly, one would just select an area as we always do to get all layers, and one of these layers would be boundaries - be it city, county, provice, country or any other type of boundary, that will fall into selected area. Would you consider implementing such workflow, or the one you described, into the core of your plugin?

Mi-Pe commented 3 years ago

What does this error mean? Did I make a typo mistake when querying data from overpass-turbo.eu? I don't think so because the site itself would throw an error but it didn't.

vvoovv commented 3 years ago

It could be a bug. Could you please send me the code of your resulting request for overpass-turbo.eu? You could send it to prokitektura@gmail.com if you don't want to expose some private information.

vvoovv commented 3 years ago

Well, I'm still seeking for a simple way of downloading boundaries as just another layer next to: buildings, water objects, forests etc. Perfectly, one would just select an area as we always do to get all layers, and one of these layers would be boundaries - be it city, county, provice, country or any other type of boundary, that will fall into selected area. Would you consider implementing such workflow, or the one you described, into the core of your plugin?

If you think the needed borders are contained in your OSM data set, set the Setup script to _baseborders.py in the 3D simple mode and that's it.

The problem is that Blender can't handle millions of buildings located even in a middle size country or province. That's why the borders for larger areas (e.g. countries, provinces) should be downloaded separately.

Mi-Pe commented 3 years ago

If you think the needed borders are contained in your OSM data set, set the Setup script to base_borders.py in the 3D simple mode and that's it.

Amazing! This is exactly what I needed! Could you implement this little script to the core of your plugin so that we can download boundaries just as easily as buildings?

I also got rid of error with overpass-turbo.eu method. Had to be my typo or something.

vvoovv commented 3 years ago

There was no big demand for that feature so far. So I'd prefer to leave it for the custom setup script.

Mi-Pe commented 3 years ago

Sure, I understand. Anyway, thank you very much. You helped me a lot!