简体   繁体   中英

How to compute outline of geometry from union of geometries

How can I compute the outline corresponding to the union of a set of geometries? Specifically, given geometry of 50 states, I want the outline of the contiguous continental US.

Using gz_2010_us_040_00_5m.json from https://github.com/kjhealy/us-county/tree/master/data/geojson

import geopandas as gpd
import numpy as np

country = gpd.read_file("data/gz_2010_us_040_00_5m.json")
conus = country[country['NAME'].isin(['Alaska','Hawaii', 'Puerto Rico']) == False]

Now we have the outlines for each state. How can we join this into the outline of conus?

Here's what I ended up doing. First, I added a column 'country' to all the states, then used 'dissolve (by='country'):

conus.loc[:,'country'] = 'usa'  # produces warning, don't know how to avoid
us = conus.dissolve(by='country', aggfunc = 'sum')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM