Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support transformations of coordinates given as numpy arrays #4

Closed
coroa opened this issue Feb 25, 2015 · 6 comments
Closed

Support transformations of coordinates given as numpy arrays #4

coroa opened this issue Feb 25, 2015 · 6 comments

Comments

@coroa
Copy link

coroa commented Feb 25, 2015

The docstring of Proj.__call__ states that it would be possible to pass an ndarray of shape (n,2), but the supporting code is commented out in __call__ as well as the cython defined methods of _invn and _fwdn.

What is the problem with these? It would help a lot if they were supported again.

@BrenBarn
Copy link

I just came across this as well. What the heck is going on there?

@timothyb0912
Copy link

I also had a problem today when I wished to use the support for arrays but encountered the following error when passing an array of shape n,2 to the projection instance: ValueError: need more than 1 value to unpack.

The documentation should at least be changed so as not to mislead people into thinking that there is support for arrays.

@danielramosg
Copy link

Same error for me. Can someone give an explanation of why numpy arguments are no longer supported? It would help a lot if fixed.

@ghost
Copy link

ghost commented Jun 4, 2019

I think Transformer.transform() recently introduced with #189 closes this longstanding issue.

@snowman2
Copy link
Member

snowman2 commented Jun 9, 2019

Here is the current recommended method to transform 2D numpy arrays with pyproj 2.x:

>>> from shapely.geometry import LineString, Point
>>> import numpy
>>> ll = LineString([Point(ii, ii) for ii in numpy.arange(0, 90, 0.01)])
>>> points = numpy.asarray(ll)
>>> points
array([[0.000e+00, 0.000e+00],
       [1.000e-02, 1.000e-02],
       [2.000e-02, 2.000e-02],
       ...,
       [8.997e+01, 8.997e+01],
       [8.998e+01, 8.998e+01],
       [8.999e+01, 8.999e+01]])
>>> from pyproj import Transformer
>>> transformer = Transformer.from_crs("epsg:4326", "epsg:3857")
>>> points_3857 = numpy.empty(points.shape)
>>> points_3857[:, 0], points_3857[:, 1] = transformer.transform(points[:, 0], points[:, 1])
>>> points_3857
array([[0.00000000e+00, 0.00000000e+00],
       [1.11319491e+03, 1.11319491e+03],
       [2.22638982e+03, 2.22638986e+03],
       ...,
       [1.00154146e+07, 5.26064404e+07],
       [1.00165278e+07, 5.51925525e+07],
       [1.00176410e+07, 5.96135402e+07]])

@snowman2
Copy link
Member

snowman2 commented Jun 9, 2019

I believe with #38 and #4 (comment), this issue has been resolved. Feel free to continue the discussion if you have further questions.

@snowman2 snowman2 closed this as completed Jun 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants