Here is the code: #!/usr/bin/env python3
# -\*- coding: utf-8 -\*-
"""
Created on Fri Feb 10 12:57:19 2023

@author: ericallen
"""
import os
import sys
from shapely.geometry import Point
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(\_\_file\_\_), '..')))
from src.read\_vdatum\_regions import read\_vdatum\_regions
from src.isrelation import is\_west\_of#, is\_north\_of
# Lookup table to get region code from region name
REGION\_DICT = {
 "Alaska": "ak",
 "South East Alaska Tidal": "seak",
 "American Samoa": "as",
 "Contiguous United States": "contiguous",
 "Chesapeake/Delaware Bay": "chesapeak\_delaware",
 "West Coast": "westcoast",
 "Guam and Commonwealth of Northern Mariana Islands": "gcnmi",
 "Hawaii": "hi",
 "Puerto Rico and US Virgin Islands": "prvi",
 "Saint George Island": "sgi",
 "Saint Paul Island": "spi",
 "Saint Lawrence Island": "sli"
}

# Unknown regions
ALASKA = (-169.5, 51.2, -129.5, 71.5)
AMERICAN\_SAMOA = (-171.8, -14.5, -168.1, -10.8)
GUAM\_CNMNI = (144.5, 13.3, 146.2, 20.8)
HAWAII = (-161.9, 18.7, -154.8, 22.5)
ST\_GEORGE\_ISLAND = (-171.8, 56.5, -169.5, 59.2)
ST\_PAUL\_ISLAND = (-173.3, 56.0, -169.5, 58.2)
ST\_LAWRENCE\_ISLAND = (-173.5, 63.0, -168.5, 65.5)
def assign\_regions\_vdatum(metadata):
 """ Only differentiates the Chesapeake from the Contiguous United States"""

 all\_kmls = read\_vdatum\_regions()

 region\_assign = []
 for index, row in metadata.iterrows():

 point = Point((row["Longitude"], row["Latitude"]))

 if any(kml.geometry.iloc[0].contains(point) for kml in (
 all\_kmls["New Jersey - coastal embayment - South"],
 all\_kmls["Virginia/Maryland/Delaware/New Jersey - Mid-Atlantic Bight shelf"],
 all\_kmls["Delaware - Delaware Bay"],
 all\_kmls["Virginia/Maryland - East Chesapeake Bay"],
 all\_kmls["Maryland - Northwest Chesapeake Bay"],
 all\_kmls["Virginia - Southwest Chesapeake Bay"])):

 region = REGION\_DICT["Chesapeake/Delaware Bay"]

 elif all\_kmls["Puerto Rico and U.S. Virgin Islands"].geometry.iloc[0].contains(point):

 region = REGION\_DICT["Puerto Rico and US Virgin Islands"]

 elif any(kml.geometry.iloc[0].contains(point) for kml in (
 all\_kmls["Alaska - Southeast, Yakutat to Glacier Bay"],
 all\_kmls["Alaska - Southeast, Glacier Bay to Whale Bay"],
 all\_kmls["Alaska - Southeast, Whale Bay to US/Canada Border"])):

 region = REGION\_DICT["South East Alaska Tidal"]
 elif any(kml.geometry.iloc[0].contains(point) for kml in (all\_kmls["Washington - Coastal"],
 all\_kmls["Washington - Strait of Juan de Fuca Inland"],
 all\_kmls["Washington - Strait of Juan de Fuca"],
 all\_kmls["Washington - Puget Sound"],
 all\_kmls["Washington/Oregon/California - Offshore"],
 all\_kmls["Oregon - Coastal Inland"],
 all\_kmls["Oregon - Coastal"],
 all\_kmls["California -Monterey Bay to Morro Bay"],
 all\_kmls["California/Oregon - Coastal"],
 all\_kmls["California - San Francisco Bay Vicinity"],
 all\_kmls["California - San Francisco Bay Inland"],
 all\_kmls["California - Southern California Inland"],
 all\_kmls["California - Southern California"],
 all\_kmls["Columbia River"])):

 region = REGION\_DICT["West Coast"]

 elif is\_west\_of(point, ALASKA[0]) and point.y >= ALASKA[1] and point.y <= ALASKA[3]:
 region = REGION\_DICT["Alaska"]
 elif is\_west\_of(point, AMERICAN\_SAMOA[0]) and\
 point.y >= AMERICAN\_SAMOA[1] and point.y <= AMERICAN\_SAMOA[3]:
 region = REGION\_DICT["American Samoa"]
 elif is\_west\_of(point, GUAM\_CNMNI[0]) and\
 point.y >= GUAM\_CNMNI[1] and point.y <= GUAM\_CNMNI[3]:
 region = REGION\_DICT["Guam and Commonwealth of Northern Mariana Islands"]
 elif not is\_west\_of(point, HAWAII[0]) and\
 point.y >= HAWAII[1] and point.y <= HAWAII[3]:
 region = REGION\_DICT["Hawaii"]
 elif is\_west\_of(point, ST\_GEORGE\_ISLAND[0]) and\
 point.y >= ST\_GEORGE\_ISLAND[1] and point.y <= ST\_GEORGE\_ISLAND[3]:
 region = REGION\_DICT["Saint George Island"]
 elif is\_west\_of(point, ST\_PAUL\_ISLAND[0]) and\
 point.y >= ST\_PAUL\_ISLAND[1] and point.y <= ST\_PAUL\_ISLAND[3]:
 region = REGION\_DICT["Saint Paul Island"]
 elif is\_west\_of(point, ST\_LAWRENCE\_ISLAND[0]) and\
 point.y >= ST\_LAWRENCE\_ISLAND[1] and point.y <= ST\_LAWRENCE\_ISLAND[3]:
 region = REGION\_DICT["Saint Lawrence Island"]
 else:
 region = REGION\_DICT["Contiguous United States"]

 region\_assign.append(region)

 return region\_assign
