인문지식 처리와 프로그래밍2020 6.04
soook
목차
tourSpace01+templateTbl.htm
tourSpace01
#!/usr/bin/python #-*- coding: utf-8 -*- import sys import pyodbc import cgi import cgitb noIconUrl = "http://dh.aks.ac.kr/VR/style/noicon60.png" referenceIconUrl = "http://dh.aks.ac.kr/VR/style/text60.png" networkIconUrl = "http://dh.aks.ac.kr/VR/style/semantic.png" vrIconUrl = "http://dh.aks.ac.kr/VR/style/vr.png" def createCZML( poiList ): for item in poiList: id = item['id'] # id label = item['label'] # name latitude = item['latitude'] # position longitude = item['longitude'] # position altitude = item['altitude'] # position infoUrl = item['infoUrl'] # description iconUrl = item['iconUrl'] # description semanticUrl = item['semanticUrl'] # description vrUrl = item['vrUrl'] # description descriptionText="<tr height='100px'><td><img width='120' src='{0}'/> <a href='{1}' target='_top'><img width='60' src='{2}'/></a> <a href='{3}' target='_top'><img width='60' src='{4}'/></a> <a href='{5}' target='_top'><img width='60' src='{6}'/></a></td><td>{7}</td></tr>".format( iconUrl, vrUrl, vrIconUrl, infoUrl, referenceIconUrl, semanticUrl, networkIconUrl, label ) print descriptionText def displayData( database, project, condition ): server = 'tcp:digerati.aks.ac.kr' username = 'guest' password = 'guest' db = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password) cur = db.cursor() geoTable = project +'Space' comstring = "select id, complex, site, label, latitude, longitude, altitude, infoUrl, iconUrl, vrUrl, semanticUrl from " + geoTable if condition <> "": command = comstring + " where {0}".format( condition ) else: command = comstring # cur.execute(unicode(command, "utf-8")) cur.execute( command ) poiList = [] for row in cur.fetchall(): try: poiList.append( {'id':row[0],'complex':row[1],'site':row[2],'label':row[3],'latitude':row[4],'longitude':row[5],'altitude':row[6],'infoUrl':row[7], 'iconUrl':row[8], 'vrUrl':row[9], 'semanticUrl':row[10] } ) except: return cur.close() db.close() createCZML( poiList ); def displayResults(template, db, project, condition): print("Content-type: text/html") print f = open(template) while 1: line = f.readline() if not line: break if( '#YourData' == line.strip()): displayData( db, project, condition ) else: print line f.close() def main(): reload(sys) sys.setdefaultencoding('utf8') cgitb.enable() form = cgi.FieldStorage() try: db = form.getvalue('db', '') project = form.getvalue('project', '') key = form.getvalue('key', '') except: return if key <> '' : condition = "complex='" + key + "'" else: condition='' displayResults("templateTbl.htm", db, project, condition ) main()
templateTbl.htm
<!--Template for displying search results, Center for DH at AKS--> <html> <head> <title>Retrieved Data Set</title> <meta charset="UTF-8"/> <style> table { border:1px solid #444444; text-align:left; width:100%; color:#202020; font-size:15px; font-family:함초롬바탕; } table th { background-color:Olive; color:White; } table tr:nth-child(odd) td{ background:#ffffff; } table tr:nth-child(even) td{ background:#dfdfdf; } td { padding: 5px 10px 5px 10px; } </style> </head> <body> <table> #YourData </table> </body> </html>
tourSpace02.py+templateNmap.htm
tourSpace02_1.py
#!/usr/bin/python #-*- coding: utf-8 -*- import sys import pyodbc import cgi import cgitb noIconUrl = "http://dh.aks.ac.kr/VR/style/photo.png" referenceIconUrl = "http://dh.aks.ac.kr/VR/style/text60.png" networkIconUrl = "http://dh.aks.ac.kr/VR/style/semantic.png" vrIconUrl = "http://dh.aks.ac.kr/VR/style/vr.png" maxPOI=250 def createMarker( poiList ): counter = 0 for item in poiList: latitude = item['latitude'] longitude = item['longitude'] label = item['label'] infoUrl = item['infoUrl'] semanticUrl = item['semanticUrl'] vrUrl = item['vrUrl'] iconUrl = item['iconUrl'] if( iconUrl<>None ): contentStr = "{0}<br/><img src=\"{1}\" width=120/>".format( label, iconUrl ) else: contentStr = "{0}<br/><img src=\"{1}\" width=120/>".format( label, noIconUrl ) if( vrUrl <> None): pavilionStr = "<a href=\"{0}\"><img src=\"{1}\" width=60/></a>".format(vrUrl, vrIconUrl) contentStr = contentStr + pavilionStr if( infoUrl <> None ): infoStr = "<a href=\"{0}\"><img src=\"{1}\" width=60/></a>".format(infoUrl, referenceIconUrl) contentStr = contentStr + infoStr if( semanticUrl <> None): networkStr = "<a href=\"{0}\"><img src=\"{1}\" width=60/></a>".format(semanticUrl, networkIconUrl) contentStr = contentStr + networkStr print "var marker{0} = new naver.maps.Marker({{".format(counter) print " position: new naver.maps.LatLng({0}, {1}),".format(latitude, longitude) print " map: map" print "});\n" print "var htmtxt{:d} = [".format(counter) print " '<div class=\"iw_inner\">'," print " '{0}',".format(contentStr) print " '</div>'" print "].join('');\n" counter = counter + 1 if counter > 100: break; def addListener( limit ): counter = 0 while( counter < limit ): print "naver.maps.Event.addListener(marker{:d}, 'click', function(e) {{".format(counter) print " if (infowindow.getMap()) {" print " infowindow.close();" print " } else {" print " infowindow.setContent(htmtxt{:d})".format(counter) print " infowindow.open(map, marker{:d});".format(counter) print " }" print "});\n" counter = counter + 1 if counter > 100: break; def displayData( database, project, condition ): server = 'tcp:digerati.aks.ac.kr' username = 'guest' password = 'guest' db = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password) cur = db.cursor() geoTable = project + 'Space' comstring = "select id, label, latitude, longitude, infoUrl, semanticUrl, vrUrl, iconUrl from " + geoTable if condition <> "": command = comstring + " where {0}".format( condition ) else: command = comstring cur.execute(unicode(command, "utf-8")) poiList = [] counter = 0 for row in cur.fetchall(): try: poiList.append( {'id':row[0],'label':row[1],'latitude':row[2],'longitude':row[3],'infoUrl':row[4], 'semanticUrl':row[5], 'vrUrl':row[6], 'iconUrl':row[7] } ) except: return counter = counter + 1; cur.close() db.close() createMarker( poiList ) addListener( counter ); def displayResults(template, db, project, condition): print("Content-type: text/html") print f = open(template) while 1: line = f.readline() if not line: break if( '#YourData' == line.strip()): displayData( db, project, condition ) else: print line f.close() def main(): reload(sys) sys.setdefaultencoding('utf8') cgitb.enable() form = cgi.FieldStorage() try: db = form.getvalue('db', '') project = form.getvalue('project', '') key = form.getvalue('key', '') except: return if key <> '' : condition = "complex='" + key + "'" else: condition='' displayResults("templateNmap.htm", db, project, condition ) main()
tourSpace02_2.py
#!/usr/bin/python #-*- coding: utf-8 -*- import sys import pyodbc import cgi import cgitb noIconUrl = "http://dh.aks.ac.kr/VR/style/photo.png" referenceIconUrl = "http://dh.aks.ac.kr/VR/style/text60.png" networkIconUrl = "http://dh.aks.ac.kr/VR/style/semantic.png" vrIconUrl = "http://dh.aks.ac.kr/VR/style/vr.png" maxPOIs = 255 def createMarker( poiList ): counter = 0 for item in poiList: latitude = item['latitude'] longitude = item['longitude'] label = item['label'] infoUrl = item['infoUrl'] semanticUrl = item['semanticUrl'] vrUrl = item['vrUrl'] iconUrl = item['iconUrl'] if( iconUrl<>None ): #아이콘이없으면 안뜨게 contentStr = "{0}<br/><img src=\"{1}\" width=120/>".format( label, iconUrl ) else: contentStr = "{0}<br/><img src=\"{1}\" width=120/>".format( label, noIconUrl ) if( vrUrl <> None): pavilionStr = "<a href=\"{0}\"><img src=\"{1}\" width=60/></a>".format(vrUrl, vrIconUrl) contentStr = contentStr + pavilionStr if( infoUrl <> None ): infoStr = "<a href=\"{0}\"><img src=\"{1}\" width=60/></a>".format(infoUrl, referenceIconUrl) contentStr = contentStr + infoStr if( semanticUrl <> None): networkStr = "<a href=\"{0}\"><img src=\"{1}\" width=60/></a>".format(semanticUrl, networkIconUrl) contentStr = contentStr + networkStr print "var marker{0} = new naver.maps.Marker({{".format(counter) print " position: new naver.maps.LatLng({0}, {1}),".format(latitude, longitude)#위도 경도정보주면서 마커생김 맵마커만들어줘 마커1...100까지 생김 print " map: map" print "});\n" print "var htmtxt{:d} = [".format(counter) print " '<div class=\"iw_inner\">'," print " '{0}',".format(contentStr) print " '</div>'" print "].join('');\n" counter = counter + 1 if counter > maxPOIs: break; def addListener( limit ): counter = 0 while( counter < limit ): print "naver.maps.Event.addListener(marker{:d}, 'click', function(e) {{".format(counter) print " if (infowindow.getMap()) {" print " infowindow.close();" print " } else {" print " infowindow.setContent(htmtxt{:d})".format(counter) print " infowindow.open(map, marker{:d});".format(counter) print " }" print "});\n" counter = counter + 1 if counter > maxPOIs: break; def displayData( database, project, condition ): server = 'tcp:digerati.aks.ac.kr' username = 'guest' password = 'guest' db = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password) cur = db.cursor() geoTable = project + 'Space' comstring = "select id, label, latitude, longitude, infoUrl, semanticUrl, vrUrl, iconUrl from " + geoTable if condition <> "": command = comstring + " where {0}".format( condition ) else: command = comstring cur.execute(unicode(command, "utf-8")) poiList = [] counter = 0 for row in cur.fetchall(): try: poiList.append( {'id':row[0],'label':row[1],'latitude':row[2],'longitude':row[3],'infoUrl':row[4], 'semanticUrl':row[5], 'vrUrl':row[6], 'iconUrl':row[7] } ) except: return counter = counter + 1; cur.close() db.close() createMarker( poiList ) addListener( counter ); def displayResults(template, db, project, condition): print("Content-type: text/html") print f = open(template) while 1: line = f.readline() if not line: break if( '#YourData' == line.strip()): displayData( db, project, condition ) else: print line f.close() def main(): reload(sys) sys.setdefaultencoding('utf8') cgitb.enable() form = cgi.FieldStorage() try: db = form.getvalue('db', '') project = form.getvalue('project', '') key = form.getvalue('key', '') except: return if key <> '' : condition = "complex='" + key + "'" else: condition='' displayResults("templateNmap.htm", db, project, condition ) main()
templateNmap.htm
<!DOCTYPE html> <html> <head> <title>Naver Map Api</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"> <script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?ncpClientId=tlmos9eset"></script> <style> div.iw_inner { text-align: center; font-family:함초롬바탕; } </style> </head> <body> <div id="map" style="width:100%;height:720px;"></div> <script> var map = new naver.maps.Map('map', { center: new naver.maps.LatLng(37, 127), zoom: 7, zoomControl: true }); var contentString = [ '<div class="iw_inner">', ' <img src=\"/VR/style/photo.png\" width=\"120\"/>', '</div>' ].join(''); var infowindow = new naver.maps.InfoWindow({ content: contentString, maxWidth: 460, backgroundColor: "White", borderColor: "DarkCyan", borderWidth: 1, anchorSize: new naver.maps.Size(10, 10), anchorSkew: true, anchorColor: "White", pixelOffset: new naver.maps.Point(10, -10) }); #YourData </script> </body> </html>
Question
* poiList : Point of interest * <div></div> : division 지도영역/info box부분 표시하는부분 스타일지정 * fetchone & fetchall **fetchone은 하나씩가져오는것-가져올양이 얼만큼인지 불확실할때 한정양을 걸어놓고 & fetchall은 한정양을 알고 있을때 몽땅 부름.