I have two 1D arrays and want to combine them into one Point GeoSeries like this:
import numpy as np
from geopandas import GeoSeries
from shapely.geometry import Point
x = np.random.rand(int(1e6))
y = np.random.rand(int(1e6))
GeoSeries(map(Point, zip(x, y)))
It costs about 5 seconds on my laptop. Is it possible to accelerate the generation of GeoSeries?
Instead of using
map, to speed up this process, you need to use vectorized operations.points_from_xyfunction provided by GeoPandas is specifically optimized for this purpose. Here's an example run on my machine:Output:
see, the
points_from_xyis almost 10x times faster as this utilized a vectorized approach.Checkout
geopandas.points_from_xydocumentation from here to learn more: https://geopandas.org/en/stable/docs/reference/api/geopandas.points_from_xy.html