intersect

In [ ]:
intersect(vdf: vDataFrame, 
          index: str, 
          gid: str, 
          g: str = "", 
          x: str = "", 
          y: str = "",)

Spatially intersects a point or points with a set of polygons.

Parameters

Name Type Optional Description
vdf
vDataFrame
vDataFrame to use to compute the spatial join.
index
str
Name of the index.
gid
str
An integer column or integer that uniquely identifies the spatial object(s) of g or x and y.
g
str
A geometry or geography (WGS84) column that contains points. The g column can contain only point geometries or geographies.
x
str
x-coordinate or longitude.
y
str
y-coordinate or latitude.

Returns

vDataFrame : object containing the result of the intersection.

Example

In [38]:
from verticapy.geo import *
from verticapy.datasets import load_world, load_cities

world = load_world()
world["id"] = "ROW_NUMBER() OVER(ORDER BY country, pop_est)"
display(world)

cities = load_cities()
cities["id"] = "ROW_NUMBER() OVER (ORDER BY city)"
cities["lat"] = "ST_X(geometry)"
cities["lon"] = "ST_Y(geometry)"
display(cities)
123
pop_est
Int
Abc
continent
Varchar(32)
Abc
country
Varchar(82)
🌎
Geometry(1048576)
123
id
Integer
134124811AsiaAfghanistan1
23047987EuropeAlbania2
340969443AfricaAlgeria3
429310273AfricaAngola4
54050AntarcticaAntarctica5
644293293South AmericaArgentina6
73045191AsiaArmenia7
823232413OceaniaAustralia8
98754413EuropeAustria9
109961396AsiaAzerbaijan10
11329988North AmericaBahamas11
12157826578AsiaBangladesh12
139549747EuropeBelarus13
1411491346EuropeBelgium14
15360346North AmericaBelize15
1611038805AfricaBenin16
17758288AsiaBhutan17
1811138234South AmericaBolivia18
193856181EuropeBosnia and Herz.19
202214858AfricaBotswana20
21207353391South AmericaBrazil21
22443593AsiaBrunei22
237101510EuropeBulgaria23
2420107509AfricaBurkina Faso24
2511466756AfricaBurundi25
2616204486AsiaCambodia26
2724994885AfricaCameroon27
2835623680North AmericaCanada28
295625118AfricaCentral African Rep.29
3012075985AfricaChad30
3117789267South AmericaChile31
321379302771AsiaChina32
3347698524South AmericaColombia33
344954674AfricaCongo34
354930258North AmericaCosta Rica35
364292095EuropeCroatia36
3711147407North AmericaCuba37
381221549AsiaCyprus38
3910674723EuropeCzechia39
4024184810AfricaCôte d'Ivoire40
4183301151AfricaDem. Rep. Congo41
425605948EuropeDenmark42
43865267AfricaDjibouti43
4410734247North AmericaDominican Rep.44
4516290913South AmericaEcuador45
4697041072AfricaEgypt46
476172011North AmericaEl Salvador47
48778358AfricaEq. Guinea48
495918919AfricaEritrea49
501251581EuropeEstonia50
51105350020AfricaEthiopia51
522931South AmericaFalkland Is.52
53920938OceaniaFiji53
545491218EuropeFinland54
55140Seven seas (open ocean)Fr. S. Antarctic Lands55
5667106161EuropeFrance56
571772255AfricaGabon57
582051363AfricaGambia58
594926330AsiaGeorgia59
6080594017EuropeGermany60
6127499924AfricaGhana61
6210768477EuropeGreece62
6357713North AmericaGreenland63
6415460732North AmericaGuatemala64
6512413867AfricaGuinea65
661792338AfricaGuinea-Bissau66
67737718South AmericaGuyana67
6810646714North AmericaHaiti68
699038741North AmericaHonduras69
709850845EuropeHungary70
71339747EuropeIceland71
721281935911AsiaIndia72
73260580739AsiaIndonesia73
7482021564AsiaIran74
7539192111AsiaIraq75
765011102EuropeIreland76
778299706AsiaIsrael77
7862137802EuropeItaly78
792990561North AmericaJamaica79
80126451398AsiaJapan80
8110248069AsiaJordan81
8218556698AsiaKazakhstan82
8347615739AfricaKenya83
841895250EuropeKosovo84
852875422AsiaKuwait85
865789122AsiaKyrgyzstan86
877126706AsiaLaos87
881944643EuropeLatvia88
896229794AsiaLebanon89
901958042AfricaLesotho90
914689021AfricaLiberia91
926653210AfricaLibya92
932823859EuropeLithuania93
94594130EuropeLuxembourg94
952103721EuropeMacedonia95
9625054161AfricaMadagascar96
9719196246AfricaMalawi97
9831381992AsiaMalaysia98
9917885245AfricaMali99
1003758571AfricaMauritania100
Rows: 1-100 | Columns: 5
Abc
city
Varchar(82)
🌎
Geometry(1048576)
123
id
Integer
🌎
lat
Float
🌎
lon
Float
1Abidjan1-4.041994118507095.32194282609856
2Abu Dhabi254.36659338259224.4666835723799
3Abuja37.531382142932339.0852790077542
4Accra4-0.2186615989606945.55198046444593
5Addis Ababa538.69805857534879.03525622129575
6Algiers63.0486066709092436.7650106566281
7Amman735.931354066874131.9519711058275
8Amsterdam84.9146943174009752.3519145466644
9Andorra91.5164859605055242.5000014435459
10Ankara1032.862445782356639.9291844440755
11Antananarivo1147.5146780415299-18.9146914920322
12Apia12-171.738641608603-13.8415450424484
13Ashgabat1358.383299111774637.949994933111
14Asmara1438.933323525759315.3333392526819
15Astana1571.42777420948351.1811253042576
16Asuncion16-57.6434510279013-25.2944571170577
17Athens1723.731375225679437.9852720905523
18Baghdad1844.391922914564133.3405943561586
19Baku1949.860271303257840.397217891343
20Bamako20-8.001984963249712.6519605263233
21Bandar Seri Begawan21114.9332840566624.88333111461924
22Bangkok22100.51469879369513.751945064088
23Bangui2318.55828812528734.36664430634909
24Banjul24-16.591701489212613.4538764603159
25Basseterre25-62.717009319699317.3020304554894
26Beijing26116.38633982565939.9308380899091
27Beirut2735.507762351377733.8739209756269
28Belgrade2820.466044822020544.8205913044467
29Belmopan29-88.767072999816517.2520335072469
30Berlin3013.399602764700552.5237645222512
31Bern317.4669754624824246.9166827586677
32Bishkek3274.583258363903742.8750253050901
33Bissau33-15.598360841320711.8650238229806
34Bloemfontein3426.2299128811774-29.1199938773787
35Bogota35-74.08528981377444.59836942114782
36Brasilia36-47.9179981470031-15.781394372879
37Bratislava3717.116980752234648.1500183299617
38Brazzaville3815.2827436338487-4.25723991319751
39Bridgetown39-59.616526735051613.1020025827511
40Brussels404.3313707496904550.8352629353303
41Bucharest4126.098000795350444.4353176634946
42Budapest4219.081374818759747.5019521849914
43Buenos Aires43-58.3994772323314-34.6005557499074
44Bujumbura4429.3600060615284-3.37608722037464
45Cairo4531.248022361126130.0519062051037
46Canberra46149.129026244299-35.2830285453721
47Cape Town4718.433042299226-33.9180651086288
48Caracas48-66.918983051050410.5029444130333
49Castries49-61.000008180369514.0019734893303
50Chisinau5028.857711139651447.0050236196706
51Colombo5179.85775060925646.93196575818212
52Conakry52-13.68218088612399.53346870502179
53Cotonou532.51804474056866.40195442278247
54Dakar54-17.475075987050614.7177775836233
55Damascus5536.298050030417133.5019798542061
56Dar es Salaam5639.2663959776946-6.79806673612438
57Dhaka5790.406633608107523.7250055703128
58Dili58125.579455931705-8.55938840854645
59Djibouti5943.148001667052311.5950144642555
60Doha6051.532967894299325.2865560089066
61Dublin61-6.2508515403910753.3350069945849
62Dushanbe6268.773879352701738.5600352163166
63Freetown63-13.23616159901278.47195727109818
64Funafuti64179.216647094029-8.51665199904107
65Gaborone6525.9119477932854-24.6463134574389
66Georgetown66-58.16702864748066.80197369275203
67Guatemala67-90.528911436561514.6230805214482
68Hanoi68105.84806834124221.0352731077371
69Harare6931.0427635720628-17.8158438357778
70Hargeysa7044.06531001666549.56002239881775
71Havana71-82.366128029953323.1339046995422
72Helsinki7224.932180482845660.1775092325681
73Honiara73159.949765733606-9.4379942950896
74Islamabad7473.164688621059633.7019418089596
75Jakarta75106.82749176247-6.17247184679889
76Jerusalem7635.206625934598731.7784078155733
77Johannesburg7728.0280638650195-26.1680988813841
78Juba7831.58002559278734.82997519827796
79Kabul7969.181314190705134.5186361449003
80Kampala8032.58137766712110.318604813383331
81Kathmandu8185.314696352227927.7186377724772
82Khartoum8232.532233380011615.5900240842777
83Kiev8330.514682110472250.4353131876072
84Kigali8430.0585859190641-1.95164421006325
85Kingston85-76.767433713669117.9770766238309
86Kingstown86-61.212062420279313.1482788278684
87Kinshasa8715.3130260231717-4.32777824327599
88Kuala Lumpur88101.6980374167463.16861173071237
89Kuwait8947.976355287625329.3716634886296
90København9012.561539888703355.6805100490259
91La Paz91-68.1519310491022-16.4960277550434
92Libreville929.45796504582370.385388609718518
93Lilongwe9333.7833019599835-13.9832950654692
94Lima94-77.0520079534347-12.0460668175256
95Lisbon95-9.1468121641021338.7246687364878
96Ljubljana9614.514969033474146.0552883087945
97Lome971.220811260745626.13388293026838
98London98-0.11866770247593251.5019405883275
99Luanda9913.2324811826686-8.83634025501266
100Lusaka10028.2813817361143-15.4146984093359
Rows: 1-100 | Columns: 5
In [39]:
# Creating Index
create_index(world, "id", "geometry", "world_polygons", True)
Out[39]:
Abc
type
Varchar(20)
123
polygons
Integer
123
SRID
Integer
123
min_x
Float
123
min_y
Float
123
max_x
Float
123
max_y
Float
Abc
info
Varchar(500)
1GEOMETRY1770-180.0-90.0180.083.64513
Rows: 1-1 | Columns: 8
In [40]:
# Intersect using Geometry
intersect(cities, "world_polygons", "id", "geometry")
Out[40]:
123
point_id
Int
123
polygon_gid
Int
11124
2269
33171
44129
55166
66145
7790
88112
99157
1010160
1111126
121361
131467
1415116
151675
161794
1718143
181989
1920114
202111
2122158
222365
232433
2426177
252772
262877
272910
2830159
293181
303266
313328
3234153
3335149
3436173
353762
3638162
3740101
3841120
394287
4043147
4144100
4245164
4346122
4447153
4548136
465047
4751121
4852104
495396
5054107
5155115
5256152
5357170
545825
556036
566159
576283
586535
596617
6067108
6168163
6269106
637048
647198
657263
667316
6774172
6875174
697654
7077153
7178105
7279139
7380144
7481133
7582141
7683146
7784102
788540
7987162
8088137
818939
829064
839197
849227
8593117
8694135
879595
889632
899780
9098156
9199132
92100109
9310113
94102150
9510668
96108165
97109128
9811031
9911126
100113167
Rows: 1-100 | Columns: 2
In [41]:
# Intersect using Latitude and Longitude
intersect(cities, "world_polygons", "id", x="lat", y="lon")
Out[41]:
123
point_id
Int
123
polygon_gid
Int
11124
2269
33171
44129
55166
66145
7790
88112
99157
1010160
1111126
121361
131467
1415116
151675
161794
1718143
181989
1920114
202111
2122158
222365
232433
2426177
252772
262877
272910
2830159
293181
303266
313328
3234153
3335149
3436173
353762
3638162
3740101
3841120
394287
4043147
4144100
4245164
4346122
4447153
4548136
465047
4751121
4852104
495396
5054107
5155115
5256152
5357170
545825
556036
566159
576283
586535
596617
6067108
6168163
6269106
637048
647198
657263
667316
6774172
6875174
697654
7077153
7178105
7279139
7380144
7481133
7582141
7683146
7784102
78