Created
February 16, 2015 16:13
-
-
Save is/31f063f0799f2a4d6ee5 to your computer and use it in GitHub Desktop.
Shapely & Fiona sample code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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