다음은 코드입니다: #!/usr/bin/env python3# -\*- 코딩: utf-8 -\*-"""생성일: 금 Feb 10 12:57:19 2023@저자: ericallen"""import osimport sysshapely.geometry에서 포인트 임포트sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(\_\_file\_\_), '..')))src.read\_vdatum\_regions에서 read\_vdatum\_regions 가져오기src.isrelation에서 is\_west\_of#, is\_north\_of 가져오기# 지역 이름에서 지역 코드를 가져오는 테이블 조회region\_dict = { "알래스카": "ak", "알래스카 남동부 갯벌": "seak", "아메리칸 사모아": "as", "인접한 미국": "인접", "체사 피크 / 델라웨어 만": "체사피크\_델라웨어", "West Coast": "westcoast", "괌 및 북마리아나 제도 연방": "GCNMI", "하와이": "hi", "푸에르토리코 및 미국령 버진 아일랜드": "prvi", "세인트 조지 섬": "sgi", "세인트 폴 섬": "spi", "세인트 로렌스 섬": "sli"}# 알 수 없는 지역알래스카 = (-169.5, 51.2, -129.5, 71.5)AMERICAN\_SAMOA = (-171.8, -14.5, -168.1, -10.8)GUAM\_CNMNI = (144.5, 13.3, 146.2, 20.8)하와이 = (-161.9, 18.7, -154.8, 22.5)st\_george\_island = (-171.8, 56.5, -169.5, 59.2)st\_paul\_island = (-173.3, 56.0, -169.5, 58.2)st\_lawrence\_island = (-173.5, 63.0, -168.5, 65.5)def assign\_regions\_vdatum(메타데이터): """ 체서피크와 인접한 미국만 구분""" all\_kmls = read\_vdatum\_regions() region\_assign = [] index의 경우, 행은 메타데이터.iterrows(): point = Point((row["경도"], row["위도"])) if any(kml.geometry.iloc[0].contains(point) for kml in ( all\_kmls["뉴저지-해안 제방-남부"], all\_kmls["버지니아/메릴랜드/델라웨어/뉴저지 - 중부 대서양 연안 제방"], all\_kmls["델라웨어 - 델라웨어만"], all\_kmls["버지니아/메릴랜드 - 이스트 체서피크 만"], all\_kmls["메릴랜드 - 북서쪽 체서피크만"], all\_kmls["버지니아 - 남서쪽 체사피크만"]))): region = REGION\_DICT["체서피크/델라웨어만"] elif all\_kmls["푸에르토리코 및 미국령 버진아일랜드"].geometry.iloc[0].contains(point): region = REGION\_DICT["푸에르토리코 및 미국령 버진아일랜드"] elif any(kml.geometry.iloc[0].contains(point) for kml in ( all\_kmls["알래스카 - 남동부, 야쿠타트에서 빙하만까지"], all\_kmls["알래스카 - 남동부, 빙하만에서 웨일만"], all\_kmls["알래스카 - 남동부, 웨일만에서 미국/캐나다 국경"]))): region = REGION\_DICT["남동 알래스카 갯벌"] elif any(kml.geometry.iloc[0].contains(point) for kml in (all\_kmls["Washington - Coastal"], all\_kmls["워싱턴 - 후안데푸카 해협 내륙"], all\_kmls["워싱턴 - 후안데푸카 해협"], all\_kmls["워싱턴 - 퓨젯 사운드"], all\_kmls["워싱턴/오레곤/캘리포니아 - 연안"], all\_kmls["오레곤 - 해안 내륙"], all\_kmls["오레곤 - 해안"], all\_kmls["캘리포니아 - 몬터레이 베이에서 모로 베이"], all\_kmls["캘리포니아/오레곤 - 해안"],   all\_kmls["캘리포니아 - 샌프란시스코만 내륙"], all\_kmls["캘리포니아 - 남부 캘리포니아 내륙"], all\_kmls["캘리포니아 - 남부 캘리포니아"], all\_kmls["Columbia River"])): region = REGION\_DICT["West Coast"] elif is\_west\_of(point, ALASKA[0]) 및 point.y >= ALASKA[1] 및 point.y <= ALASKA[3]: region = REGION\_DICT["알래스카"] elif is\_west\_of(point, AMERICAN\_SAMOA[0]) 및\. point.y >= AMERICAN\_SAMOA[1] 및 point.y <= AMERICAN\_SAMOA[3]: region = REGION\_DICT["미국령 사모아"] elif is\_west\_of(point, GUAM\_CNMNI[0]) 및\. point.y >= GUAM\_CNMNI[1] 및 point.y <= GUAM\_CNMNI[3]: region = REGION\_DICT["괌 및 북마리아나 제도 연방"] is\_west\_of(point, HAWAII[0]) 및\. point.y >= HAWAII[1] 및 point.y <= HAWAII[3]: region = REGION\_DICT["Hawaii"] elif is\_west\_of(point, ST\_GEORGE\_ISLAND[0]) 및\. point.y >= ST\_GEORGE\_ISLAND[1] 및 point.y <= ST\_GEORGE\_ISLAND[3]: region = REGION\_DICT["세인트조지섬"] elif is\_west\_of(point, ST\_PAUL\_ISLAND[0]) 및\. point.y >= ST\_PAUL\_ISLAND[1] 및 point.y <= ST\_PAUL\_ISLAND[3]: region = REGION\_DICT["세인트폴섬"] elif is\_west\_of(point, ST\_LAWRENCE\_ISLAND[0]) 및\. point.y >= ST\_LAWRENCE\_ISLAND[1] 및 point.y <= ST\_LAWRENCE\_ISLAND[3]: region = REGION\_DICT["세인트로렌스섬"] else: region = REGION\_DICT["인접한 미국"] region\_assign.append(region) 반환 지역\_할당