Shapely ज्योमेट्री और स्पैटियल रिलेशनशिप्स

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

Dani Arribas-Bel

Geographic Data Science Lab (University of Liverpool)

स्केलर ज्योमेट्री वैल्यूज़

cities = geopandas.read_file("ne_110m_populated_places.shp")
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)
4    Luxembourg   POINT (6.130002806227083 49.61166037912108)
brussels = cities.loc[170, 'geometry']
print(brussels)
POINT (4.33137074969045 50.83526293533032)
Python में Geospatial Data के साथ काम करना

स्केलर ज्योमेट्री वैल्यूज़

brussels = cities.loc[170, 'geometry']
print(brussels)
POINT (4.33137074969045 50.83526293533032)
type(brussels)
shapely.geometry.point.Point
Python में Geospatial Data के साथ काम करना

Shapely Python पैकेज

type(brussels)
shapely.geometry.point.Point

Shapely

  • ज्योमेट्रिक ऑब्जेक्ट्स को मैनीपुलेट और विश्लेषित करने के लिए Python पैकेज
  • Point, LineString और Polygon ऑब्जेक्ट्स देता है
  • GeoSeries (GeoDataFrame की 'geometry' कॉलम) shapely ऑब्जेक्ट्स से बनी होती है
Python में Geospatial Data के साथ काम करना

ज्योमेट्री ऑब्जेक्ट्स

GeoDataFrame से एक्सेस करना:

brussels = cities.loc[170, 'geometry']
paris = cities.loc[235, 'geometry']
belgium = countries.loc[countries['name'] == 'Belgium', 'geometry'].squeeze()
france = countries.loc[countries['name'] == 'France', 'geometry'].squeeze()
uk = countries.loc[countries['name'] == 'United Kingdom', 'geometry'].squeeze()

मैन्युअली बनाना:

from shapely.geometry import Point
p = Point(1, 2)
print(p)
POINT (1 2)
Python में Geospatial Data के साथ काम करना

स्पैटियल मेथड्स

किसी ज्योमेट्री का area:

belgium.area
3.8299974609075753

2 ज्योमेट्री के बीच distance:

brussels.distance(paris)
2.8049127723186214

और भी बहुत कुछ! (जैसे centroid, simplify, ...)

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

स्पैटियल रिलेशनशिप्स

geopandas.GeoSeries([belgium, france, uk, paris,  brussels, line]).plot()

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

स्पैटियल रिलेशनशिप्स

belgium.contains(brussels)
True
france.contains(brussels)
False
brussels.within(belgium)
True
belgium.touches(france)
True
line.intersects(france)
True
line.intersects(uk)
False
Python में Geospatial Data के साथ काम करना

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

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

Preparing Video For Download...