如何将section-properties的CompoundGeometry转换为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
Extract Shapely Geometries and Attributes
ACompoundGeometryis 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 theto_shapely()method. We'll also pull out relevant material properties to include as columns in our GeoDataFrame.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 ShapelyPolygonorMultiPolygon, 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
geometrykey, 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

