Skip to content
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

Place area city/town #538

Closed
wants to merge 6 commits into from
Closed

Conversation

pnorman
Copy link
Collaborator

@pnorman pnorman commented May 19, 2014

Part of #103

This will reveal two widespread problems in the data

  • TIGER import place classifications are awful.
  • There are frequently duplicate place areas and place points

I don't see revealing either as a blocker as it should lead to them getting fixed.

Previously we had one place layer for capitals and one for non-capitals
when it came to towns and cities. This combines them, reducing the number
of queries, making the SQL simpler, and making the layers more useful for
other styles.

Incidentially fixes gravitystorm#522
This is part of gravitystorm#103, but only fixes it for place=city/town

The SQL is moderately complex and difficult to document in the .mml file so it's worth documenting here

```sql
(SELECT way,place,name,capital,population
  FROM
    (SELECT
        way,place,name,NULL AS capital,way_area, -- The polygon table doesn't have the capital information with the default style
        CASE WHEN population~E'^\\d{1,9}$' THEN population::integer ELSE NULL END AS population
          -- We need to filter out population values that might cause exceptions. This is a fairly rigerous filtering as it will remove population=1,000
      FROM planet_osm_polygon
    UNION ALL -- Join the two together
    SELECT
        way,place,name,capital,NULL AS way_area, -- Points don't have an area
        CASE WHEN population~E'^\\d{1,9}$' AND length(population)<10 THEN population::integer ELSE NULL END AS population -- as above
      FROM planet_osm_point) AS p
  WHERE place IN ('city','town') -- This condition is brought inside by the query optimizer
  ORDER BY
    CASE place WHEN 'city' THEN 0 ELSE 10 END, -- We don't actually need this at moment with the current MSS
    CASE capital WHEN 'yes' THEN 0 ELSE 10 END, -- Nor this
    way_area DESC NULLS LAST, -- Put physically larger first
    population DESC NULLS LAST -- For points (no area) put larger population first
) AS placenames_medium
```

The ordering merits further discussion

We're currently not considering area or population for ordering, so anything is an improvement here. It's hard to say if area,population or population,area is better without trying one first.
Benchmarking shows \d+ and length with no NULL check is the fastest way to check if the population is safe to cast
@matthijsmelissen
Copy link
Collaborator

Thank you for this PR.

  • There are frequently duplicate place areas and place points

I am not sure if I'd consider this a bug. On the one hand, it would be good to have one OSM object for every real-world object. On the other hand, points can indicate the center of the settlement, while the area can indicate the outline. Rendering the name in the middle of the area would often be ugly, in particular for 'unbalanced' settlements - like coastal settlements typically are, for example.

@pnorman pnorman changed the title Place area Place area city/town May 20, 2014
@pnorman pnorman mentioned this pull request May 20, 2014
@pnorman
Copy link
Collaborator Author

pnorman commented May 20, 2014

Superceeded by #546

@pnorman pnorman closed this May 20, 2014
@pnorman pnorman deleted the place_area branch November 23, 2015 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants