def diff_encode(line, transform):
 coords = [transform(x, y) for (x, y) in line.coords]
 pairs = zip(coords[:], coords[1:])
 diffs = [((x2 - x1), (y2 - y1)) for ((x1, y1), (x2, y2)) in pairs]
 return (coords[:1] + [(x, y) for (x, y) in diffs if ((x, y) != (0, 0))])

def diff_encode ( line , transform ) : coords = [ transform ( x , y ) for ( x , y ) in line . coords ] pairs = zip ( coords [ : ] , coords [ 1 : ] ) diffs = [ ( ( x2 - x1 ) , ( y2 - y1 ) ) for ( ( x1 , y1 ) , ( x2 , y2 ) ) in pairs ] return ( coords [ : 1 ] + [ ( x , y ) for ( x , y ) in diffs if ( ( x , y ) != ( 0 , 0 ) ) ] )
differentially encode a shapely linestring or ring .