2

I am trying to perform a spatial autocorrelation function on a shapefile(shp). How do i generate a queen contiguity for this?

I read the pysal documentation and saw the 'queen_from_shapefile' but I get an error.

This is my code:

shp= gpd.read_file(r'..\data\districts.shp')
Q_w = ps.queen_from_shapefile(shp)

The error i keep getting is

AttributeError: module 'pysal' has no attribute 'queen_from_shapefile'
John_gis
  • 117
  • 8

2 Answers2

2

You can generate Queen contiguity from Geopandas GeoDataFrame using following script:

Q_w = ps.lib.weights.Queen.from_dataframe(shp)

queen_from_shapefile is not relevant since you are passing gdf anyway. I think it is no longer used, documentation might be outdated.

martinfleis
  • 7,124
  • 2
  • 22
  • 30
1

could also use:

libpysal.weights.contiguity.Queen()

Hadiyan
  • 11
  • 1