Im trying to create a new geodataframe with a point as one of the Attributes. It's all going to happen in a loop in the end, as I then want to concat multiple gdf's into one, but what is giving me a headache is this part:
from shapely.geometry import Point
import geopandas as gpd
ptX = 13.435621213 #row2['geometry'].x
ptY = 52.480377234 #row2['geometry'].y
gdf_this = gpd.GeoDataFrame({('name', Point(ptX, ptY))})
as it gives the Error:
TypeError: unhashable type: 'Point'
I assume it has something to do with the reference vs copy thing, so I've tried creating a temporary point first and then using
gdf_this = gpd.GeoDataFrame({('name', copy.deepcopy(temp_point))})
but that gives the same error.
The documentation for shapely.Points lists a method reverse() which is supposed to return a copy of the geometry, but Point(ptX, ptY).reverse() gives the Error AttributeError: 'Point' object has no attribute 'reverse'?!?
There are a few steps you better to consider:
1. Resolving the TypeError: unhashable type: 'Point':
Use a list of tuples: GeoDataFrame expects a list of tuples for its data, even when creating a single-row DataFrame. Here's the corrected code:
2. Clarifying the AttributeError: 'Point' object has no attribute 'reverse':
Shapely's reverse() method: It's primarily used for line-like geometries (LineStrings, MultiLineStrings) to reverse their coordinates. Points don't have a meaningful "reverse" operation, hence the error. Corrected code for creating multiple GeoDataFrames and concatenating them: