Esempio n. 1
0
 def test_point_in_polygon_latlon(self):
     # test for point in polygon across dateline
     x1 = -175.
     y1 = 50.
     poly1= [(150.,60.), (-160.,60.), (-170.,45.), (170.,45.)]
     P1 = Polygon(1, poly1)
     self.assertTrue(P1.point_in_poly_latlon(x1,y1))
Esempio n. 2
0
 def test_point_in_polygon_latlon(self):
     # test for point in polygon across dateline
     x1 = -175.
     y1 = 50.
     poly1 = [(150., 60.), (-160., 60.), (-170., 45.), (170., 45.)]
     P1 = Polygon(1, poly1)
     self.assertTrue(P1.point_in_poly_latlon(x1, y1))
Esempio n. 3
0
 def test_shift(self):
     poly3 = [(150., 20.), (-160., 30.), (-170., 10.), (170., 10.)]
     P3 = Polygon(3, poly3)
     P3._shift_coordinates()  # shift longitudes by 200 degree
     self.assertEqual(P3.poly[0][0], 150.)
     self.assertEqual(P3.poly[1][0], 200.)
     self.assertEqual(P3.poly[2][0], 190.)
     self.assertEqual(P3.poly[3][0], 170.)
Esempio n. 4
0
 def test_shift(self):
     poly3 = [(150.,20.), (-160.,30.), (-170.,10.), (170.,10.)]
     P3 = Polygon(3, poly3)
     P3._shift_coordinates()  # shift longitudes by 200 degree
     self.assertEqual(P3.poly[0][0], 150.)
     self.assertEqual(P3.poly[1][0], 200.)
     self.assertEqual(P3.poly[2][0], 190.)
     self.assertEqual(P3.poly[3][0], 170.)
Esempio n. 5
0
    def test_is_closed(self):
        poly = [(150.,20.), (-160.,30.), (-170.,10.), (170.,10.)]
        P = Polygon(3, poly)
        self.assertFalse(P.is_closed())

        poly1 = [(150.,20.), (-160.,30.), (-170.,10.), (170.,10.), (150.,20.)]
        P1 = Polygon(3, poly1)
        self.assertTrue(P1.is_closed())
Esempio n. 6
0
 def test_point_in_polygon(self):
     x = 1
     y = 1
     poly = [(0, 0), (2, 0), (2, 2), (0, 2)]
     P = Polygon(1, poly)
     self.assertTrue(P.point_in_poly(x, y))
     x = 4
     y = 4
     self.assertFalse(P.point_in_poly(x, y))
Esempio n. 7
0
 def test_point_in_polygon(self):
     x = 1
     y = 1
     poly = [(0,0), (2,0), (2,2), (0,2)]
     P = Polygon(1, poly)
     self.assertTrue(P.point_in_poly(x,y))
     x = 4
     y = 4
     self.assertFalse(P.point_in_poly(x,y))
Esempio n. 8
0
    def test_polygon_min_max(self):
        x = 1
        y = 1
        poly = [(-5, 0), (2, 0), (2, 2), (0, 6)]
        P = Polygon(1, poly)

        bbox = P.bbox()
        self.assertEqual(bbox[0], -5.)
        self.assertEqual(bbox[1], 2.)
        self.assertEqual(bbox[2], 0.)
        self.assertEqual(bbox[3], 6.)
Esempio n. 9
0
    def test_polygon_min_max(self):
        x = 1
        y = 1
        poly = [(-5,0), (2,0), (2,2), (0,6)]
        P = Polygon(1, poly)

        bbox = P.bbox()
        self.assertEqual(bbox[0], -5.)
        self.assertEqual(bbox[1], 2.)
        self.assertEqual(bbox[2], 0.)
        self.assertEqual(bbox[3], 6.)
Esempio n. 10
0
 def test_raster_multiple_polygon(self):  # this is quite slow!
     lon = np.linspace(-180., 180., 361)
     lat = np.linspace(-90., 90., 181)
     LON, LAT = np.meshgrid(lon, lat)
     #~ #~
     # test a single polygon
     poly = []
     poly1 = [(-10., -10.), (-10., 20), (15., 0.), (0., -15.)]
     poly.append(Polygon(1, poly1))
     #~ #~
     poly2 = [(-50., -80.), (-50., -70.), (-40., -70.), (-40., -75.)]
     poly.append(Polygon(2, poly2))
     #~ #~
     R = Raster(LON, LAT)
     R.rasterize_polygons(poly)
     #~ #~
     u = np.unique(R.mask[~R.mask.mask])
     self.assertTrue(len(u) == 2)
     self.assertTrue(1 in u)
     self.assertTrue(2 in u)
Esempio n. 11
0
    def test_is_closed(self):
        poly = [(150., 20.), (-160., 30.), (-170., 10.), (170., 10.)]
        P = Polygon(3, poly)
        self.assertFalse(P.is_closed())

        poly1 = [(150., 20.), (-160., 30.), (-170., 10.), (170., 10.),
                 (150., 20.)]
        P1 = Polygon(3, poly1)
        self.assertTrue(P1.is_closed())
Esempio n. 12
0
    def test_raster_single_polygon(self):
        lon = np.linspace(-180., 180., 361)
        lat = np.linspace(-90., 90., 181)
        LON, LAT = np.meshgrid(lon, lat)

        # test a single polygon
        poly = [(-10., -10.), (-10., 20), (15., 0.), (0., -25.)]
        P = Polygon(5, poly)
        R = Raster(LON, LAT)
        R.mask = np.zeros(LON.shape) * np.nan
        R._rasterize_single_polygon(P)

        print np.unique(R.mask)

        R.mask = np.ma.array(R.mask, mask=np.isnan(R.mask))

        u = np.unique(R.mask[~R.mask.mask])

        print R.mask
        print u

        self.assertTrue(len(u) == 1)
        self.assertTrue(5. in u)
Esempio n. 13
0
"""
from pycmbs.mapping import SingleMap
from pycmbs.data import Data
import matplotlib.pyplot as plt
from pycmbs.polygon import Polygon
import numpy as np

import cartopy.crs as ccrs

plt.close('all')




poly1 = [(-105., 60.), (-168.022, 60.), (-168.022, 72.554), (-105., 72.554)]  # ALA 1
P1 = Polygon(1, poly1)
P1.value=100.


poly2 = [(-66.377, -20.), (-79.729, -1.239), (-68.8, 11.439), (-50., 11.439), (-50., -20.)]
P2 = Polygon(7, poly2)
P2.value=200.



#~ AMZ 7 (20.000S, 66.377W) (1.239S, 79.729W) (11.439N, 68.800W) (11.439N, 50.000W) (20.000S, 50.000W)
#~ CAM 6 (11.439N, 68.800W) (1.239S, 79.729W) (28.566N, 118.323W) (28.566N, 90.315W)


tmp = np.ones((180, 360))
d = Data(None, None)
Esempio n. 14
0
 def test_convertOGR(self):
     poly = [(150., 20.), (-160., 30.), (-170., 10.), (170., 10.)]
     P = Polygon(3, poly)
     A = P.convertToOGRPolygon()
     B = P.convertToOGRPolygon(ensure_positive=True)
Esempio n. 15
0
 def test_convertOGR(self):
     poly = [(150.,20.), (-160.,30.), (-170.,10.), (170.,10.)]
     P = Polygon(3, poly)
     A = P.convertToOGRPolygon()
     B = P.convertToOGRPolygon(ensure_positive=True)