将Compound Geometry类转换为Geopandas数据框架



我想将使用section-properties创建的几何图形转换为geoandas数据框架以进行进一步处理。但我很难解决相应的结构。

这是对文档中的示例07的修改。注意,我必须在几个位置将from shapely替换为from shapely.geometry

# sphinx_gallery_thumbnail_number = 2
import sectionproperties.pre.library.primitive_sections as sections
import sectionproperties.pre.library.steel_sections as steel_sections
from sectionproperties.pre.geometry import CompoundGeometry
from sectionproperties.pre.pre import Material
from sectionproperties.analysis.section import Section
# %%
# Create material properties
steel = Material(
name="Steel",
elastic_modulus=200e3,
poissons_ratio=0.3,
yield_strength=500,
density=8.05e-6,
color="grey",
)
timber = Material(
name="Timber",
elastic_modulus=8e3,
poissons_ratio=0.35,
yield_strength=20,
density=0.78e-6,
color="burlywood",
)
# %%
# Create 310UB40.4
ub = steel_sections.i_section(
d=304, b=165, t_f=10.2, t_w=6.1, r=11.4, n_r=8, material=steel
)
# %%
# Create timber panel on top of the UB
panel = sections.rectangular_section(d=50, b=600, material=timber)
panel = panel.align_center(ub).align_to(ub, on="top")
# Create intermediate nodes in panel to match nodes in ub
panel = (panel - ub) | panel
# %%
# Merge the two sections into one geometry object
section_geometry = CompoundGeometry([ub, panel])
# convert to geopandas dataframe
import geopandas
gdf = geopandas.GeoDataFrame(section_geometry)

结果是这个错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~AppDataLocalTempipykernel_39361875453072.py in <module>
1 import geopandas
----> 2 gdf = geopandas.GeoDataFrame(section_geometry)
C:ProgramDataAnaconda3libsite-packagesgeopandasgeodataframe.py in __init__(self, data, geometry, crs, *args, **kwargs)
133     def __init__(self, data=None, *args, geometry=None, crs=None, **kwargs):
134         with compat.ignore_shapely2_warnings():
--> 135             super().__init__(data, *args, **kwargs)
136 
137         # set_geometry ensures the geometry data have the proper dtype,
C:ProgramDataAnaconda3libsite-packagespandascoreframe.py in __init__(self, data, index, columns, dtype, copy)
754         else:
755             if index is None or columns is None:
--> 756                 raise ValueError("DataFrame constructor not properly called!")
757 
758             # Argument 1 to "ensure_index" has incompatible type "Collection[Any]";
ValueError: DataFrame constructor not properly called!

尝试将最后一行更改为

gdf = geopandas.GeoDataFrame(geometry=[section_geometry.geom])

输出:

geometry
0  MULTIPOLYGON (((0.000 0.000, 165.000 0.000, 16...

最新更新