Combine Overlapping Extents¶
This example shows how to merge overlapping extents. This is useful if you need to combine data from partially overlapping sources.
In [1]:
Copied!
import geokit.core.extent
import geokit.core.srs
import geokit.core.geom
import geokit.core.extent
import geokit.core.srs
import geokit.core.geom
In [2]:
Copied!
# Define two overlapping extents
ext1 = geokit.core.extent.Extent(6.00, 50.00, 6.75, 51.25, srs=geokit.core.srs.EPSG4326)
ext2 = geokit.core.extent.Extent(6.25, 50.25, 7.00, 51.50, srs=geokit.core.srs.EPSG4326)
# Combine them: ext3 will represent the bounding box that covers BOTH
ext3 = ext1 + ext2
# Define two overlapping extents
ext1 = geokit.core.extent.Extent(6.00, 50.00, 6.75, 51.25, srs=geokit.core.srs.EPSG4326)
ext2 = geokit.core.extent.Extent(6.25, 50.25, 7.00, 51.50, srs=geokit.core.srs.EPSG4326)
# Combine them: ext3 will represent the bounding box that covers BOTH
ext3 = ext1 + ext2
In [3]:
Copied!
# This 'box' property (converts Extent to an OGR Geometry) and
# is useful for plotting or spatial intersections
# Visualize (if in a Jupyter environment)
AxH = geokit.core.geom.drawGeoms([ext3.box], figsize=(6, 6), fc="None", ec="#E58776", lw=5)
AxH2 = geokit.core.geom.drawGeoms([ext1.box, ext2.box], ax=AxH.ax, fc="#9CB0EC", ec="#132763", lw=1)
# This 'box' property (converts Extent to an OGR Geometry) and
# is useful for plotting or spatial intersections
# Visualize (if in a Jupyter environment)
AxH = geokit.core.geom.drawGeoms([ext3.box], figsize=(6, 6), fc="None", ec="#E58776", lw=5)
AxH2 = geokit.core.geom.drawGeoms([ext1.box, ext2.box], ax=AxH.ax, fc="#9CB0EC", ec="#132763", lw=1)