关于该主题的文献很多,但是我找不到使用GeoPandas阅读器的文献。
我的代码目的是识别点是否位于存储在S3中的.shp文件中描述的多边形中。然后,它会返回布尔值True或False。
我使用python-lambda-local python模块测试位于PyCharm上的python脚本。
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"
}
感谢您抽出宝贵的时间。