本文整理汇总了Python中geometry.Geometry.set_prim_attr_string方法的典型用法代码示例。如果您正苦于以下问题:Python Geometry.set_prim_attr_string方法的具体用法?Python Geometry.set_prim_attr_string怎么用?Python Geometry.set_prim_attr_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geometry.Geometry
的用法示例。
在下文中一共展示了Geometry.set_prim_attr_string方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: shp2geo
# 需要导入模块: from geometry import Geometry [as 别名]
# 或者: from geometry.Geometry import set_prim_attr_string [as 别名]
def shp2geo(sf):
geometry = Geometry()
index_admin = sf.get_field("ADMIN")
index_iso2 = sf.get_field("ISO_A2")
p = 0
for s, shaperecord in enumerate(sf.records()):
shaperecord = sf.shapeRecord(s)
admin = shaperecord.record[index_admin]
iso2 = shaperecord.record[index_iso2]
parts = shaperecord.shape.parts
part_shapes = []
for i, point in enumerate(shaperecord.shape.points):
if i in parts:
part_shapes.append([])
part_shapes[-1].append(point)
p += len(part_shapes)
for part_shape in part_shapes:
point_numbers = []
for point in part_shape[:-1]: # because it's closed
point_number = geometry.add_point(trunc(point[0]), trunc(point[1]), 0.0)
point_numbers.append(point_number)
prim_number = geometry.add_prim(point_numbers)
geometry.set_prim_attr_string("iso2", prim_number, iso2)
geometry.set_prim_attr_int("prim", prim_number, prim_number)
log.warning(repr((s, p)))
d = defaultdict(int)
for p, point in enumerate(geometry.points):
d[point] += 1
for p, point in enumerate(geometry.points):
geometry.set_point_attr_int("freq", p, d[point])
return geometry
示例2: shp2geo
# 需要导入模块: from geometry import Geometry [as 别名]
# 或者: from geometry.Geometry import set_prim_attr_string [as 别名]
def shp2geo(sf, iso32, border_switch, border_deny):
geometry = Geometry()
index_iso3_left = sf.get_field("adm0_a3_l")
index_iso3_right = sf.get_field("adm0_a3_r")
index_type = sf.get_field("type")
p = 0
for s, shaperecord in enumerate(sf.records()):
shaperecord = sf.shapeRecord(s)
iso3_left = shaperecord.record[index_iso3_left]
iso3_right = shaperecord.record[index_iso3_right]
type_ = shaperecord.record[index_type]
try:
iso2_left = iso32[iso3_left]
iso2_right = iso32[iso3_right]
except KeyError as e:
log.warning(repr((iso3_left, iso3_right, str(e))))
raise e
border_key = tuple(sorted([iso2_left, iso2_right]))
if border_key in border_switch:
log.warning(repr(border_switch))
log.warning("switch %s -> %s" % (repr(border_key), repr(border_switch[border_key])))
iso2_left, iso2_right = border_switch[border_key]
border_key = tuple(sorted([iso2_left, iso2_right]))
log.info(shaperecord.shape.parts)
if border_key in border_deny:
log.warning("inhibit %s" % repr(border_key))
continue
if iso2_left == iso2_right:
continue
if hasattr(shaperecord.shape, "parts"):
parts = shaperecord.shape.parts
else:
log.warning(s)
parts = []
part_shapes = []
for i, point in enumerate(shaperecord.shape.points):
if i in parts:
part_shapes.append([])
part_shapes[-1].append(point)
p += len(part_shapes)
for part_shape in part_shapes:
point_numbers = []
for point in part_shape[:]: # because it's open
point_number = geometry.add_point(trunc(point[0]), trunc(point[1]), 0.0)
point_numbers.append(point_number)
prim_number = geometry.add_prim(point_numbers, closed=False)
geometry.set_prim_attr_string('iso2_left', prim_number, iso2_left)
geometry.set_prim_attr_string('iso2_right', prim_number, iso2_right)
geometry.set_prim_attr_string('type', prim_number, type_)
geometry.set_prim_attr_int('prim', prim_number, prim_number)
d = defaultdict(int)
for p, point in enumerate(geometry.points):
d[point] += 1
for p, point in enumerate(geometry.points):
geometry.set_point_attr_int('freq', p, d[point])
return geometry