Skip to content

Commit

Permalink
moving to analytic web mercator scale factor formula
Browse files Browse the repository at this point in the history
changing regexp for width numbers
  • Loading branch information
imagico committed Sep 20, 2015
1 parent ae89a51 commit cbc48dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion project.mml
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@
"srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
"Datasource": {
"extent": "-20037508,-20037508,20037508,20037508",
"table": "(SELECT\n way,\n COALESCE(\n ('highway_' || (CASE WHEN highway IN ('residential', 'unclassified', 'pedestrian', 'service', 'footway', 'cycleway', 'living_street', 'track', 'path', 'platform', 'services') THEN highway ELSE NULL END)),\n ('railway_' || (CASE WHEN railway IN ('platform') THEN railway ELSE NULL END)),\n (('aeroway_' || CASE WHEN aeroway IN ('runway', 'taxiway', 'helipad') THEN aeroway ELSE NULL END))\n ) AS feature\n FROM (\n SELECT \n way, highway, railway, aeroway, z_order, way_area FROM planet_osm_polygon\n WHERE highway IN ('residential', 'unclassified', 'pedestrian', 'service', 'footway', 'living_street', 'track', 'path', 'platform', 'services')\n OR railway IN ('platform')\n OR aeroway IN ('taxiway', 'helipad')\n UNION ALL\n SELECT -- runways with width either tagged or estimated from runway length\n ST_Buffer(\n way,\n 0.5*(St_Distance(ST_StartPoint(way), ST_EndPoint(way))/St_Distance_Sphere(ST_Transform(ST_StartPoint(way), 4326), ST_Transform(ST_EndPoint(way), 4326)))*\n CASE\n WHEN width ~ '^-?\\d{1,4}(\\.\\d+)?$' THEN width::NUMERIC\n ELSE LEAST(GREATEST((St_Distance_Sphere(ST_Transform(ST_StartPoint(way), 4326), ST_Transform(ST_EndPoint(way), 4326)))/50.0,12.0),75.0)\n END,\n 'endcap=flat join=round'\n ),\n highway, railway, aeroway, z_order, ST_Length(way)*ST_Length(way) AS way_area FROM planet_osm_line\n WHERE aeroway IN ('runway')\n UNION ALL\n SELECT -- taxiways with width either tagged or guessed\n ST_Buffer(\n way,\n 0.5*(St_Distance(ST_StartPoint(way), ST_EndPoint(way))/St_Distance_Sphere(ST_Transform(ST_StartPoint(way), 4326), ST_Transform(ST_EndPoint(way), 4326)))*\n CASE\n WHEN width ~ '^-?\\d{1,4}(\\.\\d+)?$' THEN width::NUMERIC\n ELSE 6\n END,\n 'endcap=flat join=round'\n ),\n highway, railway, aeroway, z_order, ST_Length(way)*ST_Length(way) AS way_area FROM planet_osm_line AS tline\n WHERE aeroway IN ('taxiway')\n ) AS features\n ORDER BY z_order, way_area desc\n) AS highway_area_fill",
"table": "(SELECT\n way,\n COALESCE(\n ('highway_' || (CASE WHEN highway IN ('residential', 'unclassified', 'pedestrian', 'service', 'footway', 'cycleway', 'living_street', 'track', 'path', 'platform', 'services') THEN highway ELSE NULL END)),\n ('railway_' || (CASE WHEN railway IN ('platform') THEN railway ELSE NULL END)),\n (('aeroway_' || CASE WHEN aeroway IN ('runway', 'taxiway', 'helipad') THEN aeroway ELSE NULL END))\n ) AS feature\n FROM (\n SELECT \n way, highway, railway, aeroway, z_order, way_area FROM planet_osm_polygon\n WHERE highway IN ('residential', 'unclassified', 'pedestrian', 'service', 'footway', 'living_street', 'track', 'path', 'platform', 'services')\n OR railway IN ('platform')\n OR aeroway IN ('taxiway', 'helipad')\n UNION ALL\n SELECT -- runways with width either tagged or estimated from runway length\n ST_Buffer(\n way,\n -- more generic estimation for scale factor on arbitrary projections would be:\n -- 0.5*(St_Distance(ST_StartPoint(way), ST_EndPoint(way))/St_Distance_Sphere(ST_Transform(ST_StartPoint(way), 4326), ST_Transform(ST_EndPoint(way), 4326)))*\n (0.5 / cos(radians(ST_y(st_transform(st_centroid(way),4326)))))* -- works on Mercator only\n CASE\n WHEN width ~ '^\\d{1,3}(\\.\\d+)?$' THEN width::real\n ELSE LEAST(GREATEST(ST_Length(st_transform(way,4326)::geography)/50,12.0),75.0)\n END,\n 'endcap=flat join=round'\n ),\n highway, railway, aeroway, z_order, ST_Length(way)*ST_Length(way) AS way_area FROM planet_osm_line\n WHERE aeroway IN ('runway')\n UNION ALL\n SELECT -- taxiways with width either tagged or guessed\n ST_Buffer(\n way,\n -- more generic estimation for scale factor on arbitrary projections would be:\n -- 0.5*(St_Distance(ST_StartPoint(way), ST_EndPoint(way))/St_Distance_Sphere(ST_Transform(ST_StartPoint(way), 4326), ST_Transform(ST_EndPoint(way), 4326)))*\n (0.5 / cos(radians(ST_y(st_transform(st_centroid(way),4326)))))* -- works on Mercator only\n CASE\n WHEN width ~ '^\\d{1,3}(\\.\\d+)?$' THEN width::real\n ELSE 6\n END,\n 'endcap=flat join=round'\n ),\n highway, railway, aeroway, z_order, ST_Length(way)*ST_Length(way) AS way_area FROM planet_osm_line AS tline\n WHERE aeroway IN ('taxiway')\n ) AS features\n ORDER BY z_order, way_area desc\n) AS highway_area_fill",
"geometry_field": "way",
"type": "postgis",
"key_field": "",
Expand Down
14 changes: 9 additions & 5 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,12 @@ Layer:
SELECT -- runways with width either tagged or estimated from runway length
ST_Buffer(
way,
0.5*(St_Distance(ST_StartPoint(way), ST_EndPoint(way))/St_Distance_Sphere(ST_Transform(ST_StartPoint(way), 4326), ST_Transform(ST_EndPoint(way), 4326)))*
-- more generic estimation for scale factor on arbitrary projections would be:
-- 0.5*(St_Distance(ST_StartPoint(way), ST_EndPoint(way))/St_Distance_Sphere(ST_Transform(ST_StartPoint(way), 4326), ST_Transform(ST_EndPoint(way), 4326)))*
(0.5 / cos(radians(ST_y(st_transform(st_centroid(way),4326)))))* -- works on Mercator only
CASE
WHEN width ~ '^-?\d{1,4}(\.\d+)?$' THEN width::NUMERIC
ELSE LEAST(GREATEST((St_Distance_Sphere(ST_Transform(ST_StartPoint(way), 4326), ST_Transform(ST_EndPoint(way), 4326)))/50.0,12.0),75.0)
WHEN width ~ '^\d{1,3}(\.\d+)?$' THEN width::real
ELSE LEAST(GREATEST(ST_Length(st_transform(way,4326)::geography)/50,12.0),75.0)
END,
'endcap=flat join=round'
),
Expand All @@ -930,9 +932,11 @@ Layer:
SELECT -- taxiways with width either tagged or guessed
ST_Buffer(
way,
0.5*(St_Distance(ST_StartPoint(way), ST_EndPoint(way))/St_Distance_Sphere(ST_Transform(ST_StartPoint(way), 4326), ST_Transform(ST_EndPoint(way), 4326)))*
-- more generic estimation for scale factor on arbitrary projections would be:
-- 0.5*(St_Distance(ST_StartPoint(way), ST_EndPoint(way))/St_Distance_Sphere(ST_Transform(ST_StartPoint(way), 4326), ST_Transform(ST_EndPoint(way), 4326)))*
(0.5 / cos(radians(ST_y(st_transform(st_centroid(way),4326)))))* -- works on Mercator only
CASE
WHEN width ~ '^-?\d{1,4}(\.\d+)?$' THEN width::NUMERIC
WHEN width ~ '^\d{1,3}(\.\d+)?$' THEN width::real
ELSE 6
END,
'endcap=flat join=round'
Expand Down

0 comments on commit cbc48dc

Please sign in to comment.