การสร้าง GeoDataFrame และตรวจสอบ geometry
มาดูกันว่า service district ต่างๆ ในเมืองแนชวิลล์อยู่ที่ไหนบ้าง โดยได้เก็บ path ของไฟล์ shapefile ไว้ในตัวแปร shapefile_path แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การแสดงผลข้อมูลเชิงภูมิศาสตร์ด้วย Python
คำแนะนำการฝึกหัด
- Import
geopandasโดยใช้ alias ทั่วไปว่าgpd - อ่านไฟล์ shapefile ของ service district ด้วย
geopandasแล้วดู 5 แถวแรกโดยใช้เมธอดhead() - แสดงค่าใน geometry field ของแถวแรก (ชื่อแถวคือ '0') เพื่อดูข้อมูลที่อยู่ในฟิลด์นั้น โดยส่ง
service_district.loc[0, 'geometry']เข้าไปในฟังก์ชันprint()
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import geopandas
import ____ as ____
# Read in the services district shapefile and look at the first few rows.
service_district = gpd.____(shapefile_path)
print(service_district.____())
# Print the contents of the service districts geometry in the first row
print(service_district.loc[0, '____'])