libpysal.weights.get_points_array_from_shapefile¶
- libpysal.weights.get_points_array_from_shapefile(shapefile)[source]¶
Gets a data array of x and y coordinates from a given shapefile.
- Parameters:
- shapefile
str
name of a shape file including suffix
- shapefile
- Returns:
- points
array
(n, 2) a data array of x and y coordinates
- points
Notes
If the given shape file includes polygons, this function returns x and y coordinates of the polygons’ centroids
Examples
Point shapefile
>>> import libpysal >>> from libpysal.weights.util import get_points_array_from_shapefile >>> xy = get_points_array_from_shapefile( ... libpysal.examples.get_path('juvenile.shp') ... ) >>> xy[:3] array([[94., 93.], [80., 95.], [79., 90.]])
Polygon shapefile
>>> xy = get_points_array_from_shapefile( ... libpysal.examples.get_path('columbus.shp') ... ) >>> xy[:3] array([[ 8.82721847, 14.36907602], [ 8.33265837, 14.03162401], [ 9.01226541, 13.81971908]])