Exemplo n.º 1
0
    def test_add_points_pil(self):
        from pycoast import ContourWriterPIL
        from pyresample.geometry import AreaDefinition

        font_file = os.path.join(os.path.dirname(__file__), 'test_data',
                                 'DejaVuSerif.ttf')
        grid_img = Image.open(
            os.path.join(os.path.dirname(__file__), 'nh_points_pil.png'))
        grid_data = np.array(grid_img)

        img = Image.new('RGB', (1024, 1024), (255, 255, 255))

        proj4_string = '+proj=laea +lat_0=90 +lon_0=0 +a=6371228.0 +units=m'
        area_extent = (-5326849.0625, -5326849.0625, 5326849.0625,
                       5326849.0625)

        area_def = AreaDefinition('nh', 'nh', 'nh', proj4_string, 1024, 1024,
                                  area_extent)

        cw = ContourWriterPIL(gshhs_root_dir)
        cw.add_coastlines(img,
                          area_def,
                          outline='black',
                          resolution='l',
                          level=4)
        cw.add_borders(img, area_def, outline='black', level=1, resolution='c')

        points_list = [((13.4050, 52.5200), 'Berlin')]
        cw.add_points(img,
                      area_def,
                      points_list=points_list,
                      font_file=font_file,
                      symbol='asterisk',
                      ptsize=6,
                      outline='red',
                      box_outline='black')

        points_list = [((12.4964, 41.9028), 'Rome')]
        cw.add_points(img,
                      area_def,
                      points_list=points_list,
                      font_file=font_file,
                      symbol='square',
                      ptsize=6,
                      outline='blue',
                      fill='yellow',
                      box_outline='black')

        res = np.array(img)
        self.assertTrue(fft_metric(grid_data, res),
                        'Writing of nh points failed')
Exemplo n.º 2
0
    def test_europe(self):
        from pycoast import ContourWriterPIL
        euro_img = Image.open(
            os.path.join(os.path.dirname(__file__), 'contours_europe.png'))
        euro_data = np.array(euro_img)

        img = Image.new('RGB', (640, 480))
        proj4_string = \
            '+proj=stere +lon_0=8.00 +lat_0=50.00 +lat_ts=50.00 +ellps=WGS84'
        area_extent = (-3363403.31, -2291879.85, 2630596.69, 2203620.1)
        area_def = (proj4_string, area_extent)
        cw = ContourWriterPIL(gshhs_root_dir)
        cw.add_coastlines(img, area_def, resolution='l', level=4)
        cw.add_rivers(img, area_def, level=5, outline='blue')
        cw.add_borders(img, area_def, outline=(255, 0, 0))

        res = np.array(img)
        self.assertTrue(fft_metric(euro_data, res),
                        'Writing of contours failed')