Giter Site home page Giter Site logo

svy21's Introduction

SVY21

A Free and Open Source Library to convert between Lat/Lon, and SVY21.

Usage

Ruby

The Ruby version is packaged as a gem.

To install

gem "svy21", "~> 1.0.1"

Usage

require 'svy21'

# 570 Ang Mo Kio Avenue 10
# lat/lon
lat_lon = SVY21.svy21_to_lat_lon(39105.269, 30629.967)
puts "latitude: #{lat_long[0]}"
puts "longitude: #{lat_long[1]}"

# svy21
northing_easting = SVY21.lat_lon_to_svy21(1.3699278977737488, 103.85695034976467)
puts "northing: #{northing_easting[0]}"
puts "easting: #{northing_easting[1]}"

Python

The Python script is a ready-to-use converter. Run with python -i SVY21.py.

# Initialization
>>> cv = SVY21()

# Computing SVY21 from Lat/Lon
>>> (lat, lon) = (1.2949192688485278, 103.77367436885834)
>>> (N, E) = cv.computeSVY21(lat, lon)
>>> (N, E)
(30811.26429645264, 21362.157043860374)

# Computing Lat/Lon from SVY21
>>> (lat, lon) = cv.computeLatLon(N, E)
>>> (lat, lon)
(1.2949192688483109, 103.77367436887495)

Java

The package net.qxcg.svy21 contains all necessary files.

The static class SVY21 performs actual conversions. The classes SVY21Coordinate and LatLonCoordinate are immutable types that store SVY21 and Latitude/Longitude respectively. Conversions using SVY21 return new copies of either coordinate type.

// Required files are in this package.
import net.qxcg.svy21.*;

// Creating a latlon Coordinate.
LatLonCoordinate coord1 = new LatLonCoordinate(1.2949192688485278, 103.77367436885834);

// Conversion using coordinate method.
SVY21Coordinate result = coord1.asSVY21();

// Conversion using library.
result = SVY21.computeSVY21(coord1);

// It is also possible perform conversion directly using two plain 'double' types.
double lat = coord1.getLatitude();
double lon = coord1.getLongitude();
result = SVY21.computeSVY21(lat, lon);

// The reverse conversion also can be done using all three methods.
LatLonCoordinate reverseResult = result.asLatLon();

reverseResult = SVY21.computeLatLon(result);

double northing = result.getNorthing();
double easting = result.getEasting();
reverseResult = SVY21.computeLatLon(northing, easting);

JavaScript

// Initialization
var cv = new SVY21();

// Computing SVY21 from Lat/Lon
var lat = 1.2949192688485278;
var lon = 103.77367436885834;
var result = cv.computeSVY21(lat, lon);
console.log(result);

// Computing Lat/Lon from SVY21
var resultLatLon = cv.computeLatLon(result.N, result.E);
console.log(resultLatLon);

C#

The C# implementation was ported from the Java implementation, and includes the same tests (executable in Visual Studio.) Unlike the Java implementation, however, LatLongCoordinate and Svy21Coordinate are mutable.

The included solution can be built to produce a class library (SVY21.dll) which can be included in any project. Alternatively, the three classes (LatLongCoordinate, Svy21Coordinate, and Svy21) can be included directly.

// Creating a Lat/Long Coordinate.
LatLongCoordinate latLong = new LatLongCoordinate(1.2949192688485278, 103.77367436885834);

// "Ask" the object to convert itself.
Svy21Coordinate converted = latLong.ToSvy21Coordinate();

// Conversion using library.
converted = Svy21.ComputeSvy21(latLong);

// Conversion can also be done directly using two doubles.
double latitude = latLong.Latitude;
double longitude = latLong.Longitude;
converted = Svy21.ComputeSvy21(latitude, longitude);

// Conversion from SVY21 to Latitude/Longitude can also be done using all three methods.
LatLongCoordinate reverse = converted.ToLatLongCoordinate();
reverse = Svy21.ComputeLatitudeLongitude(converted);

double northing = converted.Northing;
double easting = converted.Easting;
reverse = Svy21.ComputeLatitudeLongitude(northing, easting);

C++

// Initialization
SVY21 svy21;

// Computing SVY21 from Lat/Lon
double lat = 1.2949192688485278;
double lon = 103.77367436885834;
double northing, easting;
svy21.latLonToSVY21(lat, lon, &northing, &easting);
printf("%lf %lf\n", northing, easting);

// Computing Lat/Lon from SVY21
svy21.SVY21ToLatLon(northing, easting, &lat, &lon);
printf("%lf %lf\n", lat, lon);

Testing

The "Protected Areas And Protected Places Act" found here lists some SVY21 points that correspond to vertices of hard-to-miss plots of land in Singapore.

You can try converting some of the Northing, Easting coordinates to Latitude and Longitude, and viewing the plot of land on Google Maps to verify their accuracy.

Precision

Like all floating-point computations, converting back and forth between Lat/Lon and SVY21 will cause the loss of precision.

In the Python example above, note that the input Lat/Lon and output Lat/Lon are very slightly different. Repeating the process a few more times will compound this difference.

The useful precision of the output also depends on the precision of the inputs.

Known Issues

  1. Setting the origin's latitude and longitude, represented by oLat and oLon respectively, to the official SVY21 datum specified here results in computation being a bit off (when compared to a Google Maps satellite image) for the above sample points. However, the rounded values of (1.366666, 103.833333) give accurate results.

Mathematics

This library makes use of the equations in the following page:
Transverse Mercator Transformation Formulae

Other Languages

Feel free to port the code to other languages, and submit a pull request if you do!

Future Direction

  1. Code quality. This library was developed during a Hackathon, and needs to be brought up to production standard.
  2. Automated and/or more comprehensive tests.

Acknowledgements

Isaac Low
Jonathan Ong
Chua Wei Kuan

If you used this library in your project and found it useful, let us know!

Created during Hack & Roll '13 by NUS Hackers

svy21's People

Contributors

cgcai avatar jcheng31 avatar jonongjs avatar khankuan avatar lxcid avatar riccqi avatar yi-jiayu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svy21's Issues

License is missing

Hi,
What is exact license of this library? Can it be used in closed-source projects?

different result using c++ and python

Hi guys,

I use the following code in c++:

SVY21 svy21;
double northing, easting;
double lat, lon;
easting = 12056.9149612;
northing = 37621.664783;
svy21.SVY21ToLatLon(northing, easting, &lat, &lon);
printf("%lf %lf\n", lat, lon);

Result: 1.356507 103.159780

I use the python:

cv = SVY21()
(N, E) = (37621.664783, 12056.9149612)
(lat, lon) = cv.computeLatLon(N, E)
(lat, lon)
(1.3565065593611545, 103.69005934636358)

Different results (longitude) and the Python one is quite accurate but the c++ one is not. Anything happened?

Deprecated, Use proj4

Javascript example:

    import proj4 from 'proj4'
    proj4.defs("EPSG:3414","+proj=tmerc +lat_0=1.366666666666667 +lon_0=103.8333333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +ellps=WGS84 +units=m +no_defs");
    var coords = proj4("EPSG:3414").inverse([43387.0213,40582.6686]);
    console.log(coords)

Projection details were retrieved from https://epsg.io/3414
https://github.com/proj4js/proj4js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.