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
city
Varchar(82)
🌎
Geometry(1048576)
🌎
lat
Float
🌎
lon
Float
1Abidjan-4.041994118507095.32194282609856
2Abu Dhabi54.36659338259224.4666835723799
3Abuja7.531382142932339.0852790077542
4Accra-0.2186615989606945.55198046444593
5Addis Ababa38.69805857534879.03525622129575
6Algiers3.0486066709092436.7650106566281
7Amman35.931354066874131.9519711058275
8Amsterdam4.9146943174009752.3519145466644
9Andorra1.5164859605055242.5000014435459
10Ankara32.862445782356639.9291844440755
11Antananarivo47.5146780415299-18.9146914920322
12Apia-171.738641608603-13.8415450424484
13Ashgabat58.383299111774637.949994933111
14Asmara38.933323525759315.3333392526819
15Astana71.42777420948351.1811253042576
16Asuncion-57.6434510279013-25.2944571170577
17Athens23.731375225679437.9852720905523
18Baghdad44.391922914564133.3405943561586
19Baku49.860271303257840.397217891343
20Bamako-8.001984963249712.6519605263233
21Bandar Seri Begawan114.9332840566624.88333111461924
22Bangkok100.51469879369513.751945064088
23Bangui18.55828812528734.36664430634909
24Banjul-16.591701489212613.4538764603159
25Basseterre-62.717009319699317.3020304554894
26Beijing116.38633982565939.9308380899091
27Beirut35.507762351377733.8739209756269
28Belgrade20.466044822020544.8205913044467
29Belmopan-88.767072999816517.2520335072469
30Berlin13.399602764700552.5237645222512
31Bern7.4669754624824246.9166827586677
32Bishkek74.583258363903742.8750253050901
33Bissau-15.598360841320711.8650238229806
34Bloemfontein26.2299128811774-29.1199938773787
35Bogota-74.08528981377444.59836942114782
36Brasilia-47.9179981470031-15.781394372879
37Bratislava17.116980752234648.1500183299617
38Brazzaville15.2827436338487-4.25723991319751
39Bridgetown-59.616526735051613.1020025827511
40Brussels4.3313707496904550.8352629353303
41Bucharest26.098000795350444.4353176634946
42Budapest19.081374818759747.5019521849914
43Buenos Aires-58.3994772323314-34.6005557499074
44Bujumbura29.3600060615284-3.37608722037464
45Cairo31.248022361126130.0519062051037
46Canberra149.129026244299-35.2830285453721
47Cape Town18.433042299226-33.9180651086288
48Caracas-66.918983051050410.5029444130333
49Castries-61.000008180369514.0019734893303
50Chisinau28.857711139651447.0050236196706
51Colombo79.85775060925646.93196575818212
52Conakry-13.68218088612399.53346870502179
53Cotonou2.51804474056866.40195442278247
54Dakar-17.475075987050614.7177775836233
55Damascus36.298050030417133.5019798542061
56Dar es Salaam39.2663959776946-6.79806673612438
57Dhaka90.406633608107523.7250055703128
58Dili125.579455931705-8.55938840854645
59Djibouti43.148001667052311.5950144642555
60Doha51.532967894299325.2865560089066
61Dublin-6.2508515403910753.3350069945849
62Dushanbe68.773879352701738.5600352163166
63Freetown-13.23616159901278.47195727109818
64Funafuti179.216647094029-8.51665199904107
65Gaborone25.9119477932854-24.6463134574389
66Georgetown-58.16702864748066.80197369275203
67Guatemala-90.528911436561514.6230805214482
68Hanoi105.84806834124221.0352731077371
69Harare31.0427635720628-17.8158438357778
70Hargeysa44.06531001666549.56002239881775
71Havana-82.366128029953323.1339046995422
72Helsinki24.932180482845660.1775092325681
73Honiara159.949765733606-9.4379942950896
74Islamabad73.164688621059633.7019418089596
75Jakarta106.82749176247-6.17247184679889
76Jerusalem35.206625934598731.7784078155733
77Johannesburg28.0280638650195-26.1680988813841
78Juba31.58002559278734.82997519827796
79Kabul69.181314190705134.5186361449003
80Kampala32.58137766712110.318604813383331
81Kathmandu85.314696352227927.7186377724772
82Khartoum32.532233380011615.5900240842777
83Kiev30.514682110472250.4353131876072
84Kigali30.0585859190641-1.95164421006325
85Kingston-76.767433713669117.9770766238309
86Kingstown-61.212062420279313.1482788278684
87Kinshasa15.3130260231717-4.32777824327599
88Kuala Lumpur101.6980374167463.16861173071237
89Kuwait47.976355287625329.3716634886296
90København12.561539888703355.6805100490259
91La Paz-68.1519310491022-16.4960277550434
92Libreville9.45796504582370.385388609718518
93Lilongwe33.7833019599835-13.9832950654692
94Lima-77.0520079534347-12.0460668175256
95Lisbon-9.1468121641021338.7246687364878
96Ljubljana14.514969033474146.0552883087945
97Lome1.220811260745626.13388293026838
98London-0.11866770247593251.5019405883275
99Luanda13.2324811826686-8.83634025501266
100Lusaka28.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
city
Varchar(82)
🌎
Geometry(1048576)
🌎
lat
Float
🌎
lon
Float
1Abidjan-449.822503653855591.773042154565
2Abu Dhabi7231.791400717762720.57108506641
3Abuja839.8735949977451010.23693281258
4Accra-24.3141194775572617.352060476089
5Addis Ababa4673.277721651081004.67465274177
6Algiers339.149661538154088.08266305019
7Amman4286.378164625473552.89708326154
8Amsterdam547.160468677865821.26729771856
9Andorra168.6452366771054725.78454290873
10Ankara3872.721794183324439.92273523603
11Antananarivo6019.74749699401-2103.21773296097
12Apianan-1539.10958564241
13Ashgabat8039.265592782174219.84690274865
14Asmara4706.852466783231704.9895334181
15Astana11537.22440422675691.08147379289
16Asuncion-7883.95588820242-2812.61530364517
17Athens2717.6645921234223.76954368256
18Baghdad5520.111033146983707.30494371905
19Baku6414.926157634994491.96568007214
20Bamako-892.6868715350171406.83382263437
21Bandar Seri Begawannan543.001645071177
22Bangkoknan1529.14652262126
23Bangui2100.6466756135485.548693327367
24Banjul-1871.251757130471496.00280608979
25Basseterre-9021.089122432031923.89800730006
26Beijingnan4440.10661226319
27Beirut4228.363163203023766.60815804841
28Belgrade2325.717487596744983.8223622637
29Belmopan-28873.01866135131918.33860030779
30Berlin1503.738577730215840.37614314779
31Bern832.6501141321955216.89709775609
32Bishkek12741.115347814767.48529368309
33Bissau-1756.289552405631319.33045363226
34Bloemfontein3024.19681372372-3237.99558308512
35Bogota-12536.0369969579511.315350469114
36Brasilia-6086.40528666433-1754.81098964113
37Bratislava1932.281943663995354.03775613425
38Brazzaville1719.88035968728-473.383479856285
39Bridgetown-8305.548086288881456.87621608583
40Brussels482.0858470860765652.62333305091
41Bucharest3007.854337613964940.98188801994
42Budapest2162.096777319355281.97608868345
43Buenos Aires-8042.69790950199-3847.40625847192
44Bujumbura3417.71838393465-375.403770815191
45Cairo3660.900572697943341.61950600567
46Canberranan-3923.29377090052
47Cape Town2085.96144524619-3771.51676167934
48Caracas-10121.67667694861167.87413355912
49Castries-8616.172963259791556.94841502514
50Chisinau3353.791261021455226.72015331502
51Colombo15430.8699973016770.799423983653
52Conakry-1536.058254762351060.07335332309
53Cotonou280.083975714459711.864852423105
54Dakar-1973.986202145021636.54219878192
55Damascus4336.852196088083725.25019233594
56Dar es Salaam4754.57643519591-755.910532048166
57Dhakanan2638.10025403268
58Dilinan-951.760566210609
59Djibouti5328.55718858941289.30678279549
60Doha6708.601419094412811.73674050389
61Dublin-696.4459105622435930.5821903499
62Dushanbe10668.95362432624287.68028728992
63Freetown-1485.06248682459942.038667295598
64Funafutinan-947.008494290607
65Gaborone2984.8356721591-2740.54501695872
66Georgetown-7993.53257723017756.34496580378
67Guatemalanan1626.0123658999
68Hanoinan2339.01565016308
69Harare3634.2328683881-1981.03144843023
70Hargeysa5469.427598264081063.02598935688
71Havana-17248.19622620182572.37283606781
72Helsinki2864.208242314086691.43372476766
73Honiaranan-1049.45708331425
74Islamabad12172.84282409873747.48494722645
75Jakartanan-686.347554220406
76Jerusalem4187.305601882923533.59772593354
77Johannesburg3248.87296947694-2909.75983554307
78Juba3704.15831766574537.068737867556
79Kabul10795.24833352963838.2972140024
80Kampala3835.5730329953235.4272388527628
81Kathmandu20364.17490782613082.1718937977
82Khartoum3829.089623488981733.53158443816
83Kiev3565.885856216855608.15095019133
84Kigali3507.15391509336-217.012934774261
85Kingston-13724.62757289111998.95971647049
86Kingstown-8664.972502849321462.02189976703
87Kinshasa1723.37130178769-481.226984294991
88Kuala Lumpurnan352.33354896165
89Kuwait6096.093057934593265.97996704683
90København1408.105539610216191.39023043305
91La Paz-10480.5539196072-1834.27459614865
92Libreville1056.4867155503742.8532581872991
93Lilongwe3995.26612978513-1554.87146905407
94Lima-13864.3467572023-1339.46151613021
95Lisbon-1021.426977524324305.9866994886
96Ljubljana1631.536993194025121.11440509041
97Lome135.758291255359682.056662477504
98London-13.19525590568695726.7545057715
99Luanda1484.64207795563-982.556206462494
100Lusaka3280.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
city
Varchar(82)
🌎
Geometry(1048576)
🌎
lat
Float
🌎
lon
Float
1Abidjan-4.041994118507085.32194282609856
2Abu Dhabi54.36659338259224.4666835723799
3Abuja7.531382142932339.0852790077542
4Accra-0.2186615989606935.55198046444593
5Addis Ababa38.69805857534879.03525622129575
6Algiers3.0486066709092436.7650106566281
7Amman35.931354066874131.9519711058275
8Amsterdam4.9146943174009752.3519145466644
9Andorra1.5164859605055242.5000014435459
10Ankara32.862445782356639.9291844440755
11Antananarivo47.5146780415299-18.9146914920322
12Apianan-13.8415450424484
13Ashgabat58.383299111774637.949994933111
14Asmara38.933323525759315.3333392526819
15Astana71.42777420948351.1811253042576
16Asuncion-57.6434510279013-25.2944571170577
17Athens23.731375225679437.9852720905523
18Baghdad44.391922914564133.3405943561586
19Baku49.860271303257840.397217891343
20Bamako-8.0019849632496912.6519605263233
21Bandar Seri Begawannan4.88333111461924
22Bangkoknan13.751945064088
23Bangui18.55828812528734.36664430634909
24Banjul-16.591701489212613.4538764603159
25Basseterre-62.717009319699317.3020304554894
26Beijingnan39.9308380899091
27Beirut35.507762351377633.8739209756269
28Belgrade20.466044822020544.8205913044467
29Belmopan-88.767072999816517.2520335072469
30Berlin13.399602764700552.5237645222512
31Bern7.4669754624824346.9166827586677
32Bishkek74.583258363903742.8750253050901
33Bissau-15.598360841320811.8650238229806
34Bloemfontein26.2299128811774-29.1199938773787
35Bogota-74.08528981377444.59836942114782
36Brasilia-47.9179981470031-15.781394372879
37Bratislava17.116980752234648.1500183299617
38Brazzaville15.2827436338487-4.25723991319751
39Bridgetown-59.616526735051613.1020025827511
40Brussels4.3313707496904550.8352629353303
41Bucharest26.098000795350444.4353176634946
42Budapest19.081374818759747.5019521849913
43Buenos Aires-58.3994772323314-34.6005557499074
44Bujumbura29.3600060615284-3.37608722037464
45Cairo31.248022361126130.0519062051037
46Canberranan-35.2830285453721
47Cape Town18.433042299226-33.9180651086288
48Caracas-66.918983051050410.5029444130333
49Castries-61.000008180369614.0019734893303
50Chisinau28.857711139651447.0050236196706
51Colombo79.85775060925646.93196575818212
52Conakry-13.68218088612399.53346870502179
53Cotonou2.518044740568596.40195442278247
54Dakar-17.475075987050614.7177775836233
55Damascus36.298050030417133.5019798542061
56Dar es Salaam39.2663959776946-6.79806673612438
57Dhakanan23.7250055703128
58Dilinan-8.55938840854646
59Djibouti43.148001667052311.5950144642555
60Doha51.532967894299325.2865560089066
61Dublin-6.2508515403910753.3350069945849
62Dushanbe68.773879352701738.5600352163166
63Freetown-13.23616159901278.47195727109818
64Funafutinan-8.51665199904107
65Gaborone25.9119477932854-24.6463134574389
66Georgetown-58.16702864748066.80197369275203
67Guatemalanan14.6230805214482
68Hanoinan21.0352731077371
69Harare31.0427635720628-17.8158438357778
70Hargeysa44.06531001666549.56002239881775
71Havana-82.366128029953323.1339046995422
72Helsinki24.932180482845660.1775092325681
73Honiaranan-9.4379942950896
74Islamabad73.164688621059633.7019418089596
75Jakartanan-6.17247184679889
76Jerusalem35.206625934598731.7784078155733
77Johannesburg28.0280638650195-26.1680988813841
78Juba31.58002559278734.82997519827796
79Kabul69.18131419070534.5186361449003
80Kampala32.5813776671210.318604813383331
81Kathmandu85.314696352227927.7186377724772
82Khartoum32.532233380011615.5900240842777
83Kiev30.514682110472250.4353131876072
84Kigali30.0585859190641-1.95164421006325
85Kingston-76.767433713669117.9770766238309
86Kingstown-61.212062420279313.1482788278684
87Kinshasa15.3130260231717-4.32777824327599
88Kuala Lumpurnan3.16861173071237
89Kuwait47.976355287625329.3716634886296
90København12.561539888703355.6805100490259
91La Paz-68.1519310491022-16.4960277550434
92Libreville9.457965045823690.385388609718518
93Lilongwe33.7833019599835-13.9832950654692
94Lima-77.0520079534347-12.0460668175256
95Lisbon-9.1468121641021238.7246687364878
96Ljubljana14.514969033474146.0552883087945
97Lome1.220811260745616.13388293026838
98London-0.11866770247593451.5019405883275
99Luanda13.2324811826685-8.83634025501266
100Lusaka28.2813817361143-15.4146984093359
Rows: 1-100 | Columns: 4