def coords_to_filename(self, longitude, latitude): """Given coordinates in decimal degrees, map to the closest filename""" if self.left_longitude > longitude or self.top_latitude < latitude: return None x_grid = MapUtils.int_trunc((longitude - self.left_longitude) * self.xscale / self.img_width) y_grid = MapUtils.int_trunc((self.top_latitude - latitude) * self.yscale / self.img_height) if not self.latfirst: temp = x_grid x_grid = y_grid y_grid = temp retstr = os.path.join(self.location, self.prefix + MapUtils.ohstring(x_grid, self.numdigits)) if self.usedash: retstr = retstr + "-" retstr = retstr + MapUtils.ohstring(y_grid, self.numdigits) + self.ext return retstr
def coords_to_filename(self, longitude, latitude): """Given a pair of coordinates in deg.mmss, map to the containing filename, e.g. q37122c2/012t0501.gif. """ latDeg = MapUtils.int_trunc(latitude) longDeg = MapUtils.int_trunc(-longitude) latMin = (latitude - latDeg) * 60. longMin = (-longitude - longDeg) * 60. # The 7.5 here is because of the 7.5 in the directory names above # (we're getting the offset of this image from the origin of # the 7.5-series map covered by the directory), # not the map series we're actually plotting now. longMinOrd = MapUtils.int_trunc(longMin / 7.5) latMinOrd = MapUtils.int_trunc(latMin / 7.5) dirname = "q" + MapUtils.ohstring(latDeg, 2) \ + MapUtils.ohstring(longDeg, 3) \ + chr(ord('a') + latMinOrd) + str(longMinOrd + 1) # Find the difference between our desired coordinates # and the origin of the map this directory represents. # The 7.5 here is because of the 7.5 in the directory names above. latMinDiff = latMin - (latMinOrd * 7.5) longMinDiff = longMin - (longMinOrd * 7.5) latOffset = MapUtils.int_trunc(latMinDiff * 10 / self.series) longOffset = MapUtils.int_trunc(longMinDiff * 10 / self.series) # Now calculate the current filename. # Note that series is either 7.5 or 15 if (self.series > 13): fileprefix = "024t" numcharts = 5 else: fileprefix = "012t" numcharts = 10 filename = fileprefix + MapUtils.ohstring(numcharts - longOffset, 2) \ + MapUtils.ohstring(numcharts - latOffset, 2) + self.img_ext return self.location + "/" + dirname + "/" + filename
def coords_to_filename(self, longitude, latitude): """Given a pair of coordinates in deg.mmss, map to the containing filename, e.g. q37122c2/012t0501.gif. """ latDeg = MapUtils.int_trunc(latitude) longDeg = MapUtils.int_trunc(-longitude) latMin = (latitude - latDeg) * 60. longMin = (-longitude - longDeg) * 60. # The 7.5 here is because of the 7.5 in the directory names above # (we're getting the offset of this image from the origin of # the 7.5-series map covered by the directory), # not the map series we're actually plotting now. longMinOrd = MapUtils.int_trunc(longMin / 7.5) latMinOrd = MapUtils.int_trunc(latMin / 7.5) dirname = "q" + MapUtils.ohstring(latDeg, 2) \ + MapUtils.ohstring(longDeg, 3) \ + chr(ord('a') + latMinOrd) + str(longMinOrd + 1) # Find the difference between our desired coordinates # and the origin of the map this directory represents. # The 7.5 here is because of the 7.5 in the directory names above. latMinDiff = latMin - (latMinOrd * 7.5) longMinDiff = longMin - (longMinOrd * 7.5) latOffset = MapUtils.int_trunc(latMinDiff * 10 / self.series) longOffset = MapUtils.int_trunc(longMinDiff * 10 / self.series) # Now calculate the current filename. # Note that series is either 7.5 or 15 if (self.series > 13): fileprefix = "024t" numcharts = 5 else: fileprefix = "012t" numcharts = 10 filename = fileprefix + MapUtils.ohstring(numcharts - longOffset, 2) \ + MapUtils.ohstring(numcharts - latOffset, 2) + self.img_ext return self.location + "/" + dirname + "/" + filename