问题描述
我使用 pyshp 库来检索形状的坐标。
sf = shapefile.Reader(r"{}".format(boundary_file))
shapes = sf.shapes()
fields = sf.fields
records = sf.records()
for record in records:
if record['NAME'] in cities_list:
city = record['NAME']
s = sf.shape(record_id)
geom = s.__geo_interface__
geom_list = []
for dict in geom:
if dict == "coordinates":
coord_dict = geom[dict]
coords = coord_dict[0]
for pairs in coords:
geom_list.append(pairs)
然后我需要根据'geom' dict 中的坐标创建一个字符串。 我使用的功能:
def listToString(s):
# initialize an empty string
str1 = ""
# traverse in the string
for ele in s:
str1 += "'{}',".format(ele)
# return string
return str1
我进一步处理字符串以删除除坐标之外的任何其他字符。
我的问题是存在一个我无法删除的换行符。
打印 print(listToString(geom_list ))
时,我注意到在特定数量的字符后有一个换行符
这是它在记事本++中的样子。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)