Skip to content

Instantly share code, notes, and snippets.

@is
Created February 16, 2015 16:13
Show Gist options
  • Select an option

  • Save is/31f063f0799f2a4d6ee5 to your computer and use it in GitHub Desktop.

Select an option

Save is/31f063f0799f2a4d6ee5 to your computer and use it in GitHub Desktop.
Shapely & Fiona sample code.
import fiona
from shapely.geometry import shape
from shapely.geometry import Polygon
from shapely.geometry import geo
p0 = geo.box(116, 22, 117, 23)
def main():
shapes = []
fa = fiona.open('c1/continent.shp')
n = 0
ps = 0
for r in fa:
n += 1
g = r['geometry']
print(g['type'])
m = 0
for p in g['coordinates']:
m += 1
ps += len(p[0])
if len(p) <= 1:
continue
print('%d.%d:%d' % (n, m, len(p[0])))
x = shape(g)
shapes.append(x)
fa.close()
for s in shapes:
x = s.intersection(p0)
if (x.is_empty):
continue
print(x.exterior)
print(x.exterior.length)
v = x.exterior.difference(p0.exterior)
print(v)
print(v.length)
print(v.buffer(0.0005).area)
print(ps)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment