Display Lat / Lon on Mousemove

Topics: Algorithms, General Topics
Oct 15, 2008 at 7:00 PM
Edited Oct 15, 2008 at 7:01 PM
Hi,
I would like to display the Lat / Lon in a status bar on MouseMove.
A shapefile is loaded.
I have been able to get the map Extents okay which come out in lat / lon
Using the ImageToWorld and WorldToImage functions only returns values that are not lat / lon
  Either I am missing something or not doing something correctly
Thanks in advance for any assistance.

Coordinator
Oct 15, 2008 at 8:01 PM
It sounds like the coordinates in the shapefile are not in lat/lon. Is there an associated .prj file?
Oct 15, 2008 at 11:11 PM
Edited Oct 15, 2008 at 11:30 PM
Hi,
here is the text from the prj file

The MapExtents result is exactly what I expected in Lat / Lon

GEOGCS["Geographic Coordinate System",DATUM["NAD83",SPHEROID["GRS 1980",6378137,298.2572220960423]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]
Coordinator
Oct 16, 2008 at 1:24 AM
Hrm, it sure does look like Lat/Lon...

What is WorldToImage()/ImageToWorld() telling you?
Oct 16, 2008 at 2:05 AM
Edited Oct 16, 2008 at 3:50 AM
Here's the code and results


    Private Sub PicMap_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PicMap.MouseMove

        Dim p As SharpMap.Geometries.Point = Nothing
        Dim pt As System.Drawing.PointF = Nothing

        p = myMap.ImageToWorld(New System.Drawing.PointF(e.X, e.Y))
        pt = myMap.WorldToImage(New SharpMap.Geometries.Point(p.X, p.Y))

        ListBox1.Items.Clear()
        ListBox1.Items.Add(p.X & vbTab & p.Y)
        ListBox1.Items.Add(pt.X & vbTab & pt.Y)



Sample of Results:
-0.24066108       0.48132216
311                      402
or substituting p.x and p.y with e.x and e.y in WorldToImage
37896.71             -14958.25







Oct 17, 2008 at 11:02 PM
Edited Oct 17, 2008 at 11:03 PM
Anyone with an answer as to why Lat / Lon are not displayed ?

Would it help if I post the code C# ?


Buster95


Coordinator
Oct 18, 2008 at 12:04 PM
Hi Buster95, can you let me know what version you are using , whether it is a release or svn trunk, and also provide some test coordinates and expected results.. cheers jd
Oct 18, 2008 at 8:59 PM
Hi John.

The SharpMap.dll is V0.9.  I guess it's a release.   Don't know for sure.  Dated April 2007.

You can download the shapefile at www.micropath.com/downloads/orders/john

GetExtents returns:
MaxLat: 41.003445
MinLat 36.992427

MaxLon: -102.041486
MinLon: -109.060257

So, as the Mouse is moved, you would expect returned lat/lon values within the range of the min/max values returned by GetExtents

Appreciate your thoughts.

thanks,


Coordinator
Oct 19, 2008 at 11:16 AM
Hi again, I haven't tested it with the 0.9 release, but I tested it with DemoWinForm from 0.9 trunk and 1.1Experimental, both gave results within the expected range so I guess the release package has a very old Proj.net. Try getting a recent changeset from the sources tab and see how you go.. hth jd