python gdal error

falcone.giuseppe at gmail.com falcone.giuseppe at gmail.com
Fri Sep 8 08:34:57 EDT 2017


Hi to all,

I'm new to python program and I have a problem with the following code.
I'm unable to read field_data variable in retrieve_model_params function.
In debug, execution ends immediately without a message.
Anyone have some idea about that?
If the for cycle in retrieve_model_params is moved to read_data_from_shape function, everything works perfectly ...

Thanks a lot.
Giuseppe


import os
from osgeo import ogr

def read_data_from_shape():
    "This function load data from a shapefile"

    shp_driver = ogr.GetDriverByName("ESRI Shapefile")

    data_source = shp_driver.Open("../shape.shp", 0) 

    layer = data_source.GetLayer()
    feature_count = layer.GetFeatureCount()
    print("Number of features:: %d" % (feature_count))
    return layer

def retrieve_model_params():

    # load data
    field_data = read_data_from_shape()

    for feature in field_data:
       vol = feature.GetField('VolHa')
       print(vol)

def main():
    retrieve_model_params()

if __name__ == '__main__':
    main()



More information about the Python-list mailing list