[MetaCRS] Followup: RE: MetaCRS Digest, Vol 28, Issue 6

Ben Krepp bkrepp at ctps.org
Mon Sep 20 11:47:32 EDT 2010


Hi Mike,

Thanks very much for chiming in on my question to the MetaCRS mailing list.
I'm writing back to you directly, rather than via the mailing list, in order
to minimize "chatter" for others on the list. When the issue I'm running
into is resolved, I'll post the results back to the list.

To answer the question you ask in your reply: 
es, I'm using exactly the same initialization string as the one you quoted
in your message. I'll post the full text of my code (which I've whittled
down to a pretty minimal test case) at the bottom of this message. It can
also be viewed "live" at http://www.bostonmpo.org/apps/bktest/test.js ; the
page that loads my test code can also be viewed "live", at:
http://www.bostonmpo.org/apps/bktest/test.cfm (The somewhat funny looking IF
statement in test.cfm can be ignored - it's simply selecting which of the
two Google Maps keys we have to use, depending on the server).

In any case, the long and the short of it is, I'm doing the following

1. Initializing Proj4js.defs for EPSG:4236 and EPSG:26986
2. Creating Proj4js.Proj objects for these two projections
3. Initializing a Proj4js Point object with the EPSG:4236 coordinates of the
point
4. Calling Proj4js.transform do to the EPSG:4236 to EPSG:26986
transformation
5. Printing out the coordinates of the 'transformed' point

A couple of follow up questions:

