Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python conversion between coordinates

Are there functions for conversion between different coordinate systems?

For example, Matlab has [rho,phi] = cart2pol(x,y) for conversion from cartesian to polar coordinates. Seems like it should be in numpy or scipy.

like image 862
cpc333 Avatar asked Jan 04 '14 17:01

cpc333


People also ask

How do you change the projection in Python?

Changing the projection is really easy to do in Geopandas with . to_crs() -function. As an input for the function, you should define the column containing the geometries, i.e. geometry in this case, and a epgs value of the projection that you want to use. Let's see how the coordinates look now.


1 Answers

Using numpy, you can define the following:

import numpy as np  def cart2pol(x, y):     rho = np.sqrt(x**2 + y**2)     phi = np.arctan2(y, x)     return(rho, phi)  def pol2cart(rho, phi):     x = rho * np.cos(phi)     y = rho * np.sin(phi)     return(x, y) 
like image 155
nzh Avatar answered Oct 02 '22 12:10

nzh