Created
June 20, 2018 13:25
-
-
Save yassineAlouini/d76d16d45a82b6a08a921d9ba74f5a94 to your computer and use it in GitHub Desktop.
Some vectorized GIS operations
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
| # -*- coding: utf-8 -*- | |
| from functools import wraps | |
| import numpy as np | |
| from shapely import wkb | |
| def vectorize(**vectorize_kwargs): | |
| """ A (numpy) vectorizing decorator | |
| """ | |
| def _vectorize(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| return np.vectorize(func, **vectorize_kwargs)(*args, **kwargs) | |
| return wrapper | |
| return _vectorize | |
| @vectorize(otypes=['object']) | |
| def get_centroid(x): | |
| return wkb.loads(x, hex=True).centroid | |
| @vectorize(otypes=['object']) | |
| def wkb_hex_loads(x): | |
| return wkb.loads(x, hex=True) | |
| @vectorize(otypes=['object']) | |
| def wkb_hex_dumps(x): | |
| return wkb.dumps(x, hex=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment