[Proj] pj_transform function

Sandeep Kumar Jakkaraju sandeepkumar.jakkaraju at gmail.com
Fri Oct 6 22:24:41 PDT 2006


Hi

I am doing this ....

I have lat/lon of Top Left Corner of the Map and  Bottom Right Corner of The
Map
iam converting them to projected X,Y using this projection defintion

World Mercator <54004> +proj=merc +latts=0 +lon0=0 +k=1.000000 +x0=0
+y0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs <>

( I have found on some site that Google Maps use this projection !!)


For example:

       tl_lat = 42.8483;
       tl_lon = -74.2935;
       br_lat = 42.3813;
       br_lon = -73.6509;


using pj_transform of proj4.. iam converting them to X,Y.


top left xy

-8270314.5893 , 5259843.0071

btm right xy

-8198780.6845 , 5189458.4882

I calculate the Centre cX,cY using the top left X,Y and Btm right X,Y...

The Size of the Image I have generated from the Map is (1031,801)...

width = absolute value of (btm right X - top left X)

height = absolute value of (btm right Y - top left Y)

Now I am trying to get the pixel x,y from the projected X,Y using this
formula

       px = 515.5 +  (1031/width)*(X-cX);
       py = 400.5  -  (801/height)*(Y-cY);

This gives correct pixels if i give top left or bottom right or the centre
X,Y...

But for some point inside the Image ...

the calcualted pixel X is some 2/3 pixels away from actual pixel X

the calcualted pixel Y is some 8/10 pixels away from actual pixel Y

where am I going wrong ... is the projection iam using correct for such
calculations ..???



Thanks in advance.

sandeep


On 10/6/06, Gerald I. Evenden <gerald.evenden at verizon.mail> wrote:
>
> On Friday 06 October 2006 4:38 am, Hugo Tyson wrote:
> > proj-bounces at lists.maptools.org <> wrote:
> > > I want to transform ... this lat/lon 39.739/-104.985...
> > > to world mercator project ..with the defintition
> > >
> > > World Mercator <54004> +proj=merc +latts=0 +lon0=0
> > > +k=1.000000 +x0=0 +y0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs <>
> > >
> > > but the method gives an "error"....
> > >
> > > this method works fine if i give lat/lon say 42.4182,-74.2643
> >
> > I've not heard of "world mercator", but looking at the parameters
> > it's projecting into a plane tangent to the sphere at lat 0, lon 0.
> > So it only works for longitudes from -90 to +90 (though these map
> > to infinities in the projected plane).
> >
> > Your example of -104 longitude is around the back of the earth,
> > on the "far side" from the projection plane.   Therefore a
> > line from the origin through the point never intersects the
> > projection plane, so no result can be calculated.  Hence your
> > error.  Lon -74 is in range, so it's OK.
>
> Excuse me for jumping into the middle of this discussion, but Mercator and
> normal proj functioning span the range of +-180 degrees longitude.  The
> plane
> of the cylindrical projection projection is "unwrapped" from a cut on the
> projection cylinder opposite the longitude of the central meridian (CM) or
> 180 degrees from the CM.  There is no such thing as the '"far side"' of
> the
> projection.
>
> The following is an example:
>
> gie at charon:~$ lproj +proj=merc +ellps=WGS84
> -104.985 39.739
> -11686876.74    4800765.45
> -74.2643 42.4182
> -8267064.06     5195000.64
> gie at charon:~$
>
> All the other parameters in the original problem are superfluous as they
> are
> default values of proj/lproj.  The datum option is not part of the
> proj/lproj
> system.
> _______________________________________________
> Proj mailing list
> Proj at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/proj
>



-- 
Sandeep Kumar Jakkaraju
WeBlog:
http://jakkarajus.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/proj/attachments/20061007/18228931/attachment.html>


More information about the Proj mailing list