Need help converting Goode to latlon

14 messages Options
Embed this post
Permalink
David Turover

Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
I have shapefiles made in ArcGIS that use the Interrupted Goode Homolosine
projection. I am trying to use libproj to reproject them to lat/lon, but the
resulting shapes do not align correctly to the corresponding features in
Google Earth. Everything is pulled to the west by a small amount near the
equator and a larger amount further away from the equator.

Example: http://segfault.cs.sonoma.edu/~dturover/gisbug/projectionError.jpg

The projection in ESRI format is Goode%20Homolosine%206378137%20sphere.prj
in that directory. The proj arguments that I am using to define Goode are:

+proj=goode +lon_0=0 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +units=m +no_defs

What sort of things might be going wrong here? How might I be able to
adjust whatever algorithm is being run to attempt to fix it? I am too new
to projections to know what is possible in these areas.

I see that the .prj file has a "<custom>" datum, but I do not know what
this implies or how to make sure proj is using it. The custom datum is:
DATUM[
        "<custom>",
        SPHEROID[
                "WGS_1984_Major_Auxiliary_Sphere",
                6378137.0,0.0
        ]
]

Also, proj -lP lists PCyl and Sph as different projection classes under
+proj=goode but I cannot find anything in the proj4 documentation on
how to specify a projection class. The .prj file says that I should be
using a spherical projection. If proj defaults to a pseudocylindrical
algorithm for Goode, would it produce different results? If so, how
could I force it to run a spherical algorithm?

Thanks in advance for any help.

 - David T.
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
Gerald I. Evenden

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
On Wednesday 22 July 2009 2:39:52 am David Turover wrote:
> I have shapefiles made in ArcGIS that use the Interrupted Goode Homolosine
> projection. I am trying to use libproj to reproject them to lat/lon, but
> the resulting shapes do not align correctly to the corresponding features
> in Google Earth. Everything is pulled to the west by a small amount near
> the equator and a larger amount further away from the equator.
>
> Example: http://segfault.cs.sonoma.edu/~dturover/gisbug/projectionError.jpg

The projection in the above jpeg looks like Near-sided perspective.  At any
rate, it certainly is not Goode's pseudocylindrical Homolosine.

> The projection in ESRI format is Goode%20Homolosine%206378137%20sphere.prj
> in that directory. The proj arguments that I am using to define Goode are:
>
> +proj=goode +lon_0=0 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +units=m +no_defs

+b= is not necessary as Goode is only available as a spherical earth and +b is
the minor axis of an ellipsoidal earth.

> What sort of things might be going wrong here? How might I be able to
> adjust whatever algorithm is being run to attempt to fix it? I am too new
> to projections to know what is possible in these areas.
>
> I see that the .prj file has a "<custom>" datum, but I do not know what
> this implies or how to make sure proj is using it. The custom datum is:
> DATUM[
>         "<custom>",
>         SPHEROID[
>                 "WGS_1984_Major_Auxiliary_Sphere",
>                 6378137.0,0.0
>         ]
> ]

At this point, and especially at global scales, I do not think you need to
worry about datums.

> Also, proj -lP lists PCyl and Sph as different projection classes under
> +proj=goode but I cannot find anything in the proj4 documentation on
> how to specify a projection class.

PCyl : pseudocylindrical

Sph: spherical earth

Just FYI info and not something you specify in selecting a projection.

> The .prj file says that I should be
> using a spherical projection. If proj defaults to a pseudocylindrical
> algorithm for Goode, would it produce different results? If so, how
> could I force it to run a spherical algorithm?
>
> Thanks in advance for any help.

Help is very difficult because of the confusion caused by the jpeg figure.  
Certainly a Goode projection is not going to come anyway come near matching
your referenced jpeg figure except in a very limited form near the center of
the projection.  See:

http://www.csiss.org/map-projections/Pseudocylindrical/Goode_Homolosine_a.pdf

--
The whole religious complexion of the modern world is due
to the absence from Jerusalem of a lunatic asylum.
-- Havelock Ellis (1859-1939) British psychologist
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
support.mn

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
In reply to this post by David Turover
David Turover [[hidden email]] kirjoitti:
>
> Example: http://segfault.cs.sonoma.edu/~dturover/gisbug/projectionError.jpg
>
>
> +proj=goode +lon_0=0 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +units=m +no_defs
>

