def get_next_maplet(self, fullpathname, dX, dY):
     """Given a maplet's pathname, get the next or previous one.
     Does not currently work for jumps more than 1 in any direction.
     Returns pixbuf, newpath (either may be None).
     """
     pathname, filename = os.path.split(fullpathname)
     if (self.Debug):
         print "Generic get_next_maplet", filename, dX, dY
     name, ext = os.path.splitext(filename)
     # traceback.print_stack()
     mapb = int(name[-self.numdigits:])
     if self.usedash:
         mapa = int(name[-self.numdigits * 2 - 1: -self.numdigits - 1])
     else:
         mapa = int(name[-self.numdigits * 2: -self.numdigits])
     if self.latfirst:
         newa = MapUtils.ohstring(mapa + dX, self.numdigits)
         newb = MapUtils.ohstring(mapb + dY, self.numdigits)
     else:
         newa = MapUtils.ohstring(mapa + dY, self.numdigits)
         newb = MapUtils.ohstring(mapb + dX, self.numdigits)
     if self.usedash:
         newname = self.prefix + newa + "-" + newb
     else:
         newname = self.prefix + newa + newb
     newpath = os.path.join(self.location, newname + ext)
     if filename is None or not os.access(filename, os.R_OK):
         return None, newpath
     pixbuf = MapWindow.load_image_from_file(newpath)
     return pixbuf, newpath
 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
示例#3
0
    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
示例#4
0
    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
示例#5
0
    def get_next_maplet(self, fullpathname, dX, dY):
        """Given a maplet's pathname, get the next or previous one.
        Does not currently work for jumps more than 1 in any direction.
        Returns pixbuf, newpath (either may be None).
        """

        if (self.Debug):
            print("get_next_maplet:", fullpathname, dX, dY)
        pathname, filename = os.path.split(fullpathname)
        collecdir, mapdir = os.path.split(pathname)
        maplat = int(mapdir[1:3])
        maplon = int(mapdir[3:6])
        name, ext = os.path.splitext(filename)
        xdir = int(mapdir[-1])
        ydir = ord(mapdir[-2]) - ord('a')     # convert from letter a-h
        if self.series == 7.5:
            serstr = self.ser7prefix
            grid = 10
        else:
            serstr = self.ser15prefix
            grid = 5

        x = int(name[-4:-2]) + dX
        y = int(name[-2:]) + dY

        if x < 1:
            x = grid
            xdir = xdir + 1
            if xdir > 8:
                xdir = 1
                if self.Debug:
                    print(mapdir, name, ": wrapping mapdir coordinates -x", end=' ')
                    print(maplon)
                maplon = str(int(maplon) + 1)
        if x > grid:
            x = 1
            xdir = xdir - 1
            if xdir < 1:
                xdir = 8
                if self.Debug:
                    print(mapdir, name, ": wrapping mapdir coordinates +x", end=' ')
                    print(maplon)
                maplon = str(int(maplon) - 1)

        if y > grid:
            y = 1
            ydir = ydir - 1
            if ydir < 0:
                ydir = 7
                if self.Debug:
                    print(mapdir, name, ": wrapping mapdir coordinates +y", end=' ')
                    print(maplat)
                maplat = str(int(maplat) - 1)

        if y < 1:
            y = grid
            ydir = ydir + 1
            if ydir > 7:
                ydir = 0
                if self.Debug:
                    print(mapdir, name, ": wrapping mapdir coordinates -y", end=' ')
                    print(maplat)
                maplat = str(int(maplat) + 1)

        # We're ready to piece the filename back together!
        newpath = os.path.join(collecdir,
                               "q" + MapUtils.ohstring(maplat, 2)
                                   + MapUtils.ohstring(maplon, 3)
                                   + chr(ydir + ord('a')) + str(xdir),
                               serstr + MapUtils.ohstring(x, 2)
                                   + MapUtils.ohstring(y, 2) + ext)
        if not os.access(newpath, os.R_OK):
            if self.Debug:
                print("get_next_maplet(", fullpathname, dX, dY, ")")
                print("  Can't open", newpath)
            return None, newpath

        pixbuf = MapWindow.load_image_from_file(newpath)
        return pixbuf, newpath
示例#6
0
    def get_next_maplet(self, fullpathname, dX, dY):
        """Given a maplet's pathname, get the next or previous one.
        Does not currently work for jumps more than 1 in any direction.
        Returns pixbuf, newpath (either may be None).
        """

        if (self.Debug):
            print "get_next_maplet:", fullpathname, dX, dY
        pathname, filename = os.path.split(fullpathname)
        collecdir, mapdir = os.path.split(pathname)
        maplat = int(mapdir[1:3])
        maplon = int(mapdir[3:6])
        name, ext = os.path.splitext(filename)
        xdir = int(mapdir[-1])
        ydir = ord(mapdir[-2]) - ord('a')     # convert from letter a-h
        if self.series == 7.5:
            serstr = self.ser7prefix
            grid = 10
        else:
            serstr = self.ser15prefix
            grid = 5

        x = int(name[-4:-2]) + dX
        y = int(name[-2:]) + dY

        if x < 1:
            x = grid
            xdir = xdir + 1
            if xdir > 8:
                xdir = 1
                if self.Debug:
                    print mapdir, name, ": wrapping mapdir coordinates -x",
                    print maplon
                maplon = str(int(maplon) + 1)
        if x > grid:
            x = 1
            xdir = xdir - 1
            if xdir < 1:
                xdir = 8
                if self.Debug:
                    print mapdir, name, ": wrapping mapdir coordinates +x",
                    print maplon
                maplon = str(int(maplon) - 1)

        if y > grid:
            y = 1
            ydir = ydir - 1
            if ydir < 0:
                ydir = 7
                if self.Debug:
                    print mapdir, name, ": wrapping mapdir coordinates +y",
                    print maplat
                maplat = str(int(maplat) - 1)

        if y < 1:
            y = grid
            ydir = ydir + 1
            if ydir > 7:
                ydir = 0
                if self.Debug:
                    print mapdir, name, ": wrapping mapdir coordinates -y",
                    print maplat
                maplat = str(int(maplat) + 1)

        # We're ready to piece the filename back together!
        newpath = os.path.join(collecdir,
                               "q" + MapUtils.ohstring(maplat, 2)
                                   + MapUtils.ohstring(maplon, 3)
                                   + chr(ydir + ord('a')) + str(xdir),
                               serstr + MapUtils.ohstring(x, 2)
                                   + MapUtils.ohstring(y, 2) + ext)
        if not os.access(newpath, os.R_OK):
            if self.Debug:
                print "get_next_maplet(", fullpathname, dX, dY, ")"
                print "  Can't open", newpath
            return None, newpath

        pixbuf = MapWindow.load_image_from_file(newpath)
        return pixbuf, newpath