def test_gpkg_header(self): """ Test the Geopackage Header """ hdr = make_gpkg_geom_header(32623) test = unpack('<2s2bi', hdr) self.assertEqual((GP_MAGIC, 0, 1, 32623), test)
def test_gpkg_linezm(self): """ Test geopackage line """ hdr = make_gpkg_geom_header(32623) expected = [(300000.0, 1.0, 20.0, 0), (700000.0, 4000000.0, 40.0, 1000)] out = points_zm_to_gpkg_line_string_zm(hdr, expected) wkb_line_hdr = self._unpack_byte_and_type(out[8:13]) self.assertEqual(wkb_line_hdr, (1, 3002)) points = self._unpack_base_points(out[13:], wkb_line_hdr[1]) self.assertEqual(expected, points)
def test_gpkg_multipoint(self): """ Test the geopackage multpoint """ hdr = make_gpkg_geom_header(32623) expected = [(300000.0, 1.0), (700000.0, 4000000.0)] out = points_to_gpkg_multipoint(hdr, expected) wkb_mp_hdr = self._unpack_byte_and_type(out[8:13]) self.assertEqual(wkb_mp_hdr, (1, 4)) points = self._unpack_wkb_points(out[13:], wkb_mp_hdr[1]) self.assertEqual(expected, points)
def test_gpkg_poly(self): """ Test geopackage poly """ hdr = make_gpkg_geom_header(32623) expected = [[(300000.0, 1.0), (300000.0, 4000000.0), (700000.0, 4000000.0), (700000.0, 1.0), (300000.0, 1.0)]] out = point_lists_to_gpkg_polygon(hdr, expected) wkb_poly_hdr = self._unpack_byte_and_type(out[8:13]) self.assertEqual(wkb_poly_hdr, (1, 3)) rings = self._unpack_rings(out[13:], wkb_poly_hdr[1]) self.assertEqual(expected, rings)
def test_gpkg_point(self): """ Test geopackage point """ hdr = make_gpkg_geom_header(32623) out = point_to_gpkg_point(hdr, 23.0, 99.0) out_hdr = unpack('<2s2bi', out[:8]) self.assertEqual((GP_MAGIC, 0, 1, 32623), out_hdr) wkb_point_hdr = self._unpack_byte_and_type(out[8:13]) self.assertEqual(wkb_point_hdr, (1, 1)) point = self._unpack_base_point(out[13:]) self.assertEqual((23.0, 99.0), point)
def test_insert_multi_point(self): """ Test insert a multi point """ target_path, gpkg, srs, fields = self._setup_basics( 'test_insert_multi_points.gpkg') fc = gpkg.create_feature_class( 'test1', srs, fields=fields, shape_type=GeometryType.multi_point) # 32623 multipoints = [(300000, 1), (300000, 4000000)] hdr = make_gpkg_geom_header(32623) gpkg_mp = points_to_gpkg_multipoint(hdr, multipoints) fc.insert_rows(['SHAPE', 'int_fld'], [(gpkg_mp, 1)]) self.assertEqual(fc.count, 1)
def test_insert_lines(self): """ Test insert a line """ target_path, gpkg, srs, fields = self._setup_basics( 'test_insert_lines.gpkg') fc = gpkg.create_feature_class( 'test1', srs, fields=fields, shape_type=GeometryType.linestring) # 32623 line = [(300000, 1), (300000, 4000000), (700000, 4000000), (700000, 1)] hdr = make_gpkg_geom_header(32623) gpkg_line = points_to_gpkg_line_string(hdr, line) fc.insert_rows(['SHAPE'], [(gpkg_line,)]) self.assertEqual(fc.count, 1)
def test_insert_lines_4326(self): """ Test insert a line """ target_path, gpkg, srs, fields = self._setup_basics( 'test_insert_lines_4326.gpkg') srs = SRS('', 'ESRI', 4326, '') fc = gpkg.create_feature_class( 'test1', srs, fields=fields, shape_type=GeometryType.linestring) # 32623 line = [(10, 10), (10, 20), (20, 20), (20, 30)] hdr = make_gpkg_geom_header(4326) gpkg_line = points_to_gpkg_line_string(hdr, line) fc.insert_rows(['SHAPE'], [(gpkg_line,)]) self.assertEqual(fc.count, 1)
def test_insert_polys(self): """ Test create a feature class """ target_path, gpkg, srs, fields = self._setup_basics( 'test_insert_polys.gpkg') fc = gpkg.create_feature_class( 'test1', srs, fields=fields, shape_type=GeometryType.polygon) # 32623 rings = [[(300000, 1), (300000, 4000000), (700000, 4000000), (700000, 1), (300000, 1)]] hdr = make_gpkg_geom_header(32623) gpkg_poly = point_lists_to_gpkg_polygon(hdr, rings) fc.insert_rows(['SHAPE'], [(gpkg_poly,)]) self.assertEqual(fc.count, 1) fc.extent = (300000, 1, 700000, 4000000) self.assertEqual((300000, 1, 700000, 4000000), fc.extent)
def test_insert_multi_lines(self): """ Test insert multi lines """ target_path, gpkg, srs, fields = self._setup_basics( 'test_insert_multi_lines.gpkg') fc = gpkg.create_feature_class( 'test1', srs, fields=fields, shape_type=GeometryType.multi_linestring, z_enabled=True, m_enabled=True) line = [[(300000.0, 1.0), (300000.0, 4000000.0), (700000.0, 4000000.0), (700000.0, 1.0)], [(600000.0, 100000.0), (600000.0, 3900000.0), (400000.0, 3900000), (400000.0, 100000.0)]] hdr = make_gpkg_geom_header(32623) gpk_multi_line = point_lists_to_gpkg_multi_line_string(hdr, line) fc.insert_rows(['SHAPE'], [(gpk_multi_line,)]) self.assertEqual(fc.count, 1) self.assertEqual('SHAPE', fc.shape_field_name)
def test_insert_multi_poly(self): """ Test create a feature class with "multi polygons" """ target_path, gpkg, srs, fields = self._setup_basics( 'test_insert_multi_polys.gpkg') fc = gpkg.create_feature_class( 'test1', srs, fields=fields, shape_type=GeometryType.multi_polygon) # 32623 polys = [[[(300000.0, 1.0), (300000.0, 4000000.0), (700000.0, 4000000.0), (700000.0, 1.0), (300000.0, 1.0)]], [[(100000.0, 1000000.0), (100000.0, 2000000.0), (200000.0, 2000000.0), (200000.0, 1000000.0), (100000.0, 1000000.0)]]] hdr = make_gpkg_geom_header(32623) gpkg_poly = point_lists_to_gpkg_multi_polygon(hdr, polys) fc.insert_rows(['SHAPE'], [(gpkg_poly,)]) self.assertEqual(fc.count, 1)