If the lon_0 parameter should be -90, since that is on USA??

Janne. - MNS Support

_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
David Turover

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
In reply to this post by Gerald I. Evenden
On Wed, Jul 22, 2009 at 10:04:18AM -0400, Gerald I. Evenden wrote:
> On Wednesday 22 July 2009 2:39:52 am David Turover wrote:
> >
> > Example: http://segfault.cs.sonoma.edu/~dturover/gisbug/projectionError.jpg
>
> The projection in the above jpeg looks like Near-sided perspective.  At any
> rate, it certainly is not Goode's pseudocylindrical Homolosine.

The jpeg is the result of attempting to reproject from Goode to geographic
coordinates. I have confirmed with an ESRI tool that the original shape is
in Goode, so the problem is in my use of proj.

Additional notes:

+proj=sinu produces similar results except that the tip of South America
is pulled further west. Since sinu is the middle half of goode and the
polar regions use a different algorithm, this should be expected.
However, it may be worth mentioning that I can't get sinu to match the
country shapes to their borders either.

Most tweaks that I attempted to make to the proj arguments resulted in
no change in the output, including turning off +no_defs and giving both
the input and output projections the same datum "+datum=WGS84".

I had the output projection as a null string to default to geographical
coordinates. "+proj=latlon +units=degrees" gives the same result.

Overstating +a (the earth's radius?) will pull shapes to the east as
they are stretched, including things at the equator that were well
placed before.

"+lon_0=-90" drew the South America shapes in the middle of the Pacific
Ocean. This makes sense since the original projection is based on the
Greenwich meridian, so this just moved everything west.

I turned on the PROJ_DEBUG environment variable but the only notice it
gave was that proj_def.dat could not be opened. I fixed this by exporting
PROJ_LIB so it searched in the right place. This did not affect the
projection.

The ESRI projection definition includes an option named "Option" that
is set to 1. This does not sound very important, but might it have an
effect?


 - David T.
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
support.mn

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
In reply to this post by David Turover
David Turover [[hidden email]] kirjoitti:
> "+lon_0=-90" drew the South America shapes in the middle of the Pacific
> Ocean. This makes sense since the original projection is based on the
> Greenwich meridian, so this just moved everything west.
>

Sure, but did the shape get any better? Some projections distort when
they are off the center. If the result is just shifted it is easy to fix that by
for example giving some flase easting (x_0=...).

1) Try to get right shape.
2) Shift and resize it to the right place.

Janne / MNS SUpport

_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
Gerald I. Evenden

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
In reply to this post by David Turover
On Thursday 23 July 2009 1:14:46 am David Turover wrote:

> On Wed, Jul 22, 2009 at 10:04:18AM -0400, Gerald I. Evenden wrote:
> > On Wednesday 22 July 2009 2:39:52 am David Turover wrote:
> > > Example:
> > > http://segfault.cs.sonoma.edu/~dturover/gisbug/projectionError.jpg
> >
> > The projection in the above jpeg looks like Near-sided perspective.  At
> > any rate, it certainly is not Goode's pseudocylindrical Homolosine.
>
> The jpeg is the result of attempting to reproject from Goode to geographic
> coordinates. I have confirmed with an ESRI tool that the original shape is
> in Goode, so the problem is in my use of proj.

I am sorry, but the above sentence makes no sense to me.  What does the jpeg
figure have to do with anything then?  It is not a representation
of "geographic coordinates" but a display of said coordinates in a particular
projection.

It would appear that your original data is in Goode projection coordinates and
you want to *inverse project* these values to geographic coordinate.

> Additional notes:
>
> +proj=sinu produces similar results except that the tip of South America
> is pulled further west. Since sinu is the middle half of goode and the
> polar regions use a different algorithm, this should be expected.
> However, it may be worth mentioning that I can't get sinu to match the
> country shapes to their borders either.

Goode's projection is a combination of the the Sinusoidal projection for
    |latitude|<40°44'
and Mollweide for all other latitudes.  It is most often used in an interupted
form.

