Monday, 15 August 2011

python 3.x - Python3 TKinter set Canvas coordinates shown -


I am working on creating a map's GUI representation, but there is a problem measuring the canvas correctly . I am currently mapping the Dubrovnik city and between latitude 42N to 43N and 18E and 19E between all points of Dubrovnik, is a latitude. I was wondering if there was any way to set the canvas so that there were coordinates (42,19) and lower right corner (43, 18) in the upper left corner of the window? Any help is greatly appreciated.

You can not do this, there is no built-in method to do this as far as I know. But you can certainly implement your own canvas that works by doing this

Like:.

  Category GeoCanvas (Tk.Canvas): def __init __ (self, master, uperleftcoords, bottomrightcoords, ** kwargs): canvas____ init __ (self, master, ** kwargs) self .minLat = uperleftcoords.getLat () self.maxLong = uperleftcoords.getLong () self.maxLat = bottomrightcoords.getLat () self.minLong = bottomrightcoords.getLong () self.width = ** kwargs ["width"] self.height = ** kwargs ["height"] self.geoWidth = self.maxLat - self.minLatself.geoHeight = self.maxLong - Self. MinLong def fromLatLong2pixels (self, coords): "coordinate" a "coordinate using a latitude / longitude coordinate for every pixel you want to attract every point you want to attract." "" If (not self.minLat & lt; = coords.getLat () & lt; = self.maxLat) or (not self.minLong & lt; = coords.getLong () & lt; = self.laxLong): Return no one else: deltaLat = coords.ge tLat () - self.minLat deltaLong = coords.getLong () - self.minLong latRatio = deltaLat / self.geoWidth longRatio = deltaLong / self.geoHeight X = latRation * self.width y = LongRatio * self.height Return X, Y  

Then you can override the drawing method that you use to convert each latitude / long coordinate to a point on your canvas Are there.


No comments:

Post a Comment