You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cartodb-postgresql/doc/CDB_TransformToWebmercator.md

1.0 KiB

Function to "safely" transform to webmercator. This function is most useful for rendering custom geometries using the CartoDB tiler. Often, transforming a projection like WGS84 can cause issues with extents beyond what are actually valid in webmercator, this attempts to fix those issues.

Using the function

Using a box that is nearly the full globe,

ST_SetSRID(
  ST_Envelope(
    ST_Collect(
      ST_MakePoint(-180,60),
      ST_MakePoint(180,-60)
    )
   ),
   4326
)

We can then convert it to a renderable webmercator geometry.

SELECT CDB_TransformToWebmercator(
 ST_SetSRID(
  ST_Envelope(
    ST_Collect(
      ST_MakePoint(-10,60),
      ST_MakePoint(300,-60)
    )
   ),
   4326
 )
)

Would give you back a single valid rectangle in webmercator. Since a longitude of 300 would convert to an unallowed webmercator coordinate, it gets clipped first. Valid extent is WGS84 (-180, -89, 180, 89)

valid geom

Arguments

CDB_TransformToWebmercator(geom)

  • geom geometry