Ejemplo n.º 1
0
    def _location_to_tile_name(cls,
                               xs,
                               ys,
                               tile_size=1,
                               ns_fixed_width=None,
                               ew_fixed_width=None):
        """Convert locations to SRTM tile name.

        For example, (-120.5, 40.1) becomes N40W121. The lower left corner of
        the tile is used. The numbers can be padded with leading zeroes to all
        be the same width.

        Args:
            xs, ys: Lists of x and y coordinates.
            tile_size: Which value to round the tiles to.
            ns_fixed_width, ew_fixed_width: Integer to pad with zeroes. None means no padding.

        Returns:
            tile_names: List of strings.
        """

        n_or_s = np.where(ys >= 0, "N", "S")
        e_or_w = np.where(xs >= 0, "E", "W")

        ns_value = np.abs(utils.base_floor(ys,
                                           tile_size)).astype(int).astype(str)
        ew_value = np.abs(utils.base_floor(xs,
                                           tile_size)).astype(int).astype(str)

        ns_fixed_width = ns_fixed_width or 0
        ew_fixed_width = ew_fixed_width or 0

        ns_value = [x.zfill(ns_fixed_width) for x in ns_value]
        ew_value = [x.zfill(ew_fixed_width) for x in ew_value]

        tile_names = np.char.add(n_or_s, ns_value)
        tile_names = np.char.add(tile_names, e_or_w)
        tile_names = np.char.add(tile_names, ew_value)

        return tile_names
Ejemplo n.º 2
0
 def test_negative_value(self):
     assert utils.base_floor(-5.1, 5) == -10
Ejemplo n.º 3
0
 def test_other_base(self):
     assert utils.base_floor(290.9, 50) == 250
Ejemplo n.º 4
0
 def test_base_1_default(self):
     values = [-1, 0, 1, -0.6, -0.4, 0.4, 0.6, 99.91]
     for x in values:
         assert np.floor(x) == utils.base_floor(x)
         assert np.floor(x) == utils.base_floor(x, 1)