2017-12-15 15 views
0

私はJupyterノートブックで以下のコードを実行しようとしたとき、私はこのエラーを取得:「NoneType」オブジェクトには属性がありません「ExportToWkt」

「NoneType」オブジェクトが属性を持っていない「ExportToWkt」

問題は何ですか?ここで

は私のコードです:

shapefile = osgeo.ogr.Open("C:/Users/chavoshi/Anaconda3/Example Data/Remorquages/pointdata.shp") 
layer = shapefile.GetLayer(0) 

#First delete the existing contents of this table in case we want to run the code multiple times. 
cursor.execute("DELETE FROM B_B") 

for i in range(layer.GetFeatureCount()): 
    feature = layer.GetFeature(i) 
    lats_o = feature.GetField("latitude_o") 
    #print(lats_o) 
    lons_o = feature.GetField("longitude_") 
    #Get feature geometry 
    geometry = feature.GetGeometryRef() 
    #Convert geometry to WKT format 
    wkt = geometry.ExportToWkt() 
    #Insert data into database, converting WKT geometry to a PostGIS geography 
    cursor.execute("INSERT INTO B_B (lats, lons, outline) VALUES ({}, {}, ST_GeogFromText('{}'))".format(lats_o, lons_o, wkt)) 
connection.commit() 

答えて

0

あなたのコール

geometry = feature.GetGeometryRef() 

はジオメトリにNoneを割り当てることはありません。そこに起こっていることを詳しく見ていく必要があります。

完全なコード(少なくとも実行中のサンプル)とデータファイルがなければ、私ははるかに役立つことはできません。

関連する問題