You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将section-properties的CompoundGeometry转换为GeoDataFrame?

How to Convert section-properties CompoundGeometry to GeoPandas GeoDataFrame

The error you're seeing happens because you can't directly pass a CompoundGeometry object to GeoPandas' GeoDataFrame constructor — GeoPandas expects explicit, Shapely-compatible geometry objects paired with structured attribute data. Let's fix this by breaking down the CompoundGeometry into its components and formatting them correctly for GeoPandas.

Step-by-Step Solution

  1. Extract Shapely Geometries and Attributes
    A CompoundGeometry is essentially a collection of individual geometry objects (your steel UB and timber panel here). Each of these sub-geometries can be converted to a Shapely polygon using the to_shapely() method. We'll also pull out relevant material properties to include as columns in our GeoDataFrame.

  2. Build a Structured Data Dictionary
    We'll collect all the geometries and attributes into lists, then package them into a dictionary that GeoPandas can interpret properly.

Modified Code for Conversion

Replace your existing GeoPandas conversion code with this:

import geopandas as gpd

# Initialize lists to store our data
geometries = []
material_names = []
elastic_moduli = []
yield_strengths = []

# Iterate over each sub-geometry in the CompoundGeometry
for geom in section_geometry.geoms:
    # Convert section-properties geometry to Shapely object (GeoPandas-compatible)
    shapely_geom = geom.to_shapely()
    geometries.append(shapely_geom)
    
    # Extract material properties from the geometry
    mat = geom.material
    material_names.append(mat.name)
    elastic_moduli.append(mat.elastic_modulus)
    yield_strengths.append(mat.yield_strength)

# Create the GeoDataFrame
gdf = gpd.GeoDataFrame(
    data={
        "material": material_names,
        "elastic_modulus": elastic_moduli,
        "yield_strength": yield_strengths,
        "geometry": geometries
    },
    crs=None  # Set to a valid CRS like "EPSG:4326" if you're working with spatial coordinates
)

What This Does

  • geom.to_shapely(): Converts each section-properties geometry into a Shapely Polygon or MultiPolygon, which is the standard geometry format GeoPandas uses.
  • Material Attributes: We pull in the material name, elastic modulus, and yield strength as additional columns — you can add more properties (like density or color) following the same pattern.
  • GeoDataFrame Construction: By passing a dictionary with a geometry key, GeoPandas automatically recognizes that column as the spatial data column.

Verify the Result

You can check that the conversion worked by printing the GeoDataFrame:

print(gdf)
print("\nGeometry types:")
print(gdf.geometry.type)

This will output a table with your material properties paired with their respective geometries, ready for further spatial analysis in GeoPandas.

内容的提问来源于stack exchange,提问作者meshWorker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 10:01:46