stamen / terrain-classic

World-wide CartoCSS port of Stamen's classic terrain style
ISC License
144 stars 35 forks source link

add Admin 1 labels #16

Closed clhenrick closed 8 years ago

clhenrick commented 9 years ago

Seems like we should be able to easily port these from Toner? Though perhaps it depends on how we address the dymo placement of labels (ref #4) screen shot 2015-08-27 at 11 27 10 am

clhenrick commented 8 years ago

We should include admin1 labels for the rest of the world where they are available from Natural Earth.

clhenrick commented 8 years ago

Admin1 labels also show up along borders: screen shot 2015-09-01 at 10 03 14 am

clhenrick commented 8 years ago

@almccon @mojodna perhaps we can take a similar approach to the solution for city labels? Instead of using Aries data we could create centroids from natural earth admin1 data for global coverage and let Mapnik do the rendering. Let me know what you think.

clhenrick commented 8 years ago

I'm running into an issue when attempting to render centroids from ne_10m_admin1_states_provinces polygons; simply creating centroids will create multiple points for every polygon that is part of a state / province when we probably want only one that is in a central location and contained inside the largest polygon for a given state / province.

Thinking there must be a way to do this with SQL but haven't figured it out yet.

almccon commented 8 years ago

Try the label points file from Natural Earth? http://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-cultural-building-blocks/

clhenrick commented 8 years ago

I checked it out and it's like they took the regular states / provinces polygon file and did ST_Centroid on it, so lots of duplicate points.

almccon commented 8 years ago

Bummer. Although, did you check to see if there's a scalerank column or something similar? They might have left those duplicate points in there for use when you're really zoomed in, but NE generally is pretty good at letting you filter out irrelevant stuff if you want a zoomed-out map.

clhenrick commented 8 years ago

Not much better, this is filtering them to zoom 2 in QGIS: screen shot 2015-09-07 at 9 50 45 pm

almccon commented 8 years ago

That's very weird. I poked around in that file, and it looks like adm0_sr works better. But I'm not sure why the column is named that... "sr" sounds like it's another scale rank but why adm0 when these are adm1?

screen shot 2015-09-07 at 7 sep 8 12 30

(dots classified by adm0_sr in this screenshot)

clhenrick commented 8 years ago

Some other things I've tried:

1. Creating a centroid for each state / province's set of points:

create table ne_10m_admin_1_label_points_centroids as (
  SELECT name, admin, scalerank, st_centroid(st_union(geometry)) as geometry 
  FROM ne_10m_admin_1_label_points 
  WHERE scalerank < 3
  AND admin ilike 'united states of am%'
  GROUP BY name, admin, scalerank
  order by admin, name
);

But this gives some odd results with points not in the central location of a state / province.

2. Pulling out the largest polygon for each state province and then creating a centroid for it:

SELECT area, name, ST_Centroid(geom) geom
FROM ne_10m_admin_1_states_provinces
WHERE area IN (
      SELECT area
      FROM ne_10m_admin_1_states_provinces 
      WHERE name = 'state province name' 
      ORDER BY area DESC
      LIMIT 1
)

So far the above query works for a single state province. I need to figure out how to iterate over every state / province's set of polygons so posted a question on gis stack exchange.

clhenrick commented 8 years ago

Update, using modified query from above I was able to get the following results which I filtered on scalerank < 4:

screen shot 2015-09-08 at 11 15 18 am

clhenrick commented 8 years ago

So I've got the admin1 labels working for both N. America and elsewhere. At lower zooms (4&5) I'm using the original admin1 labels for N. America because they contain the state / province abbreviations. Then at zoom 6 the labels switch to the new admin1 label data for both N. America and the rest of the world. At zoom 5 the rest of the world has admin1 labels start to show up from the new data. screen shot 2015-09-08 at 3 07 32 pm screen shot 2015-09-08 at 3 07 54 pm screen shot 2015-09-08 at 3 08 04 pm screen shot 2015-09-08 at 3 10 15 pm

almccon commented 8 years ago

At some zooms there are still too many state labels. Europe, z6:

screen shot 2015-10-28 at 2 09 16 pm

Europe, z7: screen shot 2015-10-28 at 2 09 45 pm

And sometimes maybe we could skip them if the names are really long, or use some kind of "short name" field in natural earth? Ethiopia, z6: screen shot 2015-10-28 at 2 07 50 pm

clhenrick commented 8 years ago

I played around with this some and it seems like using the scalerank value alone doesn't help much for Europe at lower zooms. Changing [scalerank <= x ] from 4 -10 doesn't seem to change anything at zooms 5-7. This is because most of the state / province polygons for larger European countries have a scalerank value of 3. Thus going lower than 3 removes the labels completely. Conversely, most of the smaller European countries have larger values for scalerank so they won't display at all until 4+.

Regarding the longer labels such as the one in Ethiopia; I didn't see a "short-name" column in the ne_10m_admin_1_states_provinces_scale_rank table which could be used for longer admin1 names either. We could also do some filtering on the featureclass attribute to ignore admin1 areas such as minor islands and aggregations. But unsure if that's a good idea or not? Or we could filter by string length to not display those labels that are very long.

However, reducing the text-size and lightening the text-fill of the admin1-labels layer seems to help the labels from over-powering the map style.

Here are some screenshots from zooms 5 - 7 (previously admin1 labels weren't displaying in Europe at z5):

screen shot 2015-11-03 at 12 08 43 pm

screen shot 2015-11-03 at 12 09 42 pm

screen shot 2015-11-03 at 12 12 55 pm

almccon commented 8 years ago

These are looking pretty good. I made them a little bit smaller and more gray. Calling this one finished!