Skip to content

Instantly share code, notes, and snippets.

@peterdesmet
Last active August 29, 2015 14:07
Show Gist options
  • Save peterdesmet/8537e58ab1609b3cadf1 to your computer and use it in GitHub Desktop.
Save peterdesmet/8537e58ab1609b3cadf1 to your computer and use it in GitHub Desktop.
Transform Belgian Lambert to WGS84 in PostgreSQL
-- SetSRID defines the datum. Use 31370, not 31300 for Belgian Lambert 72
SELECT
*,
ST_Transform(ST_SetSRID(ST_MakePoint(x,y),31370),4326) as geom_from_lambert,
ST_Y(ST_Transform(ST_SetSRID(ST_MakePoint(x,y),31370),4326)) as latitude_from_lambert,
ST_X(ST_Transform(ST_SetSRID(ST_MakePoint(x,y),31370),4326)) as longitude_from_lambert
FROM table_name
UPDATE table_name SET latitude_from_lambert = round(ST_Y(ST_Transform(ST_SetSRID(ST_MakePoint(x,y),31370),4326))::numeric,7);
UPDATE table_name SET longitude_from_lambert = round(ST_X(ST_Transform(ST_SetSRID(ST_MakePoint(x,y),31370),4326))::numeric,7);
@peterdesmet
Copy link
Author

geom_from_lambert seems to be interpreted as a string, not sure what function is required to make this a geometry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment