def set_ogr_feature_attribute(attr, value, feature):
attr_name = attr.name
if value == None:
feature.UnsetField(attr_name)
return
if attr.type == ogr.OFTInteger:
feature.SetField(attr_name, int(value))
elif attr.type == ogr.OFTIntegerList:
integers = eval(value)
feature.SetFieldIntegerList(attr_name, integers)
elif attr.type == ogr.OFTReal:
feature.SetField(attr_name, float(value))
elif attr.type == ogr.OFTRealList:
floats = []
for s in eval(value):
floats.append(eval(s))
feature.SetFieldDoubleList(attr_name, floats)
elif attr.type == ogr.OFTString:
feature.SetField(attr_name, value)
elif attr.type == ogr.OFTStringList:
strings = []
for s in eval(value):
strings.append(s.encode(encoding))
feature.SetFieldStringList(attr_name, strings)
elif attr.type == ogr.OFTDate:
parts = value.split(",")
year = int(parts[0])
month = int(parts[1])
day = int(parts[2])
tzone = int(parts[3])
feature.SetField(attr_name, year, month, day,
0, 0, 0, tzone)
elif attr.type == ogr.OFTTime:
parts = value.split(",")
hour = int(parts[0])
minute = int(parts[1])
second = int(parts[2])
tzone = int(parts[3])
feature.SetField(attr_name, 0, 0, 0,
hour, minute, second, tzone)
elif attr.type == ogr.OFTDateTime:
parts = value.split(",")
year = int(parts[0])
month = int(parts[1])
day = int(parts[2])
hour = int(parts[3])
minute = int(parts[4])
second = int(parts[5])
tzone = int(parts[6])
feature.SetField(attr_mame, year, month, day,
hour, minute, second, tzone)
utils.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录