-
Notifications
You must be signed in to change notification settings - Fork 819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rework admin boundaries and admin labels on lower zooms #1938
Conversation
A general remark here: While this is an understandable approach in principle it is important to also keep in mind the likely negative consequences:
Specific suggestions:
|
In general I like z4 with just the country borders. I suppose USA label should be visible if not the broken geometry you mentioned. However why Australia is different on that zoom level from the rest of the world (sub-country borders are visible)? |
<<: *osm2pgsql | ||
table: |- | ||
(SELECT | ||
ST_Simplify(way, !scale_denominator!/4500) as way, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be sqrt(!pixel_width!*!pixel_height!)*...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the idea is to make the amount of simplifications independent of the rendering resolution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this, I'm not sure what way works best.
Does this work appropriately when generating high resolution images?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I don't know, but if using pixel dimensions is the more common approach I'm happy to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on rationale for simplifying.
I'd probably do the line SQL something like this for lines
|
If you're returning |
re SQL: seems I was thinking a bit to complicated when it came to separating the less costly parts from the more expensive ones, thanks @pnorman
I don't disagree with your arguments, but waiting for the perfect solution, when the problem has been there for years already is also not desirable IMO. But of course the maintainers are free to delay or decline this, if they think there will be better solutions. Also, anybody with more expertise is free to step forward.
I have now switched to bevel joins for all boundaries. Maybe better anyway since it helps to avoid something like this:
I decided against including it as there would be too many changes, but it is on my list.
Sub-national entities should be displayed, but in the last two planet extracts I obtained China was not in the polygon table, same with Russia.
While Australia is a bit smaller than Brazil (which I have selected as cut-off country) according to https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_area it is either the sea boundaries or the projection or both that distorts the ranking. If I query the database for the biggest countries (way_area) I get the following list from the data upon which the previews are based (smallest on top): "Brasil";9.29986e+12 You see that China and Russia are missing, USA is too small because only Alaska made it into the table and also Greenland is in the list because it extends into low latitudes. I personally have no problem with Australia getting sub-national entities on z4. We would have to hardcode names or (if we would have hstore) iso codes otherwise, but that would be getting close to country specific renderings, which I wanted to avoid. |
@pnorman I cannot quite follow your last remark, can you point me towards some examples or documentation about it? |
https://github.com/mapnik/mapnik/wiki/PostGIS#bbox-token An outer filter on way will be unable to use indexes because the way returned by the query is computed, and there's no suitable indexes |
How's this going to work in countries with multiple disjoint areas like the US or Russia? |
I'll read up on it. Next good point raised. Currently it would work only for those parts which exceed the threshold. So e.g. the overseas territories that belong to the USA would not get sub-entities if they have some. Alaska has none at z4 anyway. I'm not familiar with the structure of the Russian Federation so I'm not sure if this would be a problem. |
This is not what i am suggesting. But introducing an approach that can definitely not be recommended to other map designers in the vague hope that someone will some time in the future come up with something better is equally not desirable IMO. I consider my objection essentially to be in line with what @gravitystorm told me when i made my first suggestion to deal with the Antarctic ice sheet in #646 (comment) - this essentially amounts to the demand that a solution should offer a certain level of applicability beyond the precise situation it is used in. Please don't view this as a blanket criticism of your work here - this is an interesting approach to the problem - but it seems it only works given the very special circumstances here, i.e. rendering as polygons, styling with fairly thick lines and using the trick in https://github.com/gravitystorm/openstreetmap-carto/blob/master/admin.mss#L56 Beyond these general remarks it also occurred to me that since you apply ST_Simplify up to z10 this change would seriously affect mapper feedback by showing a modified geometry at scales where the difference is already going to be clearly visible, like here: http://www.openstreetmap.org/#map=10/69.6781/30.6299
None of the Russian arctic islands is a separate level 4 entity i think, neither is the western hemisphere part. Labeling however is probably an issue (i.e Alaska etc. would not get a correct label) But admin unit labeling is already a complete mess anyway so this will probably hardly be noticeable. |
Looks clean and much more organized than the current rendering! My suggestions: |
I'm actually not quite attached to the simplification. I see the main improvements with the labels, line styles and also with removing subnational units from z4. We could also leave out the simplification, but the map would still look quite ugly.
I see the problem, that's why I wrote: "exponential decline of tolerance parameter when using ST_simplify". Still have to think about it, input welcome. Please do not expect too much out of this PR. At this stage I'm not going to add more features, it is more likely that some changes are removed.
Might be a good idea, but I only want to do that when we render something to replace them (e.g. those labels).
I'm not sure, will have to test this. |
I would drop the simplification. It adds complexity, and I'm not certain the results are what we really want. We can look at it independently. I wouldn't worry much about z0-z1. The use-cases for that are extremely limited, and it's always going to be a bad map at such a low zoom thanks to Mercator. I am still concerned about complexity, but it might be okay with those changes. |
sent from a phone
I did this on my own rendering but switched to a small shapefile because of phantasy continents popping up from time to time. |
@sommerluk I also made a quick list of low zoom levels based on French style few months ago, maybe there are things we could use. |
Rendering false continents is a good idea. At least if a fix in the database is rerendered faster than once a month (current render cycle on low zoom) |
I have removed the controversial simplification. |
…ry subdivisions only for the biggest countries on z4
I haven't had time to look at it yet. |
The cartography looks fine. I'm checking into some z3/z4 performance issues with a whole planet DB. |
FROM planet_osm_polygon o | ||
WHERE boundary = 'administrative' | ||
AND (admin_level IN ('0', '1', '2') | ||
OR (admin_level IN ('3', '4') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
admin level 0, 1, and 3 labels will disappear on zooming in. I suggest only doing 2 and 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I missed that.
This helps significantly with the use of appropriate partial indexes
This avoids getting it wrong in cases of highly-concave regions.
Did the PR nebulon42#1 to fix some issues. There's still an admin 0,1,2,3,4 vs 2,4 mismatch to be fixed, but I think that's the last of the technical issues. When those are fixed, I'm okay with it. We're adding more layers, but I'm okay with that. It comes with our choices about how to handle layers. The admin 4 in large admin 2 logic is a bit annoying to have to add, but it's not a complexity cost we're imposing on others. Most styles will use Natural Earth and special case iso_code2='USA' and a couple of other large places. |
Add additional SQL condition for very low admin logic
Thanks @pnorman. I have addressed the remaining issues. |
Thanks @nebulon42. I haven't studied the code in detail, but the output certainly looks much better. |
I used the index |
rework admin boundaries and admin labels on lower zooms
Is there a reason to keep the #necountries layer and shapefile, or would we be able to get rid of this and render the low-level admin borders based on osm-data? |
I think it would be great to replace the Natural Earth data with OSM data. But this would need generalization and should be done with a shapefile since Douglas-Peucker (ST_Simplify) was not well-received. This would need some logic similar to coastline processing and could be hosted on openstreetmapdata.com (?), but someone would need to provide the update and error logic. |
We don't use dashed lines at the even lower zooms, so the issues with dashes don't apply here. But we can handle this in a new issue. |
Yes, we should do that. But I think at least @imagico's concerns were not mainly about dashes. |
Is it just me, or is zoom level 4 not being properly updated with the new rendering on the openstreetmap.org servers? Is this a glitch on the servers or in the stylesheet? |
I had to revert this pull request, since it was bringing the OSMF servers to a halt (see the revert PR #1987 ). This is the query that had been running for more than 14 hours for one request: openstreetmap-carto/project.yaml Lines 1322 to 1342 in 7b8998c
I suspect this needs to be tested further with databases containing more representative data - it appears the query runs fine when there's a small amount of boundary-only data, but not when the tables contain lots of non-boundary data too. I think @pnorman is making some investigations regarding the query and the behaviour of the query planner. |
The shapefile layer changes which were positive on their own could be restored independently by the way. |
One of the longest queries was SELECT ST_AsBinary("way") AS geom,"admin_level" FROM (SELECT
way,
admin_level
FROM planet_osm_roads o
WHERE boundary = 'administrative'
AND (admin_level IN ('0', '1', '2')
OR (admin_level IN ('3', '4')
AND EXISTS
(SELECT 1
FROM planet_osm_polygon i
WHERE boundary = 'administrative'
AND admin_level = '2'
AND way_area > 9e+12
AND ST_Within(o.way, i.way)
AND osm_id < 0
)
)
)
AND osm_id < 0
ORDER BY admin_level DESC
) AS admin_very_low_zoom WHERE "way" && ST_SetSRID('BOX3D(-1252344.271424999 -1252344.271424999,20037508 20037508)'::box3d, 900913); This is the z4 query, which gets z2 admin or z4 admin in large z2. The query plan on one of the servers was http://explain.depesz.com/s/VgNj The query plan is moderately stupid, involving a bitmap and of a 20GB gist and 5GB btree index for the subplan, and isn't great for the roads part of the plan, though indexes are smaller there. |
Running on my server with only standard indexes, I get http://explain.depesz.com/s/laJE 30 minute query time isn't great, but there are only 4 z4 metatiles, and this is the big one that covers most of Europe. The query on production with the different plan was running for >14h before terminated. |
Is that a server with full planet loaded? |
Yes. My setup has a few differences
Since the query takes >14h to run on production, I'm not going to get any selectivity estimates to see why it's doing the BitmapAnd plan or if it's a good plan, but my instincts are telling me it's a horrible plan. My inclination is to fix this through #207, because a suitable partial index brings query times down into the 1 minute range, and even an ill-suited one is way better. |
Oh dear, I will provide a new PR with just the style updates as I think these are worthwhile to have in also without the new logic on z4. |
Fixes #907, #1571.
Adresses part of #622 (the part that is similar to #907, #1571)
Changes are concerned with reduction of complexity and better rendering of country/state labels as well as boundary lines, especially in maintaining a visual hierarchy of admin levels 2,3,4.
Details:
simplification of admin lines starting at z4 usingST_simplify
with a initial tolerance of ~ 7800 and decreasing linearly with scale denominator until the layer no longer gets rendered at z10way_area
factor of 9000000000000, which should only include Russia, Canada, China (?), United States of America, Brazil, Australia and Greenland (only if their country geometries are correct and therefore in the polygon table)Problems:
usage of ST_simplify is not undisputed (see borders at zoom 4-6 #907), but I think it is a usable possibility until we have something betterperformance of SQL query deciding if subnational entities should be rendered on z4 seems suboptimalfixed, thanks @pnorman, @imagicopossible Improvements:
exponential decline of tolerance parameter when using ST_simplify - if somebody wants to experiment with itPreviews (only after the changes, available data: admin entities incl. names and place names [city, town]):
z1
z2
z3
z4
Europe
Africa
Americas
unfortunately the USA geometry seems to be broken, but see this other screenshot in #907 (comment).
Oceania/Asia
z5 (from here roads are missing)
z6
Testing:
If you need test data you can download it from [link no longer active]. This file contains global admin boundaries of level 2,3,4 as well as place nodes of cities and towns. Some country geometries like France, Belgium ... and unfortunately also the US are broken so their name (and sub-national entities at z4 in case of US) won't appear.