Esempio n. 1
0
 def test_type(self):
     shp = shp_file(pysal.examples.get_path('Point.shp'))
     self.assertEqual("POINT", shp.type())
     shp = shp_file(pysal.examples.get_path('Polygon.shp'))
     self.assertEqual("POLYGON", shp.type())
     shp = shp_file(pysal.examples.get_path('Line.shp'))
     self.assertEqual("ARC", shp.type())
Esempio n. 2
0
 def test1(self):
     """ Test creating and reading PolyLine Shape Files """
     lines = [[(0, 0), (4, 4), (5, 4), (1, 0), (0, 0)],
              [(1, 0), (5, 4), (6, 4), (2, 0), (1, 0)]]
     shapes = []
     for line in lines:
         x = [v[0] for v in line]
         y = [v[1] for v in line]
         rec = {}
         rec['BBOX Xmin'] = min(x)
         rec['BBOX Ymin'] = min(y)
         rec['BBOX Xmax'] = max(x)
         rec['BBOX Ymax'] = max(y)
         rec['NumPoints'] = len(line)
         rec['NumParts'] = 1
         rec['Vertices'] = line
         rec['Shape Type'] = 5
         rec['Parts Index'] = [0]
         shapes.append(rec)
     shp = shp_file('test_poly', 'w', 'POLYGON')
     for line in shapes:
         shp.add_shape(line)
     shp.close()
     shp = list(shp_file('test_poly'))
     for a, b in zip(shapes, shp):
         self.assertEquals(a, b)
     os.remove('test_poly.shp')
     os.remove('test_poly.shx')
Esempio n. 3
0
 def test_type(self):
     shp = shp_file(pysal.examples.get_path('Point.shp'))
     self.assertEqual("POINT", shp.type())
     shp = shp_file(pysal.examples.get_path('Polygon.shp'))
     self.assertEqual("POLYGON", shp.type())
     shp = shp_file(pysal.examples.get_path('Line.shp'))
     self.assertEqual("ARC", shp.type())
Esempio n. 4
0
 def test1(self):
     """ Test creating and reading PolyLine Shape Files """
     lines = [[(0, 0), (4, 4), (5, 4), (
         1, 0), (0, 0)], [(1, 0), (5, 4), (6, 4), (2, 0), (1, 0)]]
     shapes = []
     for line in lines:
         x = [v[0] for v in line]
         y = [v[1] for v in line]
         rec = {}
         rec['BBOX Xmin'] = min(x)
         rec['BBOX Ymin'] = min(y)
         rec['BBOX Xmax'] = max(x)
         rec['BBOX Ymax'] = max(y)
         rec['NumPoints'] = len(line)
         rec['NumParts'] = 1
         rec['Vertices'] = line
         rec['Shape Type'] = 5
         rec['Parts Index'] = [0]
         shapes.append(rec)
     shp = shp_file('test_poly', 'w', 'POLYGON')
     for line in shapes:
         shp.add_shape(line)
     shp.close()
     shp = list(shp_file('test_poly'))
     for a, b in zip(shapes, shp):
         self.assertEquals(a, b)
     os.remove('test_poly.shp')
     os.remove('test_poly.shx')
Esempio n. 5
0
    def test1(self):
        """ Test creating and reading Point Shape Files """
        shp = shp_file('test_point', 'w', 'POINT')
        points = [{
            'Shape Type': 1,
            'X': 0,
            'Y': 0
        }, {
            'Shape Type': 1,
            'X': 1,
            'Y': 1
        }, {
            'Shape Type': 1,
            'X': 2,
            'Y': 2
        }, {
            'Shape Type': 1,
            'X': 3,
            'Y': 3
        }, {
            'Shape Type': 1,
            'X': 4,
            'Y': 4
        }]
        for pt in points:
            shp.add_shape(pt)
        shp.close()

        shp = list(shp_file('test_point'))
        for a, b in zip(points, shp):
            self.assertEquals(a, b)
        os.remove('test_point.shp')
        os.remove('test_point.shx')
Esempio n. 6
0
    def test_add_shape(self):
        shp = shp_file('test_point', 'w', 'POINT')
        points = [{
            'Shape Type': 1,
            'X': 0,
            'Y': 0
        }, {
            'Shape Type': 1,
            'X': 1,
            'Y': 1
        }, {
            'Shape Type': 1,
            'X': 2,
            'Y': 2
        }, {
            'Shape Type': 1,
            'X': 3,
            'Y': 3
        }, {
            'Shape Type': 1,
            'X': 4,
            'Y': 4
        }]
        for pt in points:
            shp.add_shape(pt)
        shp.close()

        for a, b in zip(points, shp_file('test_point')):
            self.assertEquals(a, b)
        os.remove('test_point.shp')
        os.remove('test_point.shx')
