Skip to content

Instantly share code, notes, and snippets.

@alanho
Last active October 17, 2016 08:49
Show Gist options
  • Save alanho/51ea9161ace791da6d3e to your computer and use it in GitHub Desktop.
Save alanho/51ea9161ace791da6d3e to your computer and use it in GitHub Desktop.
101 Ways to Convert HK1980 <> WGS84
Note:
HK1980: SRID 2326 http://spatialreference.org/ref/epsg/hong-kong-1980-grid-system/
WGS84: SRID 4326
Example:
Journey time indicators by Transport Department
https://data.gov.hk/en-data/dataset/hk-td-tis-journey-time-indicators
Location: H1 – JTI at Gloucester Road eastbound near the Revenue Tower (835776.133E, 815604.834N)
Method 1:
Land Department Geodetic Survey Section, Web-based Transformation Tool
http://www.geodetic.gov.hk/smo/tform/tform.aspx
=> 22.279311622,114.172101664
Method 2:
http://www.qgis.org
Method 3:
PostgreSQL + PostGIS
SELECT ST_AsText(ST_Transform(ST_GeomFromText('POINT(835776.133 815604.834)', 2326), 4326));
-----------------------------------------
POINT(114.172101663296 22.279311622048)
Method 4:
require "rgeo"
hk1980_proj4 = "+proj=tmerc +lat_0=22.31213333333334 +lon_0=114.1785555555556 +k=1 +x_0=836694.05 +y_0=819069.8 +ellps=intl +towgs84=-162.619,-276.959,-161.764,0.067753,-2.24365,-1.15883,-1.09425 +units=m +no_defs"
hk1980_wkt = <<WKT
PROJCS["Hong Kong 1980 Grid System",
GEOGCS["Hong Kong 1980",
DATUM["Hong_Kong_1980",
SPHEROID["International 1924",6378388,297,
AUTHORITY["EPSG","7022"]],
TOWGS84[-162.619,-276.959,-161.764,0.067753,-2.24365,-1.15883,-1.09425],
AUTHORITY["EPSG","6611"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4611"]],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",22.31213333333334],
PARAMETER["central_meridian",114.1785555555556],
PARAMETER["scale_factor",1],
PARAMETER["false_easting",836694.05],
PARAMETER["false_northing",819069.8],
AUTHORITY["EPSG","2326"],
AXIS["Easting",EAST],
AXIS["Northing",NORTH]]
WKT
wgs84_proj4 = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs'
wgs84_wkt = <<WKT
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.01745329251994328,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
WKT
wgs84_factory = RGeo::Geographic.spherical_factory(:srid => 4326, :proj4 => wgs84_proj4, :coord_sys => wgs84_wkt)
hk1980_factory = RGeo::Cartesian.factory(:srid => 2326, :proj4 => hk1980_proj4, :coord_sys => hk1980_wkt)
gloucester_road = hk1980_factory.point(835776.133, 815604.834)
gloucester_road_latlon = RGeo::Feature.cast(gloucester_road, :factory => wgs84_factory, :project => true)
=> #<RGeo::Geographic::SphericalPointImpl:0x3fdd0896bdb8 "POINT (114.17210166329583 22.27931162204798)">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment