Reputation: 3809
I am a novice programmer working on a JavaScript based web application for smartphones.
The application obtains the longitude & latitude using navigator.geolocation API.
I need a JavaScript based function to convert the obtained location into Easting & Northing using Polyconic Transformation with the "Everest - India 1830" datum, which I need to support. Also an inverse function of the same would be required to convert Easting/Northing to Longitude/Latitude.
After doing research on the internet I came across proj4js. However, I could not get a very clear understanding of the procedure for the required conversion & also did not find adequate documentation.
Thanks in advance.
Upvotes: 2
Views: 2128
Reputation: 6562
OK, using Spatialreference.org's REST service you can obtain the definition of this projection (http://spatialreference.org/ref/sr-org/7345/proj4/) which turns out to be
+proj=poly +lat_0=33.625 +lon_0=77.375 +x_0=0 +y_0=0 +a=6377301.243 +b=6356100.228368102 +units=m +no_defs
To get this to work with proj4, create a definition file in the defs/ folder called SRORG7345.js
containing the following:
Proj4js.defs["SRORG7345"] = "+proj=poly +lat_0=33.625 +lon_0=77.375 +x_0=0 +y_0=0 +a=6377301.243 +b=6356100.228368102 +units=m +no_defs";
Then do this to transform from EPSG:4236 to your new projection:
<html>
<Script src='proj4js-compressed.js'></script>
<script src='defs/EPSG4236.js'></script>
<script src='defs/SRORG7345.js'></script>
<script>
// creating source and destination Proj4js objects
// once initialized, these may be re-used as often as needed
var source = new Proj4js.Proj('EPSG:4236'); //source coordinates will be in Longitude/Latitude
var dest = new Proj4js.Proj('SRORG7345'); //IndiaPolyConic
var p = new Proj4js.Point(-76.0,45.0); //any object will do as long as it has 'x' and 'y' properties
Proj4js.transform(source, dest, p); //do the transformation. x and y are modified in place
console.log(p);
</script>
</html>
I'd note that according to the proj4js project page, the polyconic conversions "have not been validated against any test points yet" so you'll probably need to doing some checking of these results.
Upvotes: 2