Question:
How remove residual lines after merge two regions using Geopandas in python?

Here are the relevant steps including runnable code to remove residual lines after merge two regions using Geopandas:


import os

os.environ['USE_PYGEOS'] = '0'

import geopandas as gpd

from shapely.geometry import Polygon


# Create 2 geodataframes each containing a simple polygon 

polygon_geom1 = Polygon(zip([0, 1.05, 1.05, 0], [-0.1, -0.1, 1.2, 1.2]))

#crs = {'init': 'epsg:4326'}

crs = 'epsg:4326'

polygon1 = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[polygon_geom1])


polygon_geom2 = Polygon(zip([0+1, 1+1, 1+1, 0+1, 0.1+1, 0+1], [0,0,1,1,0.5,0]))

polygon2 = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[polygon_geom2])


# Plot to see them together

ax1 = polygon1.plot(ec='k', color='y')

polygon2.plot(ax=ax1, ec='r', color='lightgray', alpha=0.8)



Next, we do the union of the two geometries:-

polygon1.geometry.values[0].union(polygon2.geometry.values[0])


then, the exterior geometry:-

polygon1.geometry.values[0].union(polygon2.geometry.values[0]).exterior


and, finally, the interior geometry:-

# The interiors of the unioned geometry

# This show item 0 of them

polygon1.geometry.values[0].union(polygon2.geometry.values[0]).interiors[0]



Answered by: >swatchai

Credit:> StackOverflow


Suggested blogs:

>How to solve encoding issue when writing to a text file, with Python?

>Step by Step guide to Deploy Terraform in Azure using GitHub Actions

Testing react components using Hooks and Mocks

>Use Firebase Realtime Database with ASP.NET MVC App

>Use of Singletons in .NET Core in AWS Lambda

>What are common syntax errors and exceptions in Python

>What are the steps to fix error while downloading PDF file- Python

>How to do PHP Decryption from Node.js Encryption?

>How to do PHP gd Installation on Ubuntu?

>How to do Web Scraping with Python?


Submit
0 Answers