참고자료 : https://www.osgeo.kr/17
from shapely.geometry import Point
import geopandas as gpd
from xml.etree.ElementTree import parse
import argparse
parser = argparse.ArgumentParser(description="find lat long from xml metadata")
parser.add_argument("--xml_path", required=True, type=str, help="Path for xml files")
args = parser.parse_args()
def xy_from_xml(xml_path):
tree = parse(xml_path)
root = tree.getroot()
coordinate = root.findall('좌표계')
starting_point = [axis.findtext("투영원점") for axis in coordinate][0]
x = [axis.findtext("원점X좌표") for axis in coordinate][0]
y = [axis.findtext("원점Y좌표") for axis in coordinate][0]
crs = find_crs(starting_point)
lat, lng = get_point(crs, int(x), int(y))
return lat, lng
def find_crs(starting_point):
if starting_point == '서부':
return 'EPSG:5185'
elif starting_point == '중부':
return 'EPSG:5186'
elif starting_point == '동부':
return 'EPSG:5187'
elif starting_point == '동해':
return 'EPSG:5188'
def get_point(crs, x, y):
p = Point(x,y)
g = gpd.GeoDataFrame(geometry = [p], crs = crs)
g_point = str(g.to_crs('EPSG:4326').loc[0]['geometry'])
g_point = g_point.replace('(', '')
g_point = g_point.replace(')', '')
g_list = g_point.split(' ')
lat, lng = g_list[2], g_list[1]
return lat, lng
if __name__ == '__main__':
xml_path = args.xml_path
lat, lng = xy_from_xml(xml_path)
print(lat, lng)