How to use the geopandas.overlay function in geopandas

To help you get started, we’ve selected a few geopandas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bukun / book_python_gis / part010 / ch09_others / sec4_geopandas / test_4_geopandas_geom_x_x.py View on Github external
plt.show()
###############################################################################
res_intersection = gpd.overlay(df1,df2,how='intersection')
ax = res_intersection.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
###############################################################################
res_symdiff = gpd.overlay(df1, df2,
    how='symmetric_difference')
ax = res_symdiff.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
###############################################################################
res_difference = gpd.overlay(df1, df2, how='difference')
ax = res_difference.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
###############################################################################
res_identity = gpd.overlay(df1, df2, how='identity')
ax = res_identity.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
github bukun / book_python_gis / part010 / ch09_others / sec4_geopandas / test_4_geopandas_geom_x_x.py View on Github external
df1 = gpd.GeoDataFrame({'geometry': polys1, 'df1':[1,2]})
df2 = gpd.GeoDataFrame({'geometry': polys2, 'df2':[1]})
###############################################################################
ax = df1.plot(color='red')
df2.plot(ax=ax, color='green')
import matplotlib.pyplot as plt
plt.show()
###############################################################################
res_union = gpd.overlay(df1, df2, how='union')
###############################################################################
ax = res_union.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
###############################################################################
res_intersection = gpd.overlay(df1,df2,how='intersection')
ax = res_intersection.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
###############################################################################
res_symdiff = gpd.overlay(df1, df2,
    how='symmetric_difference')
ax = res_symdiff.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
###############################################################################
res_difference = gpd.overlay(df1, df2, how='difference')
ax = res_difference.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
github bukun / book_python_gis / part010 / ch09_others / sec4_geopandas / test_4_geopandas_geom_x_x.py View on Github external
plt.show()
###############################################################################
res_union = gpd.overlay(df1, df2, how='union')
###############################################################################
ax = res_union.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
###############################################################################
res_intersection = gpd.overlay(df1,df2,how='intersection')
ax = res_intersection.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
###############################################################################
res_symdiff = gpd.overlay(df1, df2,
    how='symmetric_difference')
ax = res_symdiff.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
###############################################################################
res_difference = gpd.overlay(df1, df2, how='difference')
ax = res_difference.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
plt.show()
###############################################################################
res_identity = gpd.overlay(df1, df2, how='identity')
ax = res_identity.plot()
df1.plot(ax=ax, facecolor='none')
df2.plot(ax=ax, facecolor='none')
github Servir-Mekong / hydra-floods / hydrafloods / fetch.py View on Github external
def findTiles(region, tiles):
    """Returns the tile IDs that need to be downloaded for
    a given region bounded by *region*."""

    if region is None:
        raise ValueError("No bounding box provided for study area. Aborting download!")
        ids = None
    else:
        intersection = gpd.overlay(region,tiles,how='intersection')

        if 'PATH' in intersection.columns:
            h,v = 'PATH','ROW'
        elif 'h' in intersection.columns:
            h,v = 'h','v'
        else:
            raise AttributeError('cannot parse the needed tile information from provided geopadas dataframe')

        ids = [(intersection.iloc[i][h],intersection.iloc[i][v]) for i in range(len(intersection))]

    return ids
github Oslandia / deeposlandia / deeposlandia / geometries.py View on Github external
geopandas.GeoDataFrame
        Set of ground-truth labels contained into the tile, characterized by
    their type (complete, unfinished or foundation) and their geometry

    """
    area = get_tile_footprint(
        raster_features, min_x, min_y, tile_width, tile_height
    )
    bdf = gpd.GeoDataFrame(
        crs=from_epsg(raster_features["srid"]), geometry=[area]
    )
    reproj_labels = labels.to_crs(epsg=raster_features["srid"])
    tile_items = gpd.sjoin(reproj_labels, bdf)
    if tile_items.shape[0] == 0:
        return tile_items[["condition", "geometry"]]
    tile_items = gpd.overlay(tile_items, bdf)
    tile_items = tile_items.explode()  # Manage MultiPolygons
    return tile_items[["condition", "geometry"]]
github ESA-PhiLab / OpenSarToolkit / ost / helpers / vector.py View on Github external
def difference(infile1, infile2, outfile):

    gdf1 = gpd.read_file(infile1)
    gdf2 = gpd.read_file(infile2)

    gdf3 = gpd.overlay(gdf1, gdf2, how='symmetric_difference')

    gdf3.to_file(outfile)
github Servir-Mekong / hydra-floods / hydrafloods / fetch.py View on Github external
verts = [(float(pt['PointLongitude']),float(pt['PointLatitude'])) for pt in ptList]
        verts.append(verts[0])
        x,y = list(zip(*verts))

        maxDist = max([abs(x[-1]-x[i]) for i in range(len(x)-1)])

        if maxDist < 60:
            geoms.append(Polygon(verts))
            sdrnames.append(data["S4PAGranuleMetaDataFile"]['DataGranule']['GranuleID'])

    swathGeo = gpd.GeoDataFrame(pd.DataFrame({'sdr':sdrnames,'geometry':geoms}),geometry=geoms)

    swathGeo.crs = {'init':'epsg:4326'}

    intersection = gpd.overlay(region,swathGeo,how='intersection')

    return list(intersection.sdr)
github Servir-Mekong / hydra-floods / hydrafloods / fetch.py View on Github external
def findTiles(region, tiles):
    """Returns the tile IDs that need to be downloaded for
    a given region bounded by *region*."""

    if region is None:
        raise ValueError("No bounding box provided for study area. Aborting download!")
        ids = None
    else:
        intersection = gpd.overlay(region,tiles,how='intersection')

        if 'PATH' in intersection.columns:
            h,v = 'PATH','ROW'
        elif 'h' in intersection.columns:
            h,v = 'h','v'
        else:
            raise AttributeError('cannot parse the needed tile information from provided geopadas dataframe')

        ids = [(intersection.iloc[i][h],intersection.iloc[i][v]) for i in range(len(intersection))]

    return ids