1. I'm using version 1.0.1 of proj4js, the most recent one I'm aware of. I
downloaded it http://trac.osgeo.org/proj4js/wiki/Download.  Are you using a
more recent version? If so, what is it, and where can I obtain it?
2. In your message, you mention that you transformed my point in the Proj4js
test page. When I took a look at the Proj4js test page
(http://www.proj4js.org/), EPSG:26986 isn't available as a 'dest' spatial
reference. Are you referring to a different Proj4js test page? If so, can
you point me to it? 

One other point: I'm a new user of Proj4js, and am following the
instructions posted in the on-line User Guide
(http://trac.osgeo.org/proj4js/wiki/UserGuide). In my first cut at this
little app, I put 
	<script src="../proj4js/lib/defs/EPSG4236.js"
type="text/javascript"> </script> and 
	<script src="../proj4js/lib/defs/EPSG26986.js"
type="text/javascript"> </script> tags in my test.cfm file. 
However, I later noticed that these files were not present in the copy of
Proj4js that I downloaded, and I switched to putting the initialization code
in-line, as was the case in the example in your message.

I'm still getting transformed coordinates that are off by a couple of
hundred meters (no change from Friday). So, it's clear that I'm not able
reproduce the (correct) behavior that you are seeing.
Any tips/thoughts on what I might be doing wrong or what might be going
wrong on my end would be much appreciated.

Thanks very much, and best regards,
Ben
Ben

//////////////// Begin included source code //////////////////////////
CTPS = {};
CTPS.testApp = {};

// Initialization for Proj4js
// Google Maps LatLon SRS
Proj4js.defs["EPSG:4236"] = "+proj=longlat +ellps=intl
+towgs84=-637,-549,-203,0,0,0,0 +no_defs";
// Mass State Plane NAD83 meters SRS
Proj4js.defs["EPSG:26986"] = "+proj=lcc +lat_1=42.68333333333333
+lat_2=41.71666666666667 +lat_0=41 +lon_0=-71.5 +x_0=200000 +y_0=750000
+ellps=GRS80 +datum=NAD83 +units=m +no_defs";

// Error reporting function for Proj4js
Proj4js.reportError = function(msg) {
	alert("Proj4js error: " + msg);
}

CTPS.testApp.load = function() {
	if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
		// Define Google Maps LatLng point for the location of the
Harvard Square MBTA station.
		var oGoogleLatLng = new
GLatLng(42.37346263960867,-71.11881762742996);
        map.setCenter(oGoogleLatLng, 19);
        map.addControl(new GSmallMapControl());
        map.addControl(new GScaleControl());
        map.addControl(new GMapTypeControl());
		map.setMapType(G_SATELLITE_MAP);
      } else {
		alert("Your browser doesn't support Google Maps.");
		return;
	  }
	  
	  // 'Source' SRS: Google Maps Lat/Lon
	  var oSrcPrj = new Proj4js.Proj('EPSG:4236');
	  // 'Destination' SRS: Massachusetts State Plane NAD83, meters
	  var oDestPrj = new Proj4js.Proj('EPSG:26986');
     	 // Define Proj4js point for location of the Harvard Square MBTA
station.
	  var oPoint = new Proj4js.Point(oGoogleLatLng.x,oGoogleLatLng.y);
	  // Project from EPSG:4236 to EPSG:26986; the projection is done
'in place.'
	  Proj4js.transform(oSrcPrj,oDestPrj,oPoint);
	  alert("Transformed LatLng->MassStatePlane coordinates are: X = " +
oPoint.x + " Y = " + oPoint.y);
}
//////////////////// End included source code //////////////////////////


-----Original Message-----
From: metacrs-bounces at lists.osgeo.org
[mailto:metacrs-bounces at lists.osgeo.org] On Behalf Of
metacrs-request at lists.osgeo.org
Sent: Saturday, September 18, 2010 12:00 PM
To: metacrs at lists.osgeo.org
Subject: MetaCRS Digest, Vol 28, Issue 6

Send MetaCRS mailing list submissions to
	metacrs at lists.osgeo.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://lists.osgeo.org/mailman/listinfo/metacrs
or, via email, send a message with subject or body 'help' to
	metacrs-request at lists.osgeo.org

You can reach the person managing the list at
	metacrs-owner at lists.osgeo.org

When replying, please edit your Subject line so it is more specific than
"Re: Contents of MetaCRS digest..."


Today's Topics:

   1. Proj4js problem: EPSG:4236 to EPSG:26986 transformation
      (Ben Krepp)
   2. Re: Proj4js problem: EPSG:4236 to EPSG:26986 transformation
      (Mike Adair)


----------------------------------------------------------------------

Message: 1
Date: Fri, 17 Sep 2010 15:19:41 -0400
From: "Ben Krepp" <bkrepp at ctps.org>
Subject: [MetaCRS] Proj4js problem: EPSG:4236 to EPSG:26986
	transformation
To: <metacrs at lists.osgeo.org>
Message-ID: <00dd01cb569d$470c3e30$d524ba90$@ctps.org>
Content-Type: text/plain; charset="us-ascii"

Hi all,

 

I'm trying to use the Proj4js library to transform coordinates from the
Google Maps SRS (EPSG:4236) to the Massachusetts State Plane NAD83 meters
SRS (EPSG:26986) SRS, but am running into problems. Specifically, the
results I'm getting are off by a several hundred meters for both the X and Y
values. 

 

The following snippet of JavaScript code is sufficient to expose the issue:

 

// Begin code snippet

                var oSrcPrj = new Proj4js.Proj('EPSG:4236');

                var oDestPrj = new Proj4js.Proj('EPSG:26986');

                var oPoint = new
Proj4js.Point(-71.11881762742996,42.37346263960867);

                Proj4js.transform(oSrcPrj,oDestPrj,oPoint);

                alert("Transformed LatLng->MassStatePlane coordinates are: X
= " + oPoint.x + " Y = " + oPoint.y);

// End code snippet

 

The oPoint variable represents the location of the Harvard Square MBTA
station in Cambridge, MA., as reported by Google Maps .The coordinate values
were obtained by printing them out in a simple Google Maps onclic! event
handler.

 

When run, the coordinates of the transformed point are:

X = 230616.5448393133,  Y = 902165.5744436784

 

According to the MassGIS MBTA_NODE GIS layer, which uses the Massachusetts
State Plane NAD83 meters (i.e., EPSG:26986) SRS, the coordinates of this
point are:

               X = 231394.7344,  Y = 902622.1875

 

So, there is a large discrepancy between the actual and expected results.

Am I using the library incorrectly, or is there a bug in Proj4js?

 

Thanks for any light that can be shed on this.

 

Ben Krepp

Manager of Information Technology, GIS, and Data Services

Central Transportation Planning Staff

10 Park Plaza

Suite 2150

Boston, MA 02115

e-mail: bkrepp at ctps.org

phone: 617-973-7137

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.osgeo.org/pipermail/metacrs/attachments/20100917/3855d438/attac
hment-0001.html

------------------------------

Message: 2
Date: Fri, 17 Sep 2010 15:44:42 -0400
From: Mike Adair <madair at dmsolutions.ca>
Subject: Re: [MetaCRS] Proj4js problem: EPSG:4236 to EPSG:26986
	transformation
To: metacrs at lists.osgeo.org
Message-ID: <4C93C52A.7080301 at dmsolutions.ca>
Content-Type: text/plain; charset="iso-8859-1"

  Ben,

Running that point in the test page of Proj4js, I get:
231394.84,  902621.11
(which is also almost exactly the same result I get from PROJ.4) and off
from your expected result by centimeters.

Are you using the correct initialization string?

Proj4js.defs["EPSG:26986"] = "+proj=lcc +lat_1=42.68333333333333
+lat_2=41.71666666666667 +lat_0=41 +lon_0=-71.5 +x_0=200000 +y_0=750000
+ellps=GRS80 +datum=NAD83 +units=m +no_defs";

(also at http://spatialreference.org/ref/epsg/26986/proj4js/)

Mike


On 9/17/2010 3:19 PM, Ben Krepp wrote:
>
> Hi all,
>
> I'm trying to use the Proj4js library to transform coordinates from 
> the Google Maps SRS (EPSG:4236) to the Massachusetts State Plane NAD83 
> meters SRS (EPSG:26986) SRS, but am running into problems.
> Specifically, the results I'm getting are off by a several hundred 
> meters for both the X and Y values.
>
> The following snippet of JavaScript code is sufficient to expose the
> issue:
>
> // Begin code snippet
>
>                 var oSrcPrj = new Proj4js.Proj('EPSG:4236');
>
>                 var oDestPrj = new Proj4js.Proj('EPSG:26986');
>
>                 var oPoint = new
> Proj4js.Point(-71.11881762742996,42.37346263960867);
>
>                 Proj4js.transform(oSrcPrj,oDestPrj,oPoint);
>
>                 alert("Transformed LatLng->MassStatePlane coordinates
> are: X = " + oPoint.x + " Y = " + oPoint.y);
>
> // End code snippet
>
> The oPoint variable represents the location of the Harvard Square MBTA 
> station in Cambridge, MA., as reported by Google Maps .The coordinate 
> values were obtained by printing them out in a simple Google Maps 
> onclic! event handler.
>
> When run, the coordinates of the transformed point are:
>
> X = 230616.5448393133,  Y = 902165.5744436784
>
> According to the MassGIS MBTA_NODE GIS layer, which uses the 
> Massachusetts State Plane NAD83 meters (i.e., EPSG:26986) SRS, the 
> coordinates of this point are:
>
>                X = 231394.7344,  Y = 902622.1875
>
> So, there is a large discrepancy between the actual and expected results.
>
> Am I using the library incorrectly, or is there a bug in Proj4js?
>
> Thanks for any light that can be shed on this.
>
> Ben Krepp
>
> Manager of Information Technology, GIS, and Data Services
>
> Central Transportation Planning Staff
>
> 10 Park Plaza
>
> Suite 2150
>
> Boston, MA 02115
>
> e-mail: bkrepp at ctps.org <mailto:bkrepp at ctps.org>
>
> phone: 617-973-7137
>
>
> _______________________________________________
> MetaCRS mailing list
> MetaCRS at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/metacrs

-- 
    Michael Adair
    Senior Software Architect
    DM Solutions Group Inc.

    Office: (613) 565-5056 x26
    madair at dmsolutions.ca
    http://www.dmsolutions.ca
    http://research.dmsolutions.ca


-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.osgeo.org/pipermail/metacrs/attachments/20100917/0ecbfcc4/attac
hment-0001.html

------------------------------

_______________________________________________
MetaCRS mailing list
MetaCRS at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/metacrs


End of MetaCRS Digest, Vol 28, Issue 6
**************************************



More information about the MetaCRS mailing list