Amazon s3 从python aws lambda如何使用GeoPandas reader读取S3存储桶上的文件?
有很多关于这个主题的文献,但我找不到任何一本使用GeoPandas阅读器的 我的代码的目的是确定一个点是否位于S3中存储的.shp文件中描述的多边形中。然后,它将返回布尔值True或False 我使用python lambda本地python模块测试位于PyCharm上的python脚本Amazon s3 从python aws lambda如何使用GeoPandas reader读取S3存储桶上的文件?,amazon-s3,io,aws-lambda,boto3,geopandas,Amazon S3,Io,Aws Lambda,Boto3,Geopandas,有很多关于这个主题的文献,但我找不到任何一本使用GeoPandas阅读器的 我的代码的目的是确定一个点是否位于S3中存储的.shp文件中描述的多边形中。然后,它将返回布尔值True或False 我使用python lambda本地python模块测试位于PyCharm上的python脚本 import geopandas as gpd from geopandas.geoseries import * import boto3 from io import BytesIO def searc
import geopandas as gpd
from geopandas.geoseries import *
import boto3
from io import BytesIO
def search(event, context):
dep = event['Dep']
arr = event['Arr']
point_1 = GeoSeries(dep)
point_2 = GeoSeries(arr)
s3 = boto3.client("s3")
bucket = "mybucket"
obj_key = "filename.shp"
# bytes_buffer = BytesIO()
# client.download_fileobj(Bucket=bucket, Key=obj_key, Fileobj=bytes_buffer)
obj = s3.download_file(Bucket=bucket, Key="filename.shp", Filename=obj_key)
geo = obj['body'].read().decode('ISO-8859-9')
# geo = bytes_buffer.get_key(obj_key).get_contents_as_string()
answer = gpd.read_file(geo)
print(answer)
正如您在代码中看到的,我尝试了几行不同的代码以不同的方式使用IO和reader()。但总是不成功
#And this is the error message:#
MacBook-Pro:IdPolygons me$ python-lambda-local -l lib/ -f search -t 4 IdAircraft.py event.json
*This is the point I'm trying to identify inside or outside the polygon:*
[root - INFO - 2019-12-24 07:33:54,388] Event: {'Dep': '(40.7128, 74.0060)', 'Arr': '(48.8566, 2.3522)'}
[root - INFO - 2019-12-24 07:33:54,388] START RequestId: 629c76c7-1008-40cc-8c09-6c5dd3877125 Version:
[botocore.credentials - INFO - 2019-12-24 07:33:54,923] Found credentials in shared credentials file: ~/.aws/credentials stored
[root - INFO - 2019-12-24 07:33:55,576] END RequestId: 629c76c7-1008-40cc-8c09-6c5dd3877125
[root - INFO - 2019-12-24 07:33:55,577] REPORT RequestId: 629c76c7-1008-40cc-8c09-6c5dd3877125 Duration: 663.91 ms
[root - INFO - 2019-12-24 07:33:55,577] RESULT:
{
"errorMessage": "'NoneType' object has no attribute 'startswith'",
"stackTrace": [
" File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/lambda_local/main.py\", line 153, in execute\n result = func(event, context._activate())\n",
" File \"IdAircraft.py\", line 30, in search\n df1 = gpd.read_file(obj)\n",
" File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/geopandas/io/file.py\", line 77, in read_file\n with reader(path_or_bytes, **kwargs) as features:\n",
" File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/fiona/env.py\", line 397, in wrapper\n return f(*args, **kwargs)\n",
" File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/fiona/__init__.py\", line 249, in open\n path = parse_path(fp)\n",
" File \"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/fiona/path.py\", line 132, in parse_path\n elif path.startswith('/vsi'):\n"
],
"errorType": "AttributeError"
}
感谢您抽出时间。有一点可能会有所帮助。Shp不仅仅是一个文件,它至少由3个文件(Shp、shx、dbf)组成,因此仅下载Shp无论如何都不起作用。试着拉上拉链,或者把它们都拿出来。但是,我不确定这是否导致了上述问题。谢谢@martinfleis,是的,我知道并做到了。仍然没有让它工作。