Esempio n. 7
0
    def test1(self):
        """ Test creating and reading Point Shape Files """
        shp = shp_file('test_point', 'w', 'POINT')
        points = [{'Shape Type': 1, 'X': 0, 'Y': 0}, {'Shape Type': 1, 'X': 1, 'Y': 1}, {'Shape Type': 1, 'X': 2, 'Y': 2}, {'Shape Type': 1, 'X': 3, 'Y': 3}, {'Shape Type': 1, 'X': 4, 'Y': 4}]
        for pt in points:
            shp.add_shape(pt)
        shp.close()

        shp = list(shp_file('test_point'))
        for a, b in zip(points, shp):
            self.assertEquals(a, b)
        os.remove('test_point.shp')
        os.remove('test_point.shx')
Esempio n. 8
0
    def test_add_shape(self):
        shp = shp_file('test_point', 'w', 'POINT')
        points = [{'Shape Type': 1, 'X': 0, 'Y': 0},
                  {'Shape Type': 1, 'X': 1, 'Y': 1},
                  {'Shape Type': 1, 'X': 2, 'Y': 2},
                  {'Shape Type': 1, 'X': 3, 'Y': 3},
                  {'Shape Type': 1, 'X': 4, 'Y': 4}]
        for pt in points:
            shp.add_shape(pt)
        shp.close()

        for a, b in zip(points, shp_file('test_point')):
            self.assertEquals(a, b)
        os.remove('test_point.shp')
        os.remove('test_point.shx')
Esempio n. 9
0
 def test_next(self):
     shp = shp_file(pysal.examples.get_path('Point.shp'))
     points = [pt for pt in shp]
     expected = {'Y': -0.25904661905760773, 'X': -
                 0.00068176617532103578, 'Shape Type': 1}
     self.assertEqual(expected, shp.next())
     expected = {'Y': -0.25630328607387354, 'X':
                 0.11697145363360706, 'Shape Type': 1}
     self.assertEqual(expected, shp.next())
Esempio n. 10
0
 def test_next(self):
     shp = shp_file(pysal.examples.get_path('Point.shp'))
     points = [pt for pt in shp]
     expected = {
         'Y': -0.25904661905760773,
         'X': -0.00068176617532103578,
         'Shape Type': 1
     }
     self.assertEqual(expected, shp.next())
     expected = {
         'Y': -0.25630328607387354,
         'X': 0.11697145363360706,
         'Shape Type': 1
     }
     self.assertEqual(expected, shp.next())
Esempio n. 11
0
 def test_get_shape(self):
     shp = shp_file(pysal.examples.get_path('Line.shp'))
     rec = shp.get_shape(0)
     expected = {'BBOX Ymax': -0.25832280562918325,
                 'NumPoints': 3,
                 'BBOX Ymin': -0.25895877033237352,
                 'NumParts': 1,
                 'Vertices': [(-0.0090539248870159517, -0.25832280562918325),
                              (0.0074811573959305822, -0.25895877033237352),
                              (
                                  0.0074811573959305822, -0.25895877033237352)],
                 'BBOX Xmax': 0.0074811573959305822,
                 'BBOX Xmin': -0.0090539248870159517,
                 'Shape Type': 3,
                 'Parts Index': [0]}
     self.assertEqual(expected, shp.get_shape(0))
Esempio n. 12
0
 def test___iter__(self):
     shp = shp_file(pysal.examples.get_path('Point.shp'))
     points = [pt for pt in shp]
     expected = [{'Y': -0.25904661905760773, 'X': -0.00068176617532103578, 'Shape Type': 1},
                 {'Y': -0.25630328607387354, 'X': 0.11697145363360706,
                     'Shape Type': 1},
                 {'Y': -0.33930131004366804, 'X': 0.05043668122270728,
                     'Shape Type': 1},
                 {'Y': -0.41266375545851519, 'X': -0.041266375545851552,
                     'Shape Type': 1},
                 {'Y': -0.44017467248908293, 'X': -0.011462882096069604,
                     'Shape Type': 1},
                 {'Y': -0.46080786026200882, 'X': 0.027510917030567628,
                     'Shape Type': 1},
                 {'Y': -0.45851528384279472, 'X': 0.075655021834060809,
                     'Shape Type': 1},
                 {'Y': -0.43558951965065495, 'X': 0.11233624454148461,
                     'Shape Type': 1},
                 {'Y': -0.40578602620087334, 'X': 0.13984716157205224, 'Shape Type': 1}]
     assert points == expected
