[mapserver-users] Coverting lat/long to pixel

Hulbert, Brian brian.hulbert at linquest.com
Wed May 7 09:03:15 EDT 2008


Something else to consider if your map uses multiple (or switches between)
"projections".

 

My C# map application uses both equirectangular and orthographic
projections.  Therefore, I do the following before the lines of code that
Sandeep presented:

 

            // create a Mapserver pointObj for the point being converted

            pointObj pObj = new pointObj(location.LongitudeDeg,
location.LatitudeDeg, 0, 0);

 

            // create 2 projection objects - a From projection object (a
latlong projection) and a To projection object (the current projection) 

            projectionObj projectionFrom = new projectionObj("+proj=latlong
+ellps=WGS84 +datum=WGS84 +over");

            projectionObj projectionTo = new
projectionObj(m_baseMap.getProjection());

 

            // perform the projection of the point from the current
projection to a latlong projection; the point's x (lon) and y (lat) are
updated in place

            bool bSuccess = (((int)MS_RETURN_VALUE.MS_SUCCESS) ==
pObj.project(projectionFrom, projectionTo));

 

            if (bSuccess)

            {

                  // Sandeep's code here  

            }

            // cleanup temporary objects

            pObj.Dispose();

            projectionFrom.Dispose();

            projectionTo.Dispose();

 

Brian

 

From: mapserver-users-bounces at lists.osgeo.org
[mailto:mapserver-users-bounces at lists.osgeo.org] On Behalf Of Sucharita
Samuel
Sent: Wednesday, May 07, 2008 7:42 AM
To: Sandeep Kumar Jakkaraju
Cc: mapserver-users
Subject: Re: [mapserver-users] Coverting lat/long to pixel

 

  Thanks a lot Sandeep. I think the code works.

Regards,
Sucharita

On Wed, May 7, 2008 at 3:40 PM, Sandeep Kumar Jakkaraju
<sandeepkumar.jakkaraju at gmail.com> wrote:

 

Hi Sucharita 

 

 

these are example values........

 

 private double minlat=28.6023 ;
    private double minlon=77.2018 ; 
    private double maxlat=28.6382 ;
    private double maxlon=77.2493 ; 
    
    private int screenwidth=2156;
    private int screenheight=1674;
    private Point p;
    
       
    public Point convertLatLonToPixel(double lat,double lon)
    {
        double cellsizex = (maxlon-minlon)/screenwidth;
        double cellsizey = (maxlat-minlat)/screenheight;
        
        int ix = (int) ((lon-minlon)/cellsizex);
        int iy1 = (int) ((maxlat-lat)/cellsizex);
        int iy2 = (int) ((maxlat-lat)/cellsizey);
        int iy = (int) (iy1+iy2)/2;
        
        p = new Point(ix,iy);

return p;
}

 

 


 

On 5/7/08, Sucharita Samuel <iworktech.sucharita at gmail.com> wrote: 

 Hi Sandeep,
                   A code fragment will be really helpful.

Thanks,
Sucharita 





On Wed, May 7, 2008 at 3:20 PM, Sandeep Kumar Jakkaraju
<sandeepkumar.jakkaraju at gmail.com> wrote:

 

This can be done using simple interpolation also
....................................

 

On 5/7/08, Sucharita Samuel <iworktech.sucharita at gmail.com> wrote: 

Hi friends,
              Can somebody please help me with a code to convert the
latitude and longitude of a point to pixel co-ordinates? I am using ASP.NET
<http://asp.net/> . I have heard that GDAL has a method for this conversion.
MS4W comes with GDAL as its tools, but I don't know how to implement it in
C#.NET.
             

Thanks in advance,

Regards,
Sucharita

 

_______________________________________________
mapserver-users mailing list
mapserver-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users




-- 
Thanks
Regards

Sandeep Kumar Jakkaraju 
_______________________________________________
mapserver-users mailing list
mapserver-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users

 




-- 
Thanks
Regards

Sandeep Kumar Jakkaraju 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20080507/ab13444b/attachment-0001.html


More information about the mapserver-users mailing list