6

I am new to geopandas and would like to plot only the outline of a polygon, similar to the function ST_Boundary() in PostGIS

I have a geodataframe states containing polygons for each state

states = counties.dissolve(by='STATEFP')

When I subset by one state, I am able to plot that state:

states.loc[states.index.isin(['06'])]['geometry']

I am only interested in the outline but it is not clear in the documentation how to convert a polygon to line geometry however. Is there a useful method in geopandas or another spatial library that might help in converting a polygon to a linestring?

enter image description here

iskandarblue
  • 7,208
  • 15
  • 60
  • 130

2 Answers2

6

You can get boundary as

states.boundary

Alternatively, if you want only exterior boundary you get it as

states.exterior

Those give you new GeoSeries with line geometry.

martinfleis
  • 7,124
  • 2
  • 22
  • 30
0

It seems like .exterior returns a geometry of type 'linear ring', whereas .boundary returns a geometry of type 'linestring' - this may be important when it comes to writing the line geometries to file - I had issues writing 'linear ring' to GPKG and SHP but it worked for 'linestring'.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 30 '22 at 09:35
  • Best to add this as a comment to the accepted answer. This is not a solution. – Binx Mar 14 '23 at 17:49