{"action":"created","issue":{"url":"https://api.github.com/repos/gravitystorm/openstreetmap-carto/issues/1644","labels_url":"https://api.github.com/repos/gravitystorm/openstreetmap-carto/issues/1644/labels{/name}","comments_url":"https://api.github.com/repos/gravitystorm/openstreetmap-carto/issues/1644/comments","events_url":"https://api.github.com/repos/gravitystorm/openstreetmap-carto/issues/1644/events","html_url":"https://github.com/gravitystorm/openstreetmap-carto/issues/1644","id":93915551,"number":1644,"title":"Switch to ST_PointOnSurface?","user":{"login":"pnorman","id":1190866,"avatar_url":"https://avatars.githubusercontent.com/u/1190866?v=3","gravatar_id":"","url":"https://api.github.com/users/pnorman","html_url":"https://github.com/pnorman","followers_url":"https://api.github.com/users/pnorman/followers","following_url":"https://api.github.com/users/pnorman/following{/other_user}","gists_url":"https://api.github.com/users/pnorman/gists{/gist_id}","starred_url":"https://api.github.com/users/pnorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnorman/subscriptions","organizations_url":"https://api.github.com/users/pnorman/orgs","repos_url":"https://api.github.com/users/pnorman/repos","events_url":"https://api.github.com/users/pnorman/events{/privacy}","received_events_url":"https://api.github.com/users/pnorman/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/gravitystorm/openstreetmap-carto/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-08T23:53:08Z","updated_at":"2015-07-09T09:24:29Z","closed_at":null,"body":"In vector tiles, polygons cannot be used for labeling, as polygons are clipped to the vector tile bounds.\r\n\r\nThis is a particular problem for non-PostGIS datasources, but for PostGIS ones, the standard solution is to use ST_PointOnSurface. #349 found that it was not really better or worse than Mapnik label placement.\r\n\r\nhttps://github.com/gravitystorm/openstreetmap-carto/issues/349#issuecomment-36590153 raised the possibility of performance concerns. I am not sure, but there are a couple of ways this can be addressed\r\n\r\n1. Appropriate use of `!bbox!`. `(SELECT ST_PointOnSurface(way) AS way FROM planet_osm_polygon) AS p` does not work because the geometry filtering condition used is `ST_PointOnSurface(way) && !bbox!`.\r\n\r\n  The appropriate way to write the query is\r\n   ```sql\r\n(SELECT\r\n    ST_PointOnSurface(way)\r\n  FROM planet_osm_polygon\r\n  WHERE way && !bbox!\r\n    AND name IS NOT NULL\r\n) AS p\r\n```\r\n\r\n  This will then use indexes to limit the data fetched, with a second filtering taking place in the outer select added by Mapnik. A functional index on `ST_PointOnSurface(way) WHERE name IS NOT NULL` could also help.\r\n\r\n  I don't know if @mrwojo did this when testing. If not, it could easily explain any performance differences.\r\n\r\n2. Where this is both a point and a polygon layer, these can be combined into one query with `UNION ALL`"},"comment":{"url":"https://api.github.com/repos/gravitystorm/openstreetmap-carto/issues/comments/119886543","html_url":"https://github.com/gravitystorm/openstreetmap-carto/issues/1644#issuecomment-119886543","issue_url":"https://api.github.com/repos/gravitystorm/openstreetmap-carto/issues/1644","id":119886543,"user":{"login":"gravitystorm","id":360803,"avatar_url":"https://avatars.githubusercontent.com/u/360803?v=3","gravatar_id":"","url":"https://api.github.com/users/gravitystorm","html_url":"https://github.com/gravitystorm","followers_url":"https://api.github.com/users/gravitystorm/followers","following_url":"https://api.github.com/users/gravitystorm/following{/other_user}","gists_url":"https://api.github.com/users/gravitystorm/gists{/gist_id}","starred_url":"https://api.github.com/users/gravitystorm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gravitystorm/subscriptions","organizations_url":"https://api.github.com/users/gravitystorm/orgs","repos_url":"https://api.github.com/users/gravitystorm/repos","events_url":"https://api.github.com/users/gravitystorm/events{/privacy}","received_events_url":"https://api.github.com/users/gravitystorm/received_events","type":"User","site_admin":false},"created_at":"2015-07-09T09:24:29Z","updated_at":"2015-07-09T09:24:29Z","body":"`st_pointonsurface` needs to operate on valid geometries, and calling `where st_isvalid(way)` on some of our larger geometries is a performance killer."}}