【问题标题】:pysal polygon object not returning centroidpysal多边形对象不返回质心
【发布时间】:2019-01-07 12:37:37
【问题描述】:

我使用 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)

如何纠正错误?

【问题讨论】:

    标签: python python-3.x pysal


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2013-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      相关资源
      最近更新 更多