2017-12-15 13 views
0

내가 Jupyter 노트북에 아래의 코드를 실행하려고하면이 오류를 얻을 :'NoneType'객체에는 속성이 없습니다 'ExportToWkt'

'NoneType'개체가 어떤 속성이없는 'ExportToWkt'

무엇이 문제입니까?

geometry = feature.GetGeometryRef() 

가 없음 기하학 없습니다 할당되어

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

귀하의 전화 :

여기 내 코드입니다. 거기에 무슨 일이 일어나는지 자세히 살펴볼 필요가 있습니다.

전체 코드 (또는 적어도 실행중인 샘플)와 데이터 파일이 없으면 더 많은 도움을받을 수 없습니다.