비교 필요

혜미님 코드

import simplekml
kml = simplekml.Kml()

for i in range(len(label)):
    f = kml.newfolder(name = label['name'][i])

		### 오버레이할 이미지 정보 (필수: 위치)
    img_path = 'overview/'+str(aimo_label_kml['name'][i])+'_overview.jpg'
    text = '<img style="width:258px;" src="file://'+img_path+'">'
    description = Class[i]+'<br/>'+text
    
		### 폴리곤 생성 (위치 클릭 시 이미지 정보 전시)
    pol = f.newpolygon(name='Polygon')
    pol.name=aimo_label_kml['name'][i]
    pol.outerboundaryis=aimo_label_kml['geometry'][i].exterior.coords
    pol.description=description
    pol.style.polystyle.color = simplekml.Color.changealphaint(100, simplekml.Color.white)
    pol.style.polystyle.outline = 0
    
		### groundoverlay로 이미지 전시
    ground = f.newgroundoverlay(name='GroundOverlay')
    ground.name = aimo_label_kml['name'][i]
    ground.icon.href = text
    ground.gxlatlonquad.coords = aimo_label_kml['geometry'][i].exterior.coords
    ground.Region = aimo_label_kml['geometry_1'][i].exterior.coords
    
kml.save("20211215.kml")

우열님 코드

import requests
import simplekml
import os
# Z = 17, Tile : 32,951,762,944
# Z = 8, Tile : 48311 / 125952 ->
# Z = 7, Tile : 13237 / 31744 
# Z = 6, Tile : 3738 / 7936 -> 3797
# Z = 5, Tile : 1123 / 1984 -> 1163
# Z = 4, Tile : 361 / 512 -> 386 
# minx,miny,maxx,maxy, z = 0, 1, 511, 246, 8
# minx,miny,maxx,maxy, z = 0, 0, 255, 123, 7
# minx,miny,maxx,maxy, z = 0, 0, 127, 61, 6
# minx,miny,maxx,maxy, z = 0, 0, 63, 30, 5
minx,miny,maxx,maxy, z = 0, 0, 31, 15, 4
# For Small Data
# minx,miny,maxx,maxy, z = 0, 0, 5, 5, 4
WORKSPACE = "aoi"
LAYER = "world_continents"
FILENAME = f"earth_{LAYER}_zoomLevel_{z}"
TMS_URL = f'<http://geoserver.sia-service.kr/geoserver/gwc/service/tms/1.0.0/{WORKSPACE}:{LAYER}@EPSG:4326@geojson>'
count, aoi = 0, 0
kml = simplekml.Kml()
# Style
sharedstyle = simplekml.Style()
sharedstyle.linestyle.color = "ff000ff"
sharedstyle.polystyle.fill = 0
f = kml.newfolder(name = FILENAME)
# 가능한 X,Y의 모든 조합
for x in range(minx, maxx + 1):
    for y in range(miny, maxy + 1):
        res = requests.get(TMS_URL + f'/{z}/{x}/{y}.geojson')
        resData = res.json()
        if "features" in resData and resData["features"]:
            count += 1
            for data in resData["features"]:
                if len(data['geometry']['coordinates']) == 1: data['geometry']['coordinates'] = [data['geometry']['coordinates']]
                for coors in data['geometry']['coordinates']:
                    for idx,coor in enumerate(coors):
                        # print(coor)
                        aoi += 1
                        try:
                            mminx=min(coor, key=lambda data : data[0])[0]
                            mmaxx=max(coor, key=lambda data : data[0])[0]
                            mminy=min(coor, key=lambda data : data[1])[1]
                            mmaxy=max(coor, key=lambda data : data[1])[1]
                            # print(f"mminx : {mminx} | mmaxx : {mmaxx}")
                            # print(f"mminy : {mminy} | mmaxy : {mmaxy}\\n")
                            pol = f.newpolygon(name = data['id']+f"_{idx}")
                            pol.outerboundaryis = [ (mminx,mminy), (mminx,mmaxy),
                                                    (mmaxx,mmaxy), (mmaxx,mminy),
                                                    (mminx,mminy)]
                        except Exception as e:
                            print(e, coor)
                pol.style = sharedstyle
kml.save(os.getcwd() + '/' + FILENAME+".kml")
print(f"Count : {count} | Aoi Count : {count}")