> Most tweaks that I attempted to make to the proj arguments resulted in
> no change in the output, including turning off +no_defs and giving both
> the input and output projections the same datum "+datum=WGS84".

If you were using lproj then:

lproj -I +proj=goode +lon_0=90 +R=val <input_cart.dat >output_geog.dat

The radius val needs to be determined based upon the cartesian units and scale
of your cartesian input data.  Output in output.dat will be geographic
coordinates.  +a may be substituded for +R.  lon_0 is based upon the central
meridian used in the original Goode projection.

The lproj usage should apply to Warmardam's proj.  +no_defs should not make
any difference in this case.  lon_0 and R (a) are the only two options that
really make any difference with this projection.  Note: if proj were as I
originally wrote it, then executing proj would be identical to the lproj
execition.

> I had the output projection as a null string to default to geographical
> coordinates. "+proj=latlon +units=degrees" gives the same result.
>
> Overstating +a (the earth's radius?) will pull shapes to the east as
> they are stretched, including things at the equator that were well
> placed before.

I should "stretch" things in all directions!!!

> "+lon_0=-90" drew the South America shapes in the middle of the Pacific
> Ocean. This makes sense since the original projection is based on the
> Greenwich meridian, so this just moved everything west.

???

> I turned on the PROJ_DEBUG environment variable but the only notice it
> gave was that proj_def.dat could not be opened. I fixed this by exporting
> PROJ_LIB so it searched in the right place. This did not affect the
> projection.
>
> The ESRI projection definition includes an option named "Option" that
> is set to 1. This does not sound very important, but might it have an
> effect?

I think there is a great communication problem here.

Basic questions:

1. what are the original coordinates you are dealing with?  Goode cartesian?
2. What is the central meridian used by the Goode projection to create these
coodinates?
3. What earth radius and units were used in the projection?

These questions *must* be answered before using any projection procedure.

--
The whole religious complexion of the modern world is due
to the absence from Jerusalem of a lunatic asylum.
-- Havelock Ellis (1859-1939) British psychologist
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
Gerald I. Evenden

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
In reply to this post by David Turover
ERROR ERROR ERROR

Please my correct previous email on this thread.

Regarding the lproj execution line, it should read:

lproj -I +proj=goode +lon_0=-90 +R=val <input_cart.dat >output_geog.dat


Note sigh of +lon_0 value.

I've been spending too much time with US and Canadian datum correction
processes.  :-(

--
The whole religious complexion of the modern world is due
to the absence from Jerusalem of a lunatic asylum.
-- Havelock Ellis (1859-1939) British psychologist
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
David Turover

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
In reply to this post by Gerald I. Evenden
On Thu, Jul 23, 2009 at 10:56:19AM -0400, Gerald I. Evenden wrote:
> On Thursday 23 July 2009 1:14:46 am David Turover wrote:
> > The jpeg is the result of attempting to reproject from Goode to geographic
> > coordinates. I have confirmed with an ESRI tool that the original shape is
> > in Goode, so the problem is in my use of proj.
>
> I am sorry, but the above sentence makes no sense to me.  What does the jpeg
> figure have to do with anything then?  It is not a representation
> of "geographic coordinates" but a display of said coordinates in a particular
> projection.

The jpeg shows my Goode-to-latlon results laid onto Google Earth as
coordinate-based KML so my output can be compared against Google Earth's
known-good representations of country positions in lat/lon coordinates.
Since they do not line up, I am doing something wrong. I hoped the picture
might offer more experienced people a hint as to the specific problem.

> It would appear that your original data is in Goode projection coordinates
> and you want to *inverse project* these values to geographic coordinate.

I forgot to mention that I have been adding "+inv" to the proj arguments
programmatically. When I get into work I will make sure this is working
and I will also try leaving it off to see if that makes a difference.
Let's watch this be the source of the problem since it is something that
I should have mentioned two days ago.

> I think there is a great communication problem here.
>
> Basic questions:
>
> 1. what are the original coordinates you are dealing with?  Goode cartesian?
> 2. What is the central meridian used by the Goode projection to create these
> coodinates?
> 3. What earth radius and units were used in the projection?
>
> These questions *must* be answered before using any projection procedure.

1. The input projection is "Goode_Homolosine_6378137_sphere". The coordinate
values are decimal numbers six figures long plus a fractional amount. The
full projection definition is here:
http://segfault.cs.sonoma.edu/~dturover/gisbug/Goode%20Homolosine%206378137%20sphere.prj

2. The central meridian is Greenwich.

3. Input units are meters, output units are degrees. The earth radius in
the input projection is 6378137.0.


 - David T.
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
Gerald I. Evenden

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
On Thursday 23 July 2009 1:12:02 pm David Turover wrote:

> On Thu, Jul 23, 2009 at 10:56:19AM -0400, Gerald I. Evenden wrote:
> > On Thursday 23 July 2009 1:14:46 am David Turover wrote:
> > > The jpeg is the result of attempting to reproject from Goode to
> > > geographic coordinates. I have confirmed with an ESRI tool that the
> > > original shape is in Goode, so the problem is in my use of proj.
> >
> > I am sorry, but the above sentence makes no sense to me.  What does the
> > jpeg figure have to do with anything then?  It is not a representation of
> > "geographic coordinates" but a display of said coordinates in a
> > particular projection.
>
> The jpeg shows my Goode-to-latlon results laid onto Google Earth as
> coordinate-based KML so my output can be compared against Google Earth's
> known-good representations of country positions in lat/lon coordinates.
> Since they do not line up, I am doing something wrong. I hoped the picture
> might offer more experienced people a hint as to the specific problem.

I do not know when Google became the benchmark for projection stardards but
that is another issue.  Secondly, comparing results graphically, especially
with a projection like nsper, leaves something to be desired.

In the future, I woult strongly suggest that in seeking verification of
projection operations that a short, randomly selected collection of the
source data values being converted be given and simply ask for a conversion
of these values from a knowledgeable source.

> > It would appear that your original data is in Goode projection
> > coordinates and you want to *inverse project* these values to geographic
> > coordinate.
>
> I forgot to mention that I have been adding "+inv" to the proj arguments
> programmatically. When I get into work I will make sure this is working
> and I will also try leaving it off to see if that makes a difference.
> Let's watch this be the source of the problem since it is something that
> I should have mentioned two days ago.

I have no idea what "+inv" is so I assume it is part of Warmerdam's version.  
Early proj and lproj use -I runline option to designate inverse projection.

#!/bin/bash
# run off a few test examples of Goode projection
lproj +proj=goode +R=6378137.0 <<EOF >test_cart.dat
0 45
-80 30
-120 -10
60 50
10 10
EOF
#
# run the cartesian file back to geographic coordinates
#
lproj -I +proj=goode +R=6378137.0 <test_cart.dat >test_geog.dat
#
echo done

after running above script:

gie@charon:~/tmp$ m *.dat
::::::::::::::
test_cart.dat
::::::::::::::
0.00    5003479.28
-7712440.56     3339584.72
-13155395.71    -1113194.91
4563799.12      5536706.32
1096282.98      1113194.91
::::::::::::::
test_geog.dat
::::::::::::::
0dE     45dN
80dW    30dN
120dW   10dS
60dE    50dN
10dE    10dN
gie@charon:~/tmp$

OK?

> > I think there is a great communication problem here.
> >
> > Basic questions:
> >
> > 1. what are the original coordinates you are dealing with?  Goode
> > cartesian? 2. What is the central meridian used by the Goode projection
> > to create these coodinates?
> > 3. What earth radius and units were used in the projection?
> >
> > These questions *must* be answered before using any projection procedure.
>
> 1. The input projection is "Goode_Homolosine_6378137_sphere". The
> coordinate values are decimal numbers six figures long plus a fractional
> amount. The full projection definition is here:
> http://segfault.cs.sonoma.edu/~dturover/gisbug/Goode%20Homolosine%206378137
>%20sphere.prj
>
> 2. The central meridian is Greenwich.
>
> 3. Input units are meters, output units are degrees. The earth radius in
> the input projection is 6378137.0.
>
>
>  - David T.
> _______________________________________________
> Proj mailing list
> [hidden email]
> http://lists.maptools.org/mailman/listinfo/proj



--
The whole religious complexion of the modern world is due
to the absence from Jerusalem of a lunatic asylum.
-- Havelock Ellis (1859-1939) British psychologist
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
support.mn

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
In reply to this post by David Turover
Hello

I am almost 100% sure that the problem is wrong central
meridian, since the resulting picture shows increasing
error to the north and south. Goode projection does just
that if the central meridian (lon_0) is wrong.

The data is on Americas and that uses usually lon_0=-90.
If the inverse uses lon_0=0, the distortion is evident.

Do some experimenting with lon_0 (central meridian).

Janne. / MNS Support
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
Eric Miller

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
In reply to this post by Gerald I. Evenden
>>> On 7/23/2009 at 11:18 AM, "Gerald I. Evenden" <[hidden email]>
wrote:
> On Thursday 23 July 2009 1:12:02 pm David Turover wrote:

>> I forgot to mention that I have been adding "+inv" to the proj arguments
>> programmatically. When I get into work I will make sure this is working
>> and I will also try leaving it off to see if that makes a difference.
>> Let's watch this be the source of the problem since it is something that
>> I should have mentioned two days ago.
>
> I have no idea what "+inv" is so I assume it is part of Warmerdam's version.
>  
> Early proj and lproj use -I runline option to designate inverse projection.

As far as I can tell +inv is not a valid argument.  It just gets passed to the projection initialization
routine which then ignores it.  The -I flag is still the correct way to tell "proj" program to do an inverse
projection.

Programmatically, you must use pj_inv to do an inverse projection (or use pj_transform).

--

Eric G. Miller
Staff Programmer
CA Dept. of Fish & Game


_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
Melita Kennedy

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
In reply to this post by David Turover


-----Original Message-----

>Message: 2
>Date: Wed, 22 Jul 2009 22:14:46 -0700
>From: David Turover <[hidden email]>
>Subject: Re: [Proj] Need help converting Goode to latlon
>To: [hidden email]
>Message-ID: <[hidden email]>
>Content-Type: text/plain; charset=us-ascii
>
>On Wed, Jul 22, 2009 at 10:04:18AM -0400, Gerald I. Evenden wrote:
>> On Wednesday 22 July 2009 2:39:52 am David Turover wrote:
>> >
>> > Example: http://segfault.cs.sonoma.edu/~dturover/gisbug/projectionError.jpg
>>
>> The projection in the above jpeg looks like Near-sided perspective.  At any
>> rate, it certainly is not Goode's pseudocylindrical Homolosine.
>
>The jpeg is the result of attempting to reproject from Goode to geographic
>coordinates. I have confirmed with an ESRI tool that the original shape is
>in Goode, so the problem is in my use of proj.
>
>Additional notes:
>
>+proj=sinu produces similar results except that the tip of South America
>is pulled further west. Since sinu is the middle half of goode and the
>polar regions use a different algorithm, this should be expected.
>However, it may be worth mentioning that I can't get sinu to match the
>country shapes to their borders either.
>
>Most tweaks that I attempted to make to the proj arguments resulted in
>no change in the output, including turning off +no_defs and giving both
>the input and output projections the same datum "+datum=WGS84".
>
>I had the output projection as a null string to default to geographical
>coordinates. "+proj=latlon +units=degrees" gives the same result.
>
>Overstating +a (the earth's radius?) will pull shapes to the east as
>they are stretched, including things at the equator that were well
>placed before.
>
>"+lon_0=-90" drew the South America shapes in the middle of the Pacific
>Ocean. This makes sense since the original projection is based on the
>Greenwich meridian, so this just moved everything west.
>
>I turned on the PROJ_DEBUG environment variable but the only notice it
>gave was that proj_def.dat could not be opened. I fixed this by exporting
>PROJ_LIB so it searched in the right place. This did not affect the
>projection.
>
>The ESRI projection definition includes an option named "Option" that
>is set to 1. This does not sound very important, but might it have an
>effect?
>
>
> - David T.

David,

The 'option' parameter is used to determine whether to use the 'land' or
'ocean' version. That is, if '1', the interruptions will occur in the oceans.
If '2', the interruptions will occur on land. The standard Goode's (land) prj
file is using WGS84, so the radius is 6378137.0.

Melita Kennedy
ESRI, Inc.
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
Gerald I. Evenden

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
On Thursday 23 July 2009 4:23:07 pm Melita Kennedy wrote:
> -----Original Message-----
>
> >Message: 2
        ...
>
> The 'option' parameter is used to determine whether to use the 'land' or
> 'ocean' version. That is, if '1', the interruptions will occur in the
> oceans. If '2', the interruptions will occur on land. The standard Goode's
> (land) prj file is using WGS84, so the radius is 6378137.0.
>
> Melita Kennedy
> ESRI, Inc.

If the interupted version of Goode is used then *NO* standard version of
[l]proj will handle it without the user segmenting the data into the
subregions of the interuptions.

A closer examination of jpeg does seem to verify the idea of an interrupted
projection.

As an aside, for the America continents segment: +lon_0=-100.  In addition,
one needs the appropriate +x_0=-1.745329 for unit sphere (multiply that value
by the radius used to get a proper value for this case).  These values apply
for Goode's land map.

In addition, because of the wide variation of segmentation used, it is not
likely that a proj inverse for segmented projections will be an integral part
of the basic software.

--
The whole religious complexion of the modern world is due
to the absence from Jerusalem of a lunatic asylum.
-- Havelock Ellis (1859-1939) British psychologist
_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj
David Turover

Re: Need help converting Goode to latlon

Reply Threaded More More options
Print post
Permalink
On Thu, Jul 23, 2009 at 07:37:55PM -0400, Gerald I. Evenden wrote:
> If the interupted version of Goode is used then *NO* standard version of
> [l]proj will handle it without the user segmenting the data into the
> subregions of the interuptions.

Thanks. If attachments work on this list, this post should carry a
rough modified version of PJ_goode which seems to work for at least
the three regions that I'm working in. I have not tested it more fully.

 - David T.

#ifndef lint
static const char SCCSID[]="@(#)PJ_goode.c 4.1 94/02/15     GIE     REL";
#endif
#define PROJ_PARMS__ \
        struct PJconsts *sinu; \
        struct PJconsts *moll;
#define PJ_LIB__
#include <projects.h>
PROJ_HEAD(goode_interrupted, "Goode Homolosine Interrupted") "\n\tPCyl, Sph.";
        C_NAMESPACE PJ
*pj_sinu(PJ *), *pj_moll(PJ *);
#define Y_COR 0.05280
#define PHI_LIM .71093078197902358062

/* Goode interruption parameters from:
 * http://edc2.usgs.gov/1KM/goodesarticle.php
 * A goode map for visual reference is Figure 5 from here:
 * http://proceedings.esri.com/library/userconf/proc98/proceed/to850/pap844/p844.htm
 */
static const double goode_center_x_for_region[] = {
         0, /* Default. */
        /* Use radians. */
        PI * -100.0 / 180.0,  /* Region 1 */
        PI *   30.0 / 180.0,  /* Region 2 */
        PI * -100.0 / 180.0,  /* Region 3 */
        PI *   30.0 / 180.0,  /* Region 4 */
        PI * -160.0 / 180.0,  /* Region 5 */
        PI * - 60.0 / 180.0,  /* Region 6 */
        PI *   20.0 / 180.0,  /* Region 7 */
        PI *  140.0 / 180.0,  /* Region 8 */
        PI * -160.0 / 180.0,  /* Region 9 */
        PI * - 60.0 / 180.0,  /* Region 10*/
        PI *   20.0 / 180.0,  /* Region 11*/
        PI *  140.0 / 180.0,  /* Region 12*/
};

int goode_get_region_from_lat_lon(double lat, double lon){
        if(lon > 0 ){ /* North */
                if(lon > 0.45259259259 * PI){ /* Norther */
                        if(lat < -.2222222222 * PI){
                                return 1;
                        } else {
                                return 2;
                        }
                } else {
                        /* Note: Duped code */
                        if(lat < -.2222222222 * PI){
                                return 3;
                        } else {
                                return 4;
                        }
                }

        } else { /* South */
                if(lon > -0.45259259259 * PI){ /* First section south of equator */
                        if(lat < .1111111111 * PI){
                                if(lat < -.8888888888 * PI){
                                        return 5;
                                } else {
                                        return 6;
                                }
                        } else {
                                if(lat < .7777777777 * PI){
                                        return 7;
                                } else {
                                        return 8;
                                }
                        }
                } else {
                        /* Note: Duped code */
                        if(lat < .1111111111 * PI){
                                if(lat < -.8888888888 * PI){
                                        return 9;
                                } else {
                                        return 10;
                                }
                        } else {
                                if(lat < .7777777777 * PI){
                                        return 11;
                                } else {
                                        return 12;
                                }
                        }
                }
        }
        return 0;
}

/* Macro alternative to the function. */
/* Note: Using a macro does not appear to save much time. */
#define GOODE_REGION_FROM_LATLON(lat, lon) \
( \
        (lon > 0.0) \
        ?( \
                1 + \
                ( 0x01 & (lat > (- PI * 40.0 / 180.0)) \
                | 0x02 & (lon < (PI * (40.0 + 44.0/60.0) / 90.0 )) \
                ) \
        ):( \
                5 +  \
                ( 0x01 & (lat < (PI * 140.0 / 180.0)) \
                | 0x02 & (lat > (PI * 20.0 / 180.0)) \
                | 0x04 & (lon < (- PI * (40.0 + 44.0/60.0) / 90.0 )) \
                )\
        )\
)
               

FORWARD(s_forward); /* spheroid */
        /* int goode_current_region = goode_get_region_from_lat_lon(lp.lam, lp.phi); */
        int goode_current_region = GOODE_REGION_FROM_LATLON(lp.lam, lp.phi);
       
        fprintf(stderr, "In forward, sinu %x moll %x reg %d, lam0 %.4f, l,p are: %.4f, %.4f\n",
        P->sinu, P->moll,
        goode_current_region, P->lam0, lp.lam, lp.phi);

        lp.lam -= goode_center_x_for_region[goode_current_region];

        if (fabs(lp.phi) <= PHI_LIM)
                xy = P->sinu->fwd(lp, P->sinu);
        else {
                xy = P->moll->fwd(lp, P->moll);
                xy.y -= lp.phi >= 0.0 ? Y_COR : -Y_COR;
        }

        fprintf(stderr, "In forward after mods lam0 %.4f, x,y are: %.4f, %.4f lp is %.4f, %.4f\n",
        P->lam0, xy.x, xy.y, lp.lam, lp.phi);

        xy.x += goode_center_x_for_region[goode_current_region];
        return (xy);
}
INVERSE(s_inverse); /* spheroid */
        /* int goode_current_region = goode_get_region_from_lat_lon(xy.x, xy.y);*/
        int goode_current_region = GOODE_REGION_FROM_LATLON(xy.x, xy.y);

        fprintf(stderr, "In inverse, reg %d, x,y are: %.4f, %.4f\n",
        goode_current_region, xy.x, xy.y);

        xy.x -= goode_center_x_for_region[goode_current_region];

        if (fabs(xy.y) <= PHI_LIM)
                lp = P->sinu->inv(xy, P->sinu);
        else {
                xy.y += xy.y >= 0.0 ? Y_COR : -Y_COR;
                lp = P->moll->inv(xy, P->moll);
        }

        fprintf(stderr, "In inverse after mods lam0 %.4f, x,y are: %.4f, %.4f lp is %.4f, %.4f\n",
        P->lam0, xy.x, xy.y, lp.lam, lp.phi);

        lp.lam += goode_center_x_for_region[goode_current_region];
        return (lp);
}
FREEUP;
        if (P) {
                if (P->sinu)
                        (*(P->sinu->pfree))(P->sinu);
                if (P->moll)
                        (*(P->moll->pfree))(P->moll);
                pj_dalloc(P);
        }
}
ENTRY2(goode_interrupted, sinu, moll)
        P->es = 0.;
        if (!(P->sinu = pj_sinu(0)) || !(P->moll = pj_moll(0)))
                E_ERROR_0;
        if (!(P->sinu = pj_sinu(P->sinu)) || !(P->moll = pj_moll(P->moll)))
                E_ERROR_0;
        P->fwd = s_forward;
        P->inv = s_inverse;
ENDENTRY(P)

_______________________________________________
Proj mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/proj