Esempio n. 13
0
 def test___iter__(self):
     shp = shp_file(pysal.examples.get_path('Point.shp'))
     points = [pt for pt in shp]
     expected = [{
         'Y': -0.25904661905760773,
         'X': -0.00068176617532103578,
         'Shape Type': 1
     }, {
         'Y': -0.25630328607387354,
         'X': 0.11697145363360706,
         'Shape Type': 1
     }, {
         'Y': -0.33930131004366804,
         'X': 0.05043668122270728,
         'Shape Type': 1
     }, {
         'Y': -0.41266375545851519,
         'X': -0.041266375545851552,
         'Shape Type': 1
     }, {
         'Y': -0.44017467248908293,
         'X': -0.011462882096069604,
         'Shape Type': 1
     }, {
         'Y': -0.46080786026200882,
         'X': 0.027510917030567628,
         'Shape Type': 1
     }, {
         'Y': -0.45851528384279472,
         'X': 0.075655021834060809,
         'Shape Type': 1
     }, {
         'Y': -0.43558951965065495,
         'X': 0.11233624454148461,
         'Shape Type': 1
     }, {
         'Y': -0.40578602620087334,
         'X': 0.13984716157205224,
         'Shape Type': 1
     }]
     assert points == expected
Esempio n. 14
0
 def test___init__(self):
     shp = shp_file(pysal.examples.get_path('10740.shp'))
     assert shp.header == {
         'BBOX Xmax': -105.29012,
         'BBOX Ymax': 36.219799000000002,
         'BBOX Mmax': 0.0,
         'BBOX Zmin': 0.0,
         'BBOX Mmin': 0.0,
         'File Code': 9994,
         'BBOX Ymin': 34.259672000000002,
         'BBOX Xmin': -107.62651,
         'Unused0': 0,
         'Unused1': 0,
         'Unused2': 0,
         'Unused3': 0,
         'Unused4': 0,
         'Version': 1000,
         'BBOX Zmax': 0.0,
         'Shape Type': 5,
         'File Length': 260534
     }
Esempio n. 15
0
 def test_get_shape(self):
     shp = shp_file(pysal.examples.get_path('Line.shp'))
     rec = shp.get_shape(0)
     expected = {
         'BBOX Ymax':
         -0.25832280562918325,
         'NumPoints':
         3,
         'BBOX Ymin':
         -0.25895877033237352,
         'NumParts':
         1,
         'Vertices': [(-0.0090539248870159517, -0.25832280562918325),
                      (0.0074811573959305822, -0.25895877033237352),
                      (0.0074811573959305822, -0.25895877033237352)],
         'BBOX Xmax':
         0.0074811573959305822,
         'BBOX Xmin':
         -0.0090539248870159517,
         'Shape Type':
         3,
         'Parts Index': [0]
     }
     self.assertEqual(expected, shp.get_shape(0))
Esempio n. 16
0
 def test___len__(self):
     shp = shp_file(pysal.examples.get_path('10740.shp'))
     assert len(shp) == 195
Esempio n. 17
0
 def test_close(self):
     shp = shp_file(pysal.examples.get_path('10740.shp'))
     shp.close()
     self.assertEqual(shp.fileObj.closed, True)
Esempio n. 18
0
 def test_close(self):
     shp = shp_file(pysal.examples.get_path('10740.shp'))
     shp.close()
     self.assertEqual(shp.fileObj.closed, True)
Esempio n. 19
0
 def test___len__(self):
     shp = shp_file(pysal.examples.get_path('10740.shp'))
     assert len(shp) == 195
Esempio n. 20
0
def pythonShape():
    f = shp_file(shp,'r')
    for record in f:
        pass
Esempio n. 21
0
 def test___init__(self):
     shp = shp_file(pysal.examples.get_path('10740.shp'))
     assert shp.header == {'BBOX Xmax': -105.29012, 'BBOX Ymax': 36.219799000000002, 'BBOX Mmax': 0.0, 'BBOX Zmin': 0.0, 'BBOX Mmin': 0.0, 'File Code': 9994, 'BBOX Ymin': 34.259672000000002, 'BBOX Xmin': -107.62651, 'Unused0': 0, 'Unused1': 0, 'Unused2': 0, 'Unused3': 0, 'Unused4': 0, 'Version': 1000, 'BBOX Zmax': 0.0, 'Shape Type': 5, 'File Length': 260534}