Geoprocessing#
Geoprocessing Functions#
Functions with geometries:
Function |
Description |
Syntax |
|---|---|---|
Area |
Area of polygon |
|
Bounds |
Geometry extent: minX, minY, maxX, maxY |
|
Length |
Length of geometry |
|
Centroid |
Centroid of geometry |
|
Buffer |
Buffer |
|
Distance |
Distance between two geometries |
|
Intersection |
Provides the overlapped area |
|
Union |
Union of geometries, separating the overlapped area |
|
Cascading Unions |
Union of a list of geometries, separating the overlapped area |
|
Difference |
Erases the overlapped area |
|
SymDifference |
Erases the non-overlapped area |
|
Example#
import fiona
import shapely.geometry as shp
sch = {'geometry': 'Polygon',
'properties': {'Area': 'float:13.3'}}
data1_shp = r'C:\Data\data1.shp'
data2_shp = r'C:\Data\data2.shp'
targt_shp = r'C:\Data\target.shp'
with fiona.open(targt_shp, 'w', driver='ESRI Shapefile', schema=sch) as output:
for feat1 in fiona.open(data1_shp):
geom1 = shp.shape(feat1['geometry'])
for feat2 in fiona.open(data2_shp):
geom2 = shp.shape(feat2['geometry'])
if geom1.intersects(geom2):
interc = geom1.intersection(geom2)
area = interc.area
output.write({'geometry': shp.mapping(interc),
'properties': {'Area': area}})