def readwktcsv(csv_path,removeNoBuildings=True, groundTruthFile=True):
#
# csv Format Expected = ['ImageId', 'BuildingId', 'PolygonWKT_Pix', 'PolygonWKT_Geo']
# returns list of Dictionaries {'ImageId': image_id, 'BuildingId': building_id, 'poly': poly}
# image_id is a string,
# BuildingId is an integer,
# poly is a ogr.Geometry Polygon
buildinglist = []
with open(csv_path, 'rb') as csvfile:
building_reader = csv.reader(csvfile, delimiter=',', quotechar='"')
next(building_reader, None) # skip the headers
for row in building_reader:
if removeNoBuildings:
if int(row[1]) != -1:
polyPix = ogr.CreateGeometryFromWkt(row[2])
if groundTruthFile:
polyGeo = ogr.CreateGeometryFromWkt(row[3])
else:
polyGeo = []
buildinglist.append({'ImageId': row[0], 'BuildingId': int(row[1]), 'polyPix': polyPix,
'polyGeo': polyGeo,
})
else:
polyPix = ogr.CreateGeometryFromWkt(row[2])
if groundTruthFile:
polyGeo = ogr.CreateGeometryFromWkt(row[3])
else:
polyGeo = []
buildinglist.append({'ImageId': row[0], 'BuildingId': int(row[1]), 'polyPix': polyPix,
'polyGeo': polyGeo,
})
return buildinglist
评论列表
文章目录