[Python] Loading a shapefile from S3 bucket with geopandas

Discussão em 'Python' iniciado por Stack, Janeiro 28, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to read a shapefile from an AWS bucket using Geopandas and boto3.

    I am logging onto AWS with SSO from command line, so there is no need to pass access keys.

    My below script works when adjusted to load a Geojson file, but will not work on shapefiles and I get a ' No such file or directory' error from fiona

    I am guessing this is to do with shapefiles been made up of multiple files?

    import boto3
    import geopandas as gpd

    #S3 setup
    boto3.setup_default_session(profile_name=profile_name)
    s3_client = boto3.client('s3')
    s3 = boto3.resource('s3', region_name=aws_region)
    bucket_name = 'aws_bucket'
    bucket = s3.Bucket(bucket_name)
    objects = bucket.objects.filter(Prefix='test')

    # read shapefile from aws bucket
    for object in objects:
    if object.key.endswith('.shp') and object.key.split('/')[-1].startswith('test_'):
    file_content = object.get()['Body'].read().decode('ISO-8859-1')
    shape = gpd.read_file(file_content)




    The error:

    Traceback (most recent call last):
    File "fiona\_shim.pyx", line 83, in fiona._shim.gdal_open_vector
    File "fiona\_err.pyx", line 291, in fiona._err.exc_wrap_pointer
    fiona._err.CPLE_OpenFailedError: : No such file or directory


    Is there a way to modify this script so it works on shapefiles

    Continue reading...

Compartilhe esta Página