Expand Menu
-
Home / Documentation / Geo / Coordinate Converter / Index
coordinate_converter¶
In [ ]:
coordinate_converter(vdf: vDataFrame,
x: str,
y: str,
x0: float = 0.0,
earth_radius: float = 6371,
reverse: bool = False,)
Converts between geographic coordinates (latitude and longitude) and Euclidean coordinates (x,y).
Parameters¶
Name | Type | Optional | Description |
---|---|---|---|
vdf | vDataFrame | ❌ | input vDataFrame. |
x | str | ❌ | vcolumn used as abscissa (longitude). |
y | str | ❌ | vcolumn used as ordinate (latitude). |
x0 | float | ✓ | Initial abscissa. |
earth_radius | float | ✓ | Earth radius. |
reverse | bool | ✓ | If set to True, the Euclidean coordinates are converted to latitude and longitude. |
Returns¶
vDataFrame : result of the transformation.
Example¶
In [19]:
from verticapy.geo import *
from verticapy.datasets import load_cities
cities = load_cities()
cities["lat"] = "ST_X(geometry)"
cities["lon"] = "ST_Y(geometry)"
display(cities)
Abc cityVarchar(82) | 🌎 Geometry(1048576) | 🌎 latFloat | 🌎 lonFloat | |
1 | Abidjan | -4.04199411850709 | 5.32194282609856 | |
2 | Abu Dhabi | 54.366593382592 | 24.4666835723799 | |
3 | Abuja | 7.53138214293233 | 9.0852790077542 | |
4 | Accra | -0.218661598960694 | 5.55198046444593 | |
5 | Addis Ababa | 38.6980585753487 | 9.03525622129575 | |
6 | Algiers | 3.04860667090924 | 36.7650106566281 | |
7 | Amman | 35.9313540668741 | 31.9519711058275 | |
8 | Amsterdam | 4.91469431740097 | 52.3519145466644 | |
9 | Andorra | 1.51648596050552 | 42.5000014435459 | |
10 | Ankara | 32.8624457823566 | 39.9291844440755 | |
11 | Antananarivo | 47.5146780415299 | -18.9146914920322 | |
12 | Apia | -171.738641608603 | -13.8415450424484 | |
13 | Ashgabat | 58.3832991117746 | 37.949994933111 | |
14 | Asmara | 38.9333235257593 | 15.3333392526819 | |
15 | Astana | 71.427774209483 | 51.1811253042576 | |
16 | Asuncion | -57.6434510279013 | -25.2944571170577 | |
17 | Athens | 23.7313752256794 | 37.9852720905523 | |
18 | Baghdad | 44.3919229145641 | 33.3405943561586 | |
19 | Baku | 49.8602713032578 | 40.397217891343 | |
20 | Bamako | -8.0019849632497 | 12.6519605263233 | |
21 | Bandar Seri Begawan | 114.933284056662 | 4.88333111461924 | |
22 | Bangkok | 100.514698793695 | 13.751945064088 | |
23 | Bangui | 18.5582881252873 | 4.36664430634909 | |
24 | Banjul | -16.5917014892126 | 13.4538764603159 | |
25 | Basseterre | -62.7170093196993 | 17.3020304554894 | |
26 | Beijing | 116.386339825659 | 39.9308380899091 | |
27 | Beirut | 35.5077623513777 | 33.8739209756269 | |
28 | Belgrade | 20.4660448220205 | 44.8205913044467 | |
29 | Belmopan | -88.7670729998165 | 17.2520335072469 | |
30 | Berlin | 13.3996027647005 | 52.5237645222512 | |
31 | Bern | 7.46697546248242 | 46.9166827586677 | |
32 | Bishkek | 74.5832583639037 | 42.8750253050901 | |
33 | Bissau | -15.5983608413207 | 11.8650238229806 | |
34 | Bloemfontein | 26.2299128811774 | -29.1199938773787 | |
35 | Bogota | -74.0852898137744 | 4.59836942114782 | |
36 | Brasilia | -47.9179981470031 | -15.781394372879 | |
37 | Bratislava | 17.1169807522346 | 48.1500183299617 | |
38 | Brazzaville | 15.2827436338487 | -4.25723991319751 | |
39 | Bridgetown | -59.6165267350516 | 13.1020025827511 | |
40 | Brussels | 4.33137074969045 | 50.8352629353303 | |
41 | Bucharest | 26.0980007953504 | 44.4353176634946 | |
42 | Budapest | 19.0813748187597 | 47.5019521849914 | |
43 | Buenos Aires | -58.3994772323314 | -34.6005557499074 | |
44 | Bujumbura | 29.3600060615284 | -3.37608722037464 | |
45 | Cairo | 31.2480223611261 | 30.0519062051037 | |
46 | Canberra | 149.129026244299 | -35.2830285453721 | |
47 | Cape Town | 18.433042299226 | -33.9180651086288 | |
48 | Caracas | -66.9189830510504 | 10.5029444130333 | |
49 | Castries | -61.0000081803695 | 14.0019734893303 | |
50 | Chisinau | 28.8577111396514 | 47.0050236196706 | |
51 | Colombo | 79.8577506092564 | 6.93196575818212 | |
52 | Conakry | -13.6821808861239 | 9.53346870502179 | |
53 | Cotonou | 2.5180447405686 | 6.40195442278247 | |
54 | Dakar | -17.4750759870506 | 14.7177775836233 | |
55 | Damascus | 36.2980500304171 | 33.5019798542061 | |
56 | Dar es Salaam | 39.2663959776946 | -6.79806673612438 | |
57 | Dhaka | 90.4066336081075 | 23.7250055703128 | |
58 | Dili | 125.579455931705 | -8.55938840854645 | |
59 | Djibouti | 43.1480016670523 | 11.5950144642555 | |
60 | Doha | 51.5329678942993 | 25.2865560089066 | |
61 | Dublin | -6.25085154039107 | 53.3350069945849 | |
62 | Dushanbe | 68.7738793527017 | 38.5600352163166 | |
63 | Freetown | -13.2361615990127 | 8.47195727109818 | |
64 | Funafuti | 179.216647094029 | -8.51665199904107 | |
65 | Gaborone | 25.9119477932854 | -24.6463134574389 | |
66 | Georgetown | -58.1670286474806 | 6.80197369275203 | |
67 | Guatemala | -90.5289114365615 | 14.6230805214482 | |
68 | Hanoi | 105.848068341242 | 21.0352731077371 | |
69 | Harare | 31.0427635720628 | -17.8158438357778 | |
70 | Hargeysa | 44.0653100166654 | 9.56002239881775 | |
71 | Havana | -82.3661280299533 | 23.1339046995422 | |
72 | Helsinki | 24.9321804828456 | 60.1775092325681 | |
73 | Honiara | 159.949765733606 | -9.4379942950896 | |
74 | Islamabad | 73.1646886210596 | 33.7019418089596 | |
75 | Jakarta | 106.82749176247 | -6.17247184679889 | |
76 | Jerusalem | 35.2066259345987 | 31.7784078155733 | |
77 | Johannesburg | 28.0280638650195 | -26.1680988813841 | |
78 | Juba | 31.5800255927873 | 4.82997519827796 | |
79 | Kabul | 69.1813141907051 | 34.5186361449003 | |
80 | Kampala | 32.5813776671211 | 0.318604813383331 | |
81 | Kathmandu | 85.3146963522279 | 27.7186377724772 | |
82 | Khartoum | 32.5322333800116 | 15.5900240842777 | |
83 | Kiev | 30.5146821104722 | 50.4353131876072 | |
84 | Kigali | 30.0585859190641 | -1.95164421006325 | |
85 | Kingston | -76.7674337136691 | 17.9770766238309 | |
86 | Kingstown | -61.2120624202793 | 13.1482788278684 | |
87 | Kinshasa | 15.3130260231717 | -4.32777824327599 | |
88 | Kuala Lumpur | 101.698037416746 | 3.16861173071237 | |
89 | Kuwait | 47.9763552876253 | 29.3716634886296 | |
90 | København | 12.5615398887033 | 55.6805100490259 | |
91 | La Paz | -68.1519310491022 | -16.4960277550434 | |
92 | Libreville | 9.4579650458237 | 0.385388609718518 | |
93 | Lilongwe | 33.7833019599835 | -13.9832950654692 | |
94 | Lima | -77.0520079534347 | -12.0460668175256 | |
95 | Lisbon | -9.14681216410213 | 38.7246687364878 | |
96 | Ljubljana | 14.5149690334741 | 46.0552883087945 | |
97 | Lome | 1.22081126074562 | 6.13388293026838 | |
98 | London | -0.118667702475932 | 51.5019405883275 | |
99 | Luanda | 13.2324811826686 | -8.83634025501266 | |
100 | Lusaka | 28.2813817361143 | -15.4146984093359 |
Rows: 1-100 | Columns: 4
In [21]:
# Converting lon, lat to x, y
convert_xy = coordinate_converter(cities, "lon", "lat")
convert_xy
Out[21]:
Abc cityVarchar(82) | 🌎 Geometry(1048576) | 🌎 latFloat | 🌎 lonFloat | |
1 | Abidjan | -449.822503653855 | 591.773042154565 | |
2 | Abu Dhabi | 7231.79140071776 | 2720.57108506641 | |
3 | Abuja | 839.873594997745 | 1010.23693281258 | |
4 | Accra | -24.3141194775572 | 617.352060476089 | |
5 | Addis Ababa | 4673.27772165108 | 1004.67465274177 | |
6 | Algiers | 339.14966153815 | 4088.08266305019 | |
7 | Amman | 4286.37816462547 | 3552.89708326154 | |
8 | Amsterdam | 547.16046867786 | 5821.26729771856 | |
9 | Andorra | 168.645236677105 | 4725.78454290873 | |
10 | Ankara | 3872.72179418332 | 4439.92273523603 | |
11 | Antananarivo | 6019.74749699401 | -2103.21773296097 | |
12 | Apia | nan | -1539.10958564241 | |
13 | Ashgabat | 8039.26559278217 | 4219.84690274865 | |
14 | Asmara | 4706.85246678323 | 1704.9895334181 | |
15 | Astana | 11537.2244042267 | 5691.08147379289 | |
16 | Asuncion | -7883.95588820242 | -2812.61530364517 | |
17 | Athens | 2717.664592123 | 4223.76954368256 | |
18 | Baghdad | 5520.11103314698 | 3707.30494371905 | |
19 | Baku | 6414.92615763499 | 4491.96568007214 | |
20 | Bamako | -892.686871535017 | 1406.83382263437 | |
21 | Bandar Seri Begawan | nan | 543.001645071177 | |
22 | Bangkok | nan | 1529.14652262126 | |
23 | Bangui | 2100.6466756135 | 485.548693327367 | |
24 | Banjul | -1871.25175713047 | 1496.00280608979 | |
25 | Basseterre | -9021.08912243203 | 1923.89800730006 | |
26 | Beijing | nan | 4440.10661226319 | |
27 | Beirut | 4228.36316320302 | 3766.60815804841 | |
28 | Belgrade | 2325.71748759674 | 4983.8223622637 | |
29 | Belmopan | -28873.0186613513 | 1918.33860030779 | |
30 | Berlin | 1503.73857773021 | 5840.37614314779 | |
31 | Bern | 832.650114132195 | 5216.89709775609 | |
32 | Bishkek | 12741.11534781 | 4767.48529368309 | |
33 | Bissau | -1756.28955240563 | 1319.33045363226 | |
34 | Bloemfontein | 3024.19681372372 | -3237.99558308512 | |
35 | Bogota | -12536.0369969579 | 511.315350469114 | |
36 | Brasilia | -6086.40528666433 | -1754.81098964113 | |
37 | Bratislava | 1932.28194366399 | 5354.03775613425 | |
38 | Brazzaville | 1719.88035968728 | -473.383479856285 | |
39 | Bridgetown | -8305.54808628888 | 1456.87621608583 | |
40 | Brussels | 482.085847086076 | 5652.62333305091 | |
41 | Bucharest | 3007.85433761396 | 4940.98188801994 | |
42 | Budapest | 2162.09677731935 | 5281.97608868345 | |
43 | Buenos Aires | -8042.69790950199 | -3847.40625847192 | |
44 | Bujumbura | 3417.71838393465 | -375.403770815191 | |
45 | Cairo | 3660.90057269794 | 3341.61950600567 | |
46 | Canberra | nan | -3923.29377090052 | |
47 | Cape Town | 2085.96144524619 | -3771.51676167934 | |
48 | Caracas | -10121.6766769486 | 1167.87413355912 | |
49 | Castries | -8616.17296325979 | 1556.94841502514 | |
50 | Chisinau | 3353.79126102145 | 5226.72015331502 | |
51 | Colombo | 15430.8699973016 | 770.799423983653 | |
52 | Conakry | -1536.05825476235 | 1060.07335332309 | |
53 | Cotonou | 280.083975714459 | 711.864852423105 | |
54 | Dakar | -1973.98620214502 | 1636.54219878192 | |
55 | Damascus | 4336.85219608808 | 3725.25019233594 | |
56 | Dar es Salaam | 4754.57643519591 | -755.910532048166 | |
57 | Dhaka | nan | 2638.10025403268 | |
58 | Dili | nan | -951.760566210609 | |
59 | Djibouti | 5328.5571885894 | 1289.30678279549 | |
60 | Doha | 6708.60141909441 | 2811.73674050389 | |
61 | Dublin | -696.445910562243 | 5930.5821903499 | |
62 | Dushanbe | 10668.9536243262 | 4287.68028728992 | |
63 | Freetown | -1485.06248682459 | 942.038667295598 | |
64 | Funafuti | nan | -947.008494290607 | |
65 | Gaborone | 2984.8356721591 | -2740.54501695872 | |
66 | Georgetown | -7993.53257723017 | 756.34496580378 | |
67 | Guatemala | nan | 1626.0123658999 | |
68 | Hanoi | nan | 2339.01565016308 | |
69 | Harare | 3634.2328683881 | -1981.03144843023 | |
70 | Hargeysa | 5469.42759826408 | 1063.02598935688 | |
71 | Havana | -17248.1962262018 | 2572.37283606781 | |
72 | Helsinki | 2864.20824231408 | 6691.43372476766 | |
73 | Honiara | nan | -1049.45708331425 | |
74 | Islamabad | 12172.8428240987 | 3747.48494722645 | |
75 | Jakarta | nan | -686.347554220406 | |
76 | Jerusalem | 4187.30560188292 | 3533.59772593354 | |
77 | Johannesburg | 3248.87296947694 | -2909.75983554307 | |
78 | Juba | 3704.15831766574 | 537.068737867556 | |
79 | Kabul | 10795.2483335296 | 3838.2972140024 | |
80 | Kampala | 3835.57303299532 | 35.4272388527628 | |
81 | Kathmandu | 20364.1749078261 | 3082.1718937977 | |
82 | Khartoum | 3829.08962348898 | 1733.53158443816 | |
83 | Kiev | 3565.88585621685 | 5608.15095019133 | |
84 | Kigali | 3507.15391509336 | -217.012934774261 | |
85 | Kingston | -13724.6275728911 | 1998.95971647049 | |
86 | Kingstown | -8664.97250284932 | 1462.02189976703 | |
87 | Kinshasa | 1723.37130178769 | -481.226984294991 | |
88 | Kuala Lumpur | nan | 352.33354896165 | |
89 | Kuwait | 6096.09305793459 | 3265.97996704683 | |
90 | København | 1408.10553961021 | 6191.39023043305 | |
91 | La Paz | -10480.5539196072 | -1834.27459614865 | |
92 | Libreville | 1056.48671555037 | 42.8532581872991 | |
93 | Lilongwe | 3995.26612978513 | -1554.87146905407 | |
94 | Lima | -13864.3467572023 | -1339.46151613021 | |
95 | Lisbon | -1021.42697752432 | 4305.9866994886 | |
96 | Ljubljana | 1631.53699319402 | 5121.11440509041 | |
97 | Lome | 135.758291255359 | 682.056662477504 | |
98 | London | -13.1952559056869 | 5726.7545057715 | |
99 | Luanda | 1484.64207795563 | -982.556206462494 | |
100 | Lusaka | 3280.8208493044 | -1714.0362588741 |
Rows: 1-100 | Columns: 4
In [23]:
# Converting x, y to lon, lat
convert_reverse_xy = coordinate_converter(convert_xy, "lon", "lat", reverse=True)
convert_reverse_xy
Out[23]:
Abc cityVarchar(82) | 🌎 Geometry(1048576) | 🌎 latFloat | 🌎 lonFloat | |
1 | Abidjan | -4.04199411850708 | 5.32194282609856 | |
2 | Abu Dhabi | 54.366593382592 | 24.4666835723799 | |
3 | Abuja | 7.53138214293233 | 9.0852790077542 | |
4 | Accra | -0.218661598960693 | 5.55198046444593 | |
5 | Addis Ababa | 38.6980585753487 | 9.03525622129575 | |
6 | Algiers | 3.04860667090924 | 36.7650106566281 | |
7 | Amman | 35.9313540668741 | 31.9519711058275 | |
8 | Amsterdam | 4.91469431740097 | 52.3519145466644 | |
9 | Andorra | 1.51648596050552 | 42.5000014435459 | |
10 | Ankara | 32.8624457823566 | 39.9291844440755 | |
11 | Antananarivo | 47.5146780415299 | -18.9146914920322 | |
12 | Apia | nan | -13.8415450424484 | |
13 | Ashgabat | 58.3832991117746 | 37.949994933111 | |
14 | Asmara | 38.9333235257593 | 15.3333392526819 | |
15 | Astana | 71.427774209483 | 51.1811253042576 | |
16 | Asuncion | -57.6434510279013 | -25.2944571170577 | |
17 | Athens | 23.7313752256794 | 37.9852720905523 | |
18 | Baghdad | 44.3919229145641 | 33.3405943561586 | |
19 | Baku | 49.8602713032578 | 40.397217891343 | |
20 | Bamako | -8.00198496324969 | 12.6519605263233 | |
21 | Bandar Seri Begawan | nan | 4.88333111461924 | |
22 | Bangkok | nan | 13.751945064088 | |
23 | Bangui | 18.5582881252873 | 4.36664430634909 | |
24 | Banjul | -16.5917014892126 | 13.4538764603159 | |
25 | Basseterre | -62.7170093196993 | 17.3020304554894 | |
26 | Beijing | nan | 39.9308380899091 | |
27 | Beirut | 35.5077623513776 | 33.8739209756269 | |
28 | Belgrade | 20.4660448220205 | 44.8205913044467 | |
29 | Belmopan | -88.7670729998165 | 17.2520335072469 | |
30 | Berlin | 13.3996027647005 | 52.5237645222512 | |
31 | Bern | 7.46697546248243 | 46.9166827586677 | |
32 | Bishkek | 74.5832583639037 | 42.8750253050901 | |
33 | Bissau | -15.5983608413208 | 11.8650238229806 | |
34 | Bloemfontein | 26.2299128811774 | -29.1199938773787 | |
35 | Bogota | -74.0852898137744 | 4.59836942114782 | |
36 | Brasilia | -47.9179981470031 | -15.781394372879 | |
37 | Bratislava | 17.1169807522346 | 48.1500183299617 | |
38 | Brazzaville | 15.2827436338487 | -4.25723991319751 | |
39 | Bridgetown | -59.6165267350516 | 13.1020025827511 | |
40 | Brussels | 4.33137074969045 | 50.8352629353303 | |
41 | Bucharest | 26.0980007953504 | 44.4353176634946 | |
42 | Budapest | 19.0813748187597 | 47.5019521849913 | |
43 | Buenos Aires | -58.3994772323314 | -34.6005557499074 | |
44 | Bujumbura | 29.3600060615284 | -3.37608722037464 | |
45 | Cairo | 31.2480223611261 | 30.0519062051037 | |
46 | Canberra | nan | -35.2830285453721 | |
47 | Cape Town | 18.433042299226 | -33.9180651086288 | |
48 | Caracas | -66.9189830510504 | 10.5029444130333 | |
49 | Castries | -61.0000081803696 | 14.0019734893303 | |
50 | Chisinau | 28.8577111396514 | 47.0050236196706 | |
51 | Colombo | 79.8577506092564 | 6.93196575818212 | |
52 | Conakry | -13.6821808861239 | 9.53346870502179 | |
53 | Cotonou | 2.51804474056859 | 6.40195442278247 | |
54 | Dakar | -17.4750759870506 | 14.7177775836233 | |
55 | Damascus | 36.2980500304171 | 33.5019798542061 | |
56 | Dar es Salaam | 39.2663959776946 | -6.79806673612438 | |
57 | Dhaka | nan | 23.7250055703128 | |
58 | Dili | nan | -8.55938840854646 | |
59 | Djibouti | 43.1480016670523 | 11.5950144642555 | |
60 | Doha | 51.5329678942993 | 25.2865560089066 | |
61 | Dublin | -6.25085154039107 | 53.3350069945849 | |
62 | Dushanbe | 68.7738793527017 | 38.5600352163166 | |
63 | Freetown | -13.2361615990127 | 8.47195727109818 | |
64 | Funafuti | nan | -8.51665199904107 | |
65 | Gaborone | 25.9119477932854 | -24.6463134574389 | |
66 | Georgetown | -58.1670286474806 | 6.80197369275203 | |
67 | Guatemala | nan | 14.6230805214482 | |
68 | Hanoi | nan | 21.0352731077371 | |
69 | Harare | 31.0427635720628 | -17.8158438357778 | |
70 | Hargeysa | 44.0653100166654 | 9.56002239881775 | |
71 | Havana | -82.3661280299533 | 23.1339046995422 | |
72 | Helsinki | 24.9321804828456 | 60.1775092325681 | |
73 | Honiara | nan | -9.4379942950896 | |
74 | Islamabad | 73.1646886210596 | 33.7019418089596 | |
75 | Jakarta | nan | -6.17247184679889 | |
76 | Jerusalem | 35.2066259345987 | 31.7784078155733 | |
77 | Johannesburg | 28.0280638650195 | -26.1680988813841 | |
78 | Juba | 31.5800255927873 | 4.82997519827796 | |
79 | Kabul | 69.181314190705 | 34.5186361449003 | |
80 | Kampala | 32.581377667121 | 0.318604813383331 | |
81 | Kathmandu | 85.3146963522279 | 27.7186377724772 | |
82 | Khartoum | 32.5322333800116 | 15.5900240842777 | |
83 | Kiev | 30.5146821104722 | 50.4353131876072 | |
84 | Kigali | 30.0585859190641 | -1.95164421006325 | |
85 | Kingston | -76.7674337136691 | 17.9770766238309 | |
86 | Kingstown | -61.2120624202793 | 13.1482788278684 | |
87 | Kinshasa | 15.3130260231717 | -4.32777824327599 | |
88 | Kuala Lumpur | nan | 3.16861173071237 | |
89 | Kuwait | 47.9763552876253 | 29.3716634886296 | |
90 | København | 12.5615398887033 | 55.6805100490259 | |
91 | La Paz | -68.1519310491022 | -16.4960277550434 | |
92 | Libreville | 9.45796504582369 | 0.385388609718518 | |
93 | Lilongwe | 33.7833019599835 | -13.9832950654692 | |
94 | Lima | -77.0520079534347 | -12.0460668175256 | |
95 | Lisbon | -9.14681216410212 | 38.7246687364878 | |
96 | Ljubljana | 14.5149690334741 | 46.0552883087945 | |
97 | Lome | 1.22081126074561 | 6.13388293026838 | |
98 | London | -0.118667702475934 | 51.5019405883275 | |
99 | Luanda | 13.2324811826685 | -8.83634025501266 | |
100 | Lusaka | 28.2813817361143 | -15.4146984093359 |
Rows: 1-100 | Columns: 4
(c) Copyright [2020-2022] Vertica