@@ -416,7 +416,7 @@ def to_latlong(self):
416416 return Proj (self .crs .to_geodetic ())
417417
418418
419- def transform (p1 , p2 , x , y , z = None ):
419+ def transform (p1 , p2 , x , y , z = None , radians = False ):
420420 """
421421 x2, y2, z2 = transform(p1, p2, x1, y1, z1)
422422
@@ -427,7 +427,10 @@ def transform(p1, p2, x, y, z=None):
427427 transformed to x2,y2,z2 in the coordinate system defined by p2.
428428
429429 z1 is optional, if it is not set it is assumed to be zero (and
430- only x2 and y2 are returned).
430+ only x2 and y2 are returned). If the optional keyword
431+ 'radians' is True (default is False), then all input and
432+ output coordinates will be in radians instead of the default
433+ of degrees for geographic input/output projections.
431434
432435 In addition to converting between cartographic and geographic
433436 projection coordinates, this function can take care of datum
@@ -489,6 +492,11 @@ def transform(p1, p2, x, y, z=None):
489492 >>> x3, y3 = transform("epsg:4326", "epsg:3857", 33, 98)
490493 >>> "%.3f %.3f" % (x3, y3)
491494 '10909310.098 3895303.963'
495+ >>> pj = Proj(init="epsg:4214")
496+ >>> pjx, pjy = pj(116.366, 39.867)
497+ >>> xr, yr = transform(pj, Proj(4326), pjx, pjy, radians=True)
498+ >>> "%.3f %.3f" % (xr, yr)
499+ '2.031 0.696'
492500 """
493501 # check that p1 and p2 are valid
494502 if not isinstance (p1 , Proj ):
@@ -504,7 +512,7 @@ def transform(p1, p2, x, y, z=None):
504512 else :
505513 inz = None
506514 # call pj_transform. inx,iny,inz buffers modified in place.
507- _proj ._transform (p1 , p2 , inx , iny , inz )
515+ _proj ._transform (p1 , p2 , inx , iny , inz , radians )
508516 # if inputs were lists, tuples or floats, convert back.
509517 outx = _convertback (xisfloat , xislist , xistuple , inx )
510518 outy = _convertback (yisfloat , yislist , xistuple , iny )
@@ -515,7 +523,7 @@ def transform(p1, p2, x, y, z=None):
515523 return outx , outy
516524
517525
518- def itransform (p1 , p2 , points , switch = False ):
526+ def itransform (p1 , p2 , points , switch = False , radians = False ):
519527 """
520528 points2 = transform(p1, p2, points1)
521529 Iterator/generator version of the function pyproj.transform.
@@ -534,7 +542,9 @@ def itransform(p1, p2, points, switch=False):
534542 - a generator of coordinates (xi,yi) for 2d points or (xi,yi,zi) for 3d
535543
536544 If optional keyword 'switch' is True (default is False) then x, y or lon,lat coordinates
537- of points are switched to y, x or lat, lon.
545+ of points are switched to y, x or lat, lon. If the optional keyword 'radians' is True
546+ (default is False), then all input and output coordinates will be in radians instead
547+ of the default of degrees for geographic input/output projections.
538548
539549
540550 Example usage:
@@ -555,6 +565,10 @@ def itransform(p1, p2, points, switch=False):
555565 '2221638.801 2637034.372'
556566 '2212924.125 2619851.898'
557567 '2238294.779 2703763.736'
568+ >>> pj = Proj(init="epsg:4214")
569+ >>> pjx, pjy = pj(116.366, 39.867)
570+ >>> for pt in itransform(pj, Proj(4326), [(pjx, pjy)]): '{:.3f} {:.3f}'.format(*pt)
571+ '2.031 0.696'
558572 """
559573 if not isinstance (p1 , Proj ):
560574 p1 = CRS .from_user_input (p1 )
@@ -582,7 +596,7 @@ def itransform(p1, p2, points, switch=False):
582596 if len (buff ) == 0 :
583597 break
584598
585- _proj ._transform_sequence (p1 , p2 , stride , buff , switch )
599+ _proj ._transform_sequence (p1 , p2 , stride , buff , switch , radians )
586600
587601 for pt in zip (* ([iter (buff )] * stride )):
588602 yield pt
0 commit comments