1

Shapely question: Given a list of linestrings (as coordinate arrays) to be reprojected - what is best way to reproject just using pyproj and shapely?

If I cast as an array of linestrings, and apply the transform on each in a list, I seem to be getting slightly better performance (~7-8%) than if I cast all linestrings into one parent MultiLineString and apply the transform once.

from pyproj import CRS, Transformer
from shapely.ops import transform

project_to_meter = Transformer.from_crs(
    CRS.from_epsg(4326),
    CRS.from_epsg(2163),
    always_xy=True)

option_1 = [LineString(path) for path in example_linestring_list]
option_2 = MultiLineString(mls_alt)

# method 2 seems to be ~7-8% faster - why? Is that the preferred pattern?
method_1 = transform(project_to_meter.transform, mls)
method_2 = [transform(project_to_meter.transform, x) for x in mls_alt]
kuanb
  • 1,618
  • 2
  • 20
  • 42
  • Answer: Method 2 is almost the same as what the transform method in Shapely is doing: https://github.com/Toblerity/Shapely/blob/cabea3a3a3aca6166dc1c2e1d0dfdcc5b6694987/shapely/ops.py#L255 TLDR it actually applies the transform on each element of the multilinestring and then recasts as a multi-ls. – kuanb Feb 28 '20 at 18:26

0 Answers0