GeoDjango is based on the GEOS library as Shapely. If you don't use Django it is more interesting to work with this module (many examples in GIS SE)
Following the explanations of GEOS: Prepared Geometries, a Prepared Geometry is a spatial predicate (only True or False). Geometries are "prepared" ala SQL for efficient batch operations (Efficient batch operations for Shapely)
myPolygon.intersects(lineAB)
lineAB.intersects(myPolygon)
myPreparedPolygont.intersects(lineAB)
With Shapely
from shapely.prepared import prep
myPolygon.intersects(lineAB)
lineAB.intersects(myPolygon)
prep(myPolygon).intersects(line)
give the same result, True
.
The only difference is the speed if you work with many objects (see Efficient batch operations for Shapely) as a Spatial Index (More Efficient Spatial join in Python without QGIS, ArcGIS, PostGIS, etc).
The performance gains from using PreparedGeometry in real-world situations can be dramatic - up to 40 times improvement in speed (PreparedGeometry - efficient batch spatial operations for JTS )
With GeoDjango or Shapely
res = [line for line in lines if myPolygon.intersects(line)]
# and
res = [line for line in lines if myPreparedPolygont.intersects(line)]
In your example, the only solution (or use a Spatial Index) is the result of
With GeoDjango or Shapely
len(lineAB.intersection(myPolygon))
2 # -> MultiLineString

Compare with the upper line (green) where thelen = 1
(simple LineString)
Or the inverse with
lineAB.difference(myPolygon)
