AI/Geospatial Analysis

Coordinate Reference Systems

아무 말하는 감자 2022. 11. 21. 00:08

Introduction

https://www.kaggle.com/code/alexisbcook/coordinate-reference-systems/tutorial

 

Coordinate Reference Systems

Explore and run machine learning code with Kaggle Notebooks | Using data from multiple data sources

www.kaggle.com

이 과정에서 생성하는 지도는 지구 표면을 2차원으로 묘사합니다. 하지만 아시다시피 세상은 사실 3차원 지구본입니다. 그래서 map projection이라는 방법을 사용하여 평면으로 렌더링해야 합니다.

map projection은 100% 정확할 수 없습니다. 각 프로젝션은 일부 유용한 특성을 유지하면서 어떤 방식으로든 지구 표면을 왜곡합니다.

List of map projections

좌표 참조 시스템(CRS)을 사용하여 투영된 점이 지구상의 실제 위치와 어떻게 일치하는지 보여줍니다.

=좌표 참조 시스템(CRS)은 GIS의 2차원 투영 지도가 지구상의 실제 장소와 어떻게 관련되는지 정의합니다.

이 자습서에서는 GeoPandas에서 좌표 참조 시스템을 사용하는 방법과 함께 좌표 참조 시스템에 대해 자세히 알아봅니다.

Setting the CRS

shapefile에서 GeoDataFrame을 생성할 때 CRS는 이미 가져왔습니다.

# Load a GeoDataFrame containing regions in Ghana
regions = gpd.read_file("../input/geospatial-learn-course-data/ghana/ghana/Regions/Map_of_Regions_in_Ghana.shp")
print(regions.crs)
epsg:32630

>How do you interpret that?

좌표 참조 시스템은 EPSG(European Petroleum Survey Group) 코드로 참조됩니다.

이 GeoDataFrame은 EPSG 32630을 사용하며, 일반적으로 "Mercator projection"이라고 합니다. 이 프로젝션은 각도를 유지하고(해상 탐색에 유용함) 영역을 약간 왜곡합니다.

그러나 CSV 파일에서 GeoDataFrame을 생성할 때 CRS를 설정해야 합니다. EPSG 4326은 위도와 경도 좌표에 해당합니다.

# Create a DataFrame with health facilities in Ghana
facilities_df = pd.read_csv("../input/geospatial-learn-course-data/ghana/ghana/health_facilities.csv")

# Convert the DataFrame to a GeoDataFrame
facilities = gpd.GeoDataFrame(facilities_df, geometry=gpd.points_from_xy(facilities_df.Longitude, facilities_df.Latitude))

# Set the coordinate reference system (CRS) to EPSG 4326
facilities.crs = {'init': 'epsg:4326'}

# View the first five rows of the GeoDataFrame
facilities.head()

위의 코드 셀에서 CSV 파일로부터 GeoDataFrame을 생성하려면 Pandas와 GeoPandas를 모두 사용해야함:

  • 위도와 경도 좌표가 있는 열을 포함하는 DataFrame을 만드는 것으로 시작합니다.
  • GeoDataFrame으로 변환하기 위해 gpd.GeoDataFrame()을 사용합니다.
  • gpd.points_from_xy() 함수는 위도 및 경도 열에서 Point 객체를 생성합니다.

Re-projecting

Re-projecting은 CRS를 변경하는 과정을 말합니다. 이것은 to_crs() 메서드를 사용하여 GeoPandas에서 수행됩니다.

여러 GeoDataFrame을 플로팅할 때 모두 동일한 CRS를 사용하는 것이 중요합니다. 아래 코드 셀에서 GeoDataFrame 시설의 CRS를 플롯하기 전에 지역의 CRS와 일치하도록 변경합니다.

# Create a map
ax = regions.plot(figsize=(8,8), color='whitesmoke', linestyle=':', edgecolor='black')
facilities.to_crs(epsg=32630).plot(markersize=1, ax=ax)

to_crs() 메서드는 "geometry" 열만 수정합니다. 다른 모든 열은 그대로 유지됩니다.

# The "Latitude" and "Longitude" columns are unchanged
facilities.to_crs(epsg=32630).head()

GeoPandas에서 EPSG 코드를 사용할 수 없는 경우 CRS의 "proj4 string"로 알려진 것으로 CRS를 변경할 수 있습니다.

+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
# Change the CRS to EPSG 4326
regions.to_crs("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs").head()

Attributes of geometric objects

첫 번째 자습서에서 배운 것처럼 임의의 GeoDataFrame의 경우 "geometry" 열의 유형은 표시하려는 항목에 따라 다릅니다.

  • 지진의 진원지점
  • 거리에 대한 유도선
  • 국가 경계를 표시하는 다각형

세 가지 유형의 기하학적 개체 모두 데이터 세트를 빠르게 분석하는 데 사용할 수 있는 기본 속성이 있습니다. 예를 들어 x 및 y 속성에서 각각 Point의 x 및 y 좌표를 가져올 수 있습니다.

# Get the x-coordinate of each point
facilities.geometry.head().x
0   -1.96317
1   -1.58592
2   -1.34982
3   -1.61098
4   -1.61098
dtype: float64
# Calculate the area (in square meters) of each polygon in the GeoDataFrame 
regions.loc[:, "AREA"] = regions.geometry.area / 10**6

print("Area of Ghana: {} square kilometers".format(regions.AREA.sum()))
print("CRS:", regions.crs)
regions.head()
Area of Ghana: 239584.5760055668 square kilometers
CRS: epsg:32630

'AI > Geospatial Analysis' 카테고리의 다른 글

Your First Map  (0) 2022.11.20