1
votes

I used pysal/cenpy to extract geo info, but the object is returning errors by calling centroid

import cenpy as cen
import pysal as ps
import geopandas as gpd 

dataset = 'ACSSF5Y2015'
con = cen.base.Connection(dataset)

con.set_mapservice('tigerWMS_ACS2017') 
geotmp = con.mapservice.query(layer=84, where='STATE=' + str(1))
type(geotmp)
#pandas.core.frame.DataFrame
type(geotmp.geometry[0])
#pysal.cg.shapes.Polygon

geotmp.geometry.centroid
AttributeError: 'Series' object has no attribute 'centroid'

Checked the same on a built-in dataset from the gds-scipy16

type(data_table)
#pandas.core.frame.DataFrame
type(data_table.geometry[0])
#pysal.cg.shapes.Polygon

data_table.geometry[0].centroid
#(-94.90336786329912, 48.771730563701574)

How to correct the error?

1

1 Answers

0
votes

Although this does not directly answer your question, there is a newer pre-release version of cenpy out that is much more streamlined and will avoid the problem you describe above (see example below). Instructions for installing the pre-release can be found here and a gist demonstrating functionality here.

import cenpy
cenpy.__version__
>>> '1.0.0dev'
florida = cenpy.products.Decennial2010().from_state('Florida')
>>> Matched: Florida to Florida, FL within layer States
type(florida)
>>> geopandas.geodataframe.GeoDataFrame
type(florida.geometry[0])
>>> shapely.geometry.polygon.Polygon
print(florida.geometry[0].centroid)
>>> POINT (-9734271.078405051 3547557.287300871)