pysal.lib.weights.get_points_array_from_shapefile

pysal.lib.weights.get_points_array_from_shapefile(shapefile)[source]

Gets a data array of x and y coordinates from a given shapefile.

Parameters:
shapefile : string

name of a shape file including suffix

Returns:
points : array

(n, 2) a data array of x and y coordinates

Notes

If the given shape file includes polygons, this function returns x and y coordinates of the polygons’ centroids

Examples

Point shapefile

>>> import pysal.lib
>>> from pysal.lib.weights.util import get_points_array_from_shapefile
>>> xy = get_points_array_from_shapefile(pysal.lib.examples.get_path('juvenile.shp'))
>>> xy[:3] 
array([[94., 93.],
       [80., 95.],
       [79., 90.]])

Polygon shapefile

>>> xy = get_points_array_from_shapefile(pysal.lib.examples.get_path('columbus.shp'))
>>> xy[:3]
array([[ 8.82721847, 14.36907602],
       [ 8.33265837, 14.03162401],
       [ 9.01226541, 13.81971908]])