使用Fiona可以打开shp或者geojson等数据,安装fiona库后,import,直接可以打开一个文件。

网址:https://github.com/Toblerity/Fiona

import fiona
#只读方式打开一个文件
shpdata = fiona.open(path, 'r')

#使用while循环shp数据的每条数据,因为循环是用next,所以使用except进行结束?
while True:
try:

evdata = shdata.next()
  except StopIteration:
       break
循环的evdata结果是一个json数据的样式:
{'geometry': {'coordinates': [(106.7322972, 26.4702006),
(106.730837, 26.4701069), (106.7294714, 26.4700042),
(106.7286771, 26.4699373)],
'type': 'LineString'},
'properties': OrderedDict([('osm_id', '230614887'),
('name', '环城公路'), ('highway...
 包含坐标信息和其中的属性信息
 
 使用shapely可以处理其中的空间数据,将json数据的坐标,传入到shape中,
即能进行空间的数据处理。
 
类库网址:https://github.com/Toblerity/Shapely   

#导入类库
from shapely.geometry import shape
#转换其中的空间数据
sh_geom = shape(evdata['geometry'])
shapely要基于python版的geos,可以做缓冲、相交等空间分析操作,还可以根据
坐标系转换其中的坐标。