GeoPandas के साथ spatial संबंध

Python में Geospatial Data के साथ काम करना

Dani Arribas-Bel

Geographic Data Science Lab (University of Liverpool)

एलिमेंट-वाइज़ spatial relationship methods

brussels.within(france)
False
paris.within(france)
True
Python में Geospatial Data के साथ काम करना

एलिमेंट-वाइज़ spatial relationship methods

brussels.within(france)
False

पूरे GeoDataFrame के लिए?

cities.head()
           name                                      geometry
0  Vatican City   POINT (12.45338654497177 41.90328217996012)
1    San Marino     POINT (12.44177015780014 43.936095834768)
2         Vaduz   POINT (9.516669472907267 47.13372377429357)
3       Lobamba  POINT (31.19999710971274 -26.46666746135247)
...
Python में Geospatial Data के साथ काम करना

एलिमेंट-वाइज़ spatial relationship methods

cities की हर geometry पर within() ऑपरेशन:

cities.within(france)
0      False
1      False
2      False
       ...  
240    False
241    False
242    False
Length: 243, dtype: bool
cities['geometry'][0].within(france)
False
cities['geometry'][1].within(france)
False
cities['geometry'][2].within(france)
False

...

Python में Geospatial Data के साथ काम करना

Spatial relation से फ़िल्टरिंग

within() के आधार पर cities को फ़िल्टर करें:

cities[cities.within(france)]
        name                                     geometry
10    Monaco  POINT (7.406913173465057 43.73964568785249)
13   Andorra    POINT (1.51648596050552 42.5000014435459)
235    Paris   POINT (2.33138946713035 48.86863878981461)
Python में Geospatial Data के साथ काम करना

Spatial relation से फ़िल्टरिंग

Amazon किन देशों से होकर बहती है?

rivers = geopandas.read_file("ne_50m_rivers_lake_centerlines.shp")
rivers.head()
              type      name                                 geometry
0  Lake Centerline      Kama  LINESTRING (51.94 55.70, 51.88 55.69...
1            River      Kama  LINESTRING (53.69 58.21, 53.68 58.27...
2  Lake Centerline      Abay  LINESTRING (37.11 11.85, 37.15 11.89...
...
amazon = rivers[rivers['name'] == 'Amazonas'].geometry.squeeze()
mask = countries.intersects(amazon)
Python में Geospatial Data के साथ काम करना

Spatial relation से फ़िल्टरिंग

countries[mask]
         name      continent                                 geometry
22     Brazil  South America  POLYGON ((-57.63 -30.22, -56.29 -28....
35   Colombia  South America  POLYGON ((-66.88 1.25, -67.07 1.13, ...
124      Peru  South America  POLYGON ((-69.53 -10.95, -68.67 -12....
  • within
  • contains
  • intersects

और जानें: https://shapely.readthedocs.io/en/latest/

Python में Geospatial Data के साथ काम करना

Shapely objects

paris.within(france)
True

GeoPandas

cities.within(france)
0      False
1      False
2      False
       ...
france.intersects(amazon)
False
countries.intersects(amazon)
0      False
1      False
2      False
       ...
Python में Geospatial Data के साथ काम करना

अभ्यास करते हैं!

Python में Geospatial Data के साथ काम करना

Preparing Video For Download...