%matplotlib inline
import geopandas as gpd
import pysal as ps
import pandas as pd
import numpy as np
from shapely.geometry import Point
pts = gpd.read_file(ps.examples.get_path('columbus.shp')).centroid
pts.plot();
xys = pd.DataFrame(pts.apply(lambda pt: pd.Series({'X': pt.x, 'Y': pt.y})))
xys.head()
X | Y | |
---|---|---|
0 | 8.827218 | 14.369076 |
1 | 8.332658 | 14.031624 |
2 | 9.012265 | 13.819719 |
3 | 8.460801 | 13.716962 |
4 | 9.007982 | 13.296366 |
new_pts = gpd.GeoDataFrame({'geometry':
xys.apply(lambda r: Point(r['X'], r['Y']), axis=1)
}, crs=pts.crs)
new_pts.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x1236d6198>