pysal多边形对象不返回质心

2024-03-28 22:38:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用pysal/cenpy提取地理信息,但是对象通过调用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'

对来自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)

如何纠正错误?你知道吗


Tags: importmapdataastypeservicetablecon
1条回答
网友
1楼 · 发布于 2024-03-28 22:38:04

虽然这并不能直接回答您的问题,但是有一个更新的cenpyout预发布版本,它更加精简,可以避免您上面描述的问题(参见下面的示例)。Instructions for installing the pre-release can be found herea 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)

相关问题 更多 >