Skip to content

Commit

Permalink
Merge pull request #5 from snorfalorpagus/patch-1
Browse files Browse the repository at this point in the history
Use shapely.ops.transform in example
  • Loading branch information
urschrei committed Sep 6, 2019
2 parents 10b077d + 8395403 commit 839994a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions README.md
Expand Up @@ -64,12 +64,28 @@ lats_np = np.array(lats)
# b is (2.0, 4.0)

### But I have `Shapely` Geometries
from shapely.geometry import LineString

ls = LineString([[651307.003, 313255.686], [651307.004, 313255.687]])
new_linestring = LineString(
zip(*convert_etrs89_to_lonlat(*zip(*ls.coords)))
)
```python
from convertbng.util import convert_etrs89_to_lonlat
from shapely.geometry import LineString
from shapely.ops import transform
from math import isnan
from functools import partial

def transform_protect_nan(f, xs, ys):
# This function protects Shapely against NaN values in the output of the
# transform, which would otherwise case a segfault.
xs_t, ys_t = f(xs, ys)
assert not any([isnan(x) for x in xs_t]), "Transformed xs contains NaNs"
assert not any([isnan(y) for y in ys_t]), "Transformed ys contains NaNs"
return xs_t, ys_t

convert_etrs89_to_lonlat_protect_nan = partial(transform_protect_nan, convert_etrs89_to_lonlat)

line = LineString([[651307.003, 313255.686], [651307.004, 313255.687]])

new_line = transform(convert_etrs89_to_lonlat_protect_nan, line)
```

# Experimental Cython Module
If you're comfortable with restricting yourself to `NumPy f64` arrays, you may use the Cython functions instead. These are identical to those listed below, and are selected by changing the import statement
Expand Down

0 comments on commit 839994a

Please sign in to comment.