Created
April 27, 2018 12:22
-
-
Save yassineAlouini/bf889822b37188f72e5db14cd2b1688f 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
from shapely import wkb | |
import numpy as np | |
from functools import wraps | |
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): | |
# TODO: Add some documentation | |
# This might change depending on the input_df | |
return wkb.loads(x, hex=True).centroid | |
@vectorize(otypes=['object']) | |
def wkb_hex_loads(x): | |
return wkb.loads(x, hex=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment