Intersection and Union
Intersect and Union¶
Example for Intersection and Union of two geometries area1 and area2.
- Intersection of geoms: 'area1.Intersection(area2)'
- Union of geoms: 'area1.Union(area2)'
Important: All geometry operations need to happen in the same SRS! If they are not in the same srs, change to one srs: area2 = gk.geom.transform(area2, toSRS=area1.GetSpatialReference())
In [1]:
Copied!
import geokit.core.srs
import geokit.core.geom
import geokit.core.srs
import geokit.core.geom
In [2]:
Copied!
aachen_pt = geokit.core.geom.point((6.083, 52.775), srs=geokit.core.srs.EPSG4326)
print(type(aachen_pt))
# Get the buffer around this point
aachen_buffered_area = aachen_pt.Buffer(1)
aachen_pt = geokit.core.geom.point((6.083, 52.775), srs=geokit.core.srs.EPSG4326)
print(type(aachen_pt))
# Get the buffer around this point
aachen_buffered_area = aachen_pt.Buffer(1)
<class 'osgeo.ogr.Geometry'>
In [3]:
Copied!
# Geom 1:
axh = geokit.core.geom.drawGeoms(aachen_buffered_area, figsize=(5, 5), srs=4326)
# Geom 2:
box = geokit.core.geom.box(6, 52, 7, 53, srs=geokit.core.srs.EPSG4326)
geokit.core.geom.drawGeoms(box, figsize=(5, 5), srs=4326, ax=axh)
# Geom 1:
axh = geokit.core.geom.drawGeoms(aachen_buffered_area, figsize=(5, 5), srs=4326)
# Geom 2:
box = geokit.core.geom.box(6, 52, 7, 53, srs=geokit.core.srs.EPSG4326)
geokit.core.geom.drawGeoms(box, figsize=(5, 5), srs=4326, ax=axh)
Out[3]:
AxHands(ax=<Axes: >, handles=[<matplotlib.patches.PathPatch object at 0x7821d1ec5450>], cbar=None)
In [4]:
Copied!
# Intersection of geoms
intersect_geom = aachen_buffered_area.Intersection(box)
axh = geokit.core.geom.drawGeoms(intersect_geom, figsize=(5, 5), srs=4326)
# Intersection of geoms
intersect_geom = aachen_buffered_area.Intersection(box)
axh = geokit.core.geom.drawGeoms(intersect_geom, figsize=(5, 5), srs=4326)
In [5]:
Copied!
# Union of geoms
unioned_geom = aachen_buffered_area.Union(box)
axh = geokit.core.geom.drawGeoms(unioned_geom, figsize=(5, 5), srs=4326)
# Union of geoms
unioned_geom = aachen_buffered_area.Union(box)
axh = geokit.core.geom.drawGeoms(unioned_geom, figsize=(5, 5), srs=4326)