Jawaban:
Perpotongan Polygon dan LineString adalah LineString dan perpotongan dua LineString adalah sebuah Point (atau MultiPoint), jadi Anda perlu mengubah Polygon Anda menjadi LineString -> Shapely: LinearRings
from shapely.geometry import shape
import fiona
# polygon layer
poly = fiona.open("polygons.shp")
# line layer
line = fiona.open("lines.shp")
# First Feature of the shapefiles
s_poly = shape(poly.next()['geometry'])
s_line = shape(line.next()['geometry'])
print s_poly.intersection(s_line)
LINESTRING (360.4742985178883 -286.9847328244275, 450.1982781776156 -140.6494330268984)
# transform the polygon into a LineString
ring = LineString(list(s_poly.exterior.coords))
print ring.intersection(line)
MULTIPOINT (360.4742985178883 -286.9847328244275, 450.1982781776156
# or, more formal
from shapely.geometry.polygon import LinearRing
lring = LinearRing(list(s_poly.exterior.coords))
print lring.intersection(s_line)
MULTIPOINT (360.4742985178883 -286.9847328244275, 450.1982781776156 -140.6494330268984)
Jika Anda memiliki banyak poligon dan banyak polyline:
Multi_pol_ext = MultiLineString([list(shape(pol['geometry']).exterior.coords) for pol in fiona.open("polygons.shp")])
Multi_lines = MultiLineString([shape(line['geometry']) for line in fiona.open("lines.shp")])
Multi_pol_ext.intersection(Multi_lines)
<shapely.geometry.multipoint.MultiPoint object at 0x1091a5210>