def load(Class, path): if not exists(path): raise IOError if path.endswith('.zip'): import geometryIO from crosscompute_table import pandas as pd [ proj4, geometries, field_packs, field_definitions, ] = geometryIO.load(path) # Convert to (longitude, latitude) normalize_geometry = geometryIO.get_transformGeometry( proj4 or geometryIO.proj4LL) geometries = [normalize_geometry(x) for x in geometries] # Convert to (latitude, longitude) geometries = transform_geometries(geometries, drop_z) geometries = transform_geometries(geometries, flip_xy) # Generate table table = pd.DataFrame( field_packs, columns=[x[0] for x in field_definitions]) table['WKT'] = [x.wkt for x in geometries] else: table = super(GeotableType, Class).load(path) # TODO: Consider whether there is a better way to do this table.interpret = create_bound_method(_interpret, table) return table
def load_geotable(path): if path.endswith('.csv'): table = read_csv(path) elif path.endswith('.zip'): proj4, geometries, fields, definitions = geometryIO.load(path) normalize_geometry = geometryIO.get_transformGeometry(proj4) geometries = [normalize_geometry(x) for x in geometries] table = DataFrame(fields, columns=[x[0] for x in definitions]) table['WKT'] = [x.wkt for x in geometries] else: raise UnsupportedFormat('cannot load geotable (%s)' % path) return table
def load_geotable(path): if path.endswith('.csv'): table = read_csv(path) elif path.endswith('.zip'): proj4, geometries, fields, definitions = geometryIO.load(path) normalize_geometry = geometryIO.get_transformGeometry(proj4) # Convert to (longitude, latitude) geometries = [normalize_geometry(x) for x in geometries] # Convert to (latitude, longitude) geometries = transform_geometries(geometries, flip_xy) table = DataFrame(fields, columns=[x[0] for x in definitions]) table['WKT'] = [x.wkt for x in geometries] else: raise UnsupportedFormat('cannot load geotable (%s)' % path) return table
def test_get_transformGeometry_runs(self): transformGeometry = get_transformGeometry(proj4LL, proj4SM) self.assertEqual(type(transformGeometry(Point(0, 0))), type(Point(0, 0))) self.assertEqual(type(transformGeometry(CreateGeometryFromWkt('POINT (0 0)'))), type(CreateGeometryFromWkt('POINT (0 0)'))) with self.assertRaises(GeometryError): transformGeometry(Point(1000, 1000))