簡體   English   中英

pysal多邊形對象不返回質心

[英]pysal polygon object not returning centroid

我使用pysal / cenpy提取了地理信息,但是對象通過調用質心返回了錯誤

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)

如何糾正錯誤?

盡管這不能直接回答您的問題,但是有一個新的cenpy out發行前版本可以簡化,並且可以避免您上面描述的問題(請參見下面的示例)。 可以在此處找到安裝預發行版的說明,在此處可以找到 演示功能的要點

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM