Adding Projection Classes to Proj4js

4 messages Options
Embed this post
Permalink
Richard Marsden

Adding Projection Classes to Proj4js

Reply Threaded More More options
Print post
Permalink
Hello,

I'm currently working on a demonstration project, most of which I shall be writing up on http://www.geowebguru.com in September as a part of a series on map projections and coordinate systems.

I have chosen 9 global equal area map projections, and have them implemented in MapServer and OpenLayers.
Well the MapServer / WMS / OpenLayers side of things is working, but OpenLayers has problems adding overlays (typically GeoRSS or KML) for 7 out of the 9 projections.
It didn't take much investigating before I found the reason for this was because proj4js did not support the projection classes in question.
For the record, they are:

crast Parabolic Craster
eck4 Eckert IV
eck6 Eckert VI
mbtfpq McBryde-Thomas Polar Quartic
quau Quartic Authalic
hammer Hammer
cea Cylindrical Equal Area (I'm actually using the Behrmann variant)
bonne Bonne

(Mollweide and Sinusoidal both work fine - thanks, guys!)

In retrospect, it isn't that surprising that many of these are missing. proj.4 is an extensive library (hence MapServer supports them all), but proj4js needs to be relatively lightweight due to its use in web page client applications.

So, thinking about it, I could skip the overlay support for most of the above projections (especially all the extra pseudo-cylindricals).
However, the one I really want (and I am surprised it is not supported), is the cea Cylindrical Equal Area projection class. The maths for this should be relatively easy, so how easy is it to add new projections to proj4js? Yes I'm proposing to do it myself.

Cylindrical Equal Area will allow support for the Behrmann Projection (the one I want) but also the much-maligned-but-popular-in-some-circles Gall-Peters.

I don't know if there have been requests for the others? Bonne is a nice novelty projection but probably has limited value in the 21st century...

I'm jetting off on vacation on Monday, so unless I "pull an all-nighter" this weekend, implementing CEA will probably have to wait until mid-August.

I'm always on the lookout for possible new articles for GeoWebGuru.com. I think proj4js development might be a bit too detailed/intricate, but I think there's definitely potential for me to write a short "how to use proj4js" article in my planned series on map projections.



Richard Marsden
Winwaed Software Technology LLC
http://www.winwaed.com
http://www.mapping-tools.com
http://www.geowebguru.com
_______________________________________________
MetaCRS mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/metacrs
Richard Marsden

Re: Adding Projection Classes to Proj4js

Reply Threaded More More options
Print post
Permalink
Further to last night's email, I now have an implementation of the cea "Cylindrical Equal Area" projection working. However it currently assumes a sphere.

I believe I have the forward transform working for an ellipsoid (see below).
Does this look correct?  I try to calculate the Earth's radius at the coord's latitude and use this for calculating the y ordinate.    This is not applied to the x ordinate because this would break the "cylindrical" nature of the projection.

(I notice that many of the projections marked as untested, assume a spherical Earth)

Personally I don't need the inverse transform, but I'm also not sure how to apply the ellipsoid correction to the inverse transform.

I know the efficiency of the following code can be improved - eg. cos(lat_ts) could be cached in the initialisation function.


Richard
-------------------------------


  /* Cylindrical Equal Area forward equations--mapping lat,long to x,y
    ------------------------------------------------------------*/
  forward: function(p) {
    var lon=p.x;
    var lat=p.y;
    /* Forward equations
      -----------------*/
    dlon = Proj4js.common.adjust_lon(lon - this.long0);
    var x,y;

    if (this.sphere)
    {
       x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
       y = this.y0 + this.a * Math.sin(lat) / Math.cos(this.lat_ts);
    }
    else
    { // Radius at this latitude
      var Sin_Lat = Math.sin(lat);
      var Rn = this.a * (Math.sqrt(1.0e0 - this.es * Sin_Lat*Sin_Lat));

      x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
      y = this.y0 + Rn * Math.sin(lat) / Math.cos(this.lat_ts);
    }

    p.x=x;
    p.y=y;
    return p;
  },//ceaFwd()


_______________________________________________
MetaCRS mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/metacrs
Mike Adair

Re: Re: Adding Projection Classes to Proj4js

Reply Threaded More More options
Print post
Permalink
Hi Richard,

Thanks for this,  I don't know about the math involved here but the
coding looks fine.  It's best to have an independent test point to check
this against and you could add that to proj4js/test/testdata.js.  I
wouldn't want to add this without both the forward and inverse
transforms however, can you do that one as well?

The best place to put this is as a patch on the Proj4js trac instance
at: http://trac.osgeo.org/proj4js/,  create a new ticket and add a patch
as an attachment.

Mike





Richard Marsden wrote:

> Further to last night's email, I now have an implementation of the cea
> "Cylindrical Equal Area" projection working. However it currently
> assumes a sphere.
>
> I believe I have the forward transform working for an ellipsoid (see
> below).
> Does this look correct?  I try to calculate the Earth's radius at the
> coord's latitude and use this for calculating the y ordinate.    This
> is not applied to the x ordinate because this would break the
> "cylindrical" nature of the projection.
>
> (I notice that many of the projections marked as untested, assume a
> spherical Earth)
>
> Personally I don't need the inverse transform, but I'm also not sure
> how to apply the ellipsoid correction to the inverse transform.
>
> I know the efficiency of the following code can be improved - eg.
> cos(lat_ts) could be cached in the initialisation function.
>
>
> Richard
> -------------------------------
>
>
>   /* Cylindrical Equal Area forward equations--mapping lat,long to x,y
>     ------------------------------------------------------------*/
>   forward: function(p) {
>     var lon=p.x;
>     var lat=p.y;
>     /* Forward equations
>       -----------------*/
>     dlon = Proj4js.common.adjust_lon(lon - this.long0);
>     var x,y;
>
>     if (this.sphere)
>     {
>        x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
>        y = this.y0 + this.a * Math.sin(lat) / Math.cos(this.lat_ts);
>     }
>     else
>     { // Radius at this latitude
>       var Sin_Lat = Math.sin(lat);
>       var Rn = this.a * (Math.sqrt(1.0e0 - this.es <http://this.es> *
> Sin_Lat*Sin_Lat));
>
>       x = this.x0 + this.a * dlon * Math.cos(this.lat_ts);
>       y = this.y0 + Rn * Math.sin(lat) / Math.cos(this.lat_ts);
>     }
>
>     p.x=x;
>     p.y=y;
>     return p;
>   },//ceaFwd()
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> MetaCRS mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/metacrs
>  

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

   Office: (613) 565-5056 x26
   [hidden email]
   http://www.dmsolutions.ca
   http://research.dmsolutions.ca


_______________________________________________
MetaCRS mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/metacrs
Richard Marsden

Re: Re: Adding Projection Classes to Proj4js

Reply Threaded More More options
Print post
Permalink
Thanks Mike.  I'll have a look when I return (currently on vacation!)

The problem with the inverse is knowing how to handle the ellipsoid rather than the sphere.
Perhaps with a pen and paper or some web searching, I can find the answer.

Richard


On Thu, Jul 30, 2009 at 3:07 PM, Mike Adair <[hidden email]> wrote:
Hi Richard,

Thanks for this,  I don't know about the math involved here but the coding looks fine.  It's best to have an independent test point to check this against and you could add that to proj4js/test/testdata.js.  I wouldn't want to add this without both the forward and inverse transforms however, can you do that one as well?

The best place to put this is as a patch on the Proj4js trac instance at: http://trac.osgeo.org/proj4js/,  create a new ticket and add a patch as an attachment.

Mike



_______________________________________________
MetaCRS mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/metacrs