-
I want to test if some polygons touch the others to create a map with different colors for different regions, by using greedy_color (with Here is a reproducible example: import geopandas as gpd
import networkx as nx
gdf = gpd.read_file('BlackSea_0.json')
# Create an empty graph
G = nx.Graph()
# Add a node for each polygon
for index, row in gdf.iterrows():
G.add_node(index, polygon=row['geometry'])
# Test if the 2 polygons touch
G.nodes(data=True)[0]["polygon"].touches(G.nodes(data=True)[1]["polygon"]) I attached the screen capture I was wondering if I misunderstood something? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
It looks like the key function/method here is You can cut to the heart of the issue without using networkx: import geopandas as gpd
gdf = gpd.read_file('BlackSea_0.json')
p0, p1 = gdf['geometry']
p0.touches(p1) # returns False |
Beta Was this translation helpful? Give feedback.
-
Glad you found a solution. |
Beta Was this translation helpful? Give feedback.
I replaced
touches
withintersects
, and as far as I see, everything worked as expected!Thank you very much!