使用 Dataflow + Beam + Python 从 Google Cloud Storage 读取 Shapefile
Read Shapefile from Google Cloud Storage using Dataflow + Beam + Python
如何使用 Dataflow + Beam + Python.
从 Google 云存储中读取 Shapefile
我只找到 beam.io.ReadFromText
,但 python shapefile reader 需要类似文件的对象:shp.Reader(shp=shp_file, dbf=dbf_file)
或 shapefile。
我正在使用 Python 2.7.
方法如下:
prj_file = beam.io.gcp.gcsio.GcsIO().open(
filenamePRJ,
mode='r',
read_buffer_size=1677721600,
mime_type='application/octet-stream'
)
shp_file = beam.io.gcp.gcsio.GcsIO().open(
filenameSHP,
mode='r',
read_buffer_size=1677721600,
mime_type='application/octet-stream'
)
dbf_file = beam.io.gcp.gcsio.GcsIO().open(
filenameDBF,
mode='r',
read_buffer_size=1677721600,
mime_type='application/octet-stream'
)
sf = shp.Reader(shp=shp_file, dbf=dbf_file)
euref = osr.SpatialReference()
euref.ImportFromWkt(str(prj_file.read()))
wgs84 = osr.SpatialReference()
wgs84.ImportFromEPSG(4326)
transformation = osr.CoordinateTransformation(euref,wgs84)
这里是 python 包,其中包含用于读取 Shapefile 的自定义 Beam I/O 连接器:https://github.com/GoogleCloudPlatform/dataflow-geobeam
如何使用 Dataflow + Beam + Python.
从 Google 云存储中读取 Shapefile
我只找到 beam.io.ReadFromText
,但 python shapefile reader 需要类似文件的对象:shp.Reader(shp=shp_file, dbf=dbf_file)
或 shapefile。
我正在使用 Python 2.7.
方法如下:
prj_file = beam.io.gcp.gcsio.GcsIO().open(
filenamePRJ,
mode='r',
read_buffer_size=1677721600,
mime_type='application/octet-stream'
)
shp_file = beam.io.gcp.gcsio.GcsIO().open(
filenameSHP,
mode='r',
read_buffer_size=1677721600,
mime_type='application/octet-stream'
)
dbf_file = beam.io.gcp.gcsio.GcsIO().open(
filenameDBF,
mode='r',
read_buffer_size=1677721600,
mime_type='application/octet-stream'
)
sf = shp.Reader(shp=shp_file, dbf=dbf_file)
euref = osr.SpatialReference()
euref.ImportFromWkt(str(prj_file.read()))
wgs84 = osr.SpatialReference()
wgs84.ImportFromEPSG(4326)
transformation = osr.CoordinateTransformation(euref,wgs84)
这里是 python 包,其中包含用于读取 Shapefile 的自定义 Beam I/O 连接器:https://github.com/GoogleCloudPlatform/dataflow-geobeam