What is the most efficient way to convert numpy arrays to Shapely Points?
I think this is a good way:
import numpy as np
from shapely import geometry
points_np_array = np.random.rand(50,2)
polygon_1 = geometry.Polygon(np.squeeze(points_np_array))
There is no built-in way to do this with shapely
, so you need to iterate through the values yourself. For doing that, this should be a rather efficient way:
In [4]: from geopandas import GeoSeries
In [5]: s = GeoSeries(map(Point, zip(x, y)))
In [6]: s.head()
Out[6]:
0 POINT (0 0)
1 POINT (1.01010101010101 0)
2 POINT (2.02020202020202 0)
3 POINT (3.03030303030303 0)
4 POINT (4.040404040404041 0)
dtype: object
In [6]: %timeit GeoSeries(map(Point, zip(x, y)))
114 ms ± 8.45 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
(or slight alternative GeoSeries(list(zip(x, y))).map(Point)
)
See here for some example doing this: http://geopandas.readthedocs.io/en/latest/gallery/create_geopandas_from_pandas.html
There is some (stalled) work to include this in geopandas directly: https://github.com/geopandas/geopandas/pull/75