[GRASS-SVN] r47926 - grass-addons/grass7/gui/wxpython/wx.wms
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Aug 28 16:51:26 EDT 2011
Author: sudeepsingh
Date: 2011-08-28 13:51:26 -0700 (Sun, 28 Aug 2011)
New Revision: 47926
Modified:
grass-addons/grass7/gui/wxpython/wx.wms/parse.py
grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py
Log:
Layers Displayed Hierarchialy now, unstable version, to be modified
Modified: grass-addons/grass7/gui/wxpython/wx.wms/parse.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/parse.py 2011-08-28 19:53:58 UTC (rev 47925)
+++ grass-addons/grass7/gui/wxpython/wx.wms/parse.py 2011-08-28 20:51:26 UTC (rev 47926)
@@ -24,9 +24,18 @@
from grass.script import core as grass
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
import re
+from xml.dom.minidom import parse, parseString
from urllib2 import Request, urlopen, URLError, HTTPError
+key = 0
+
+class newLayerData():
+ name = None
+ title = None
+ abstract = None
+ srsList = None
+
class LayerData():
name = None
title = None
@@ -137,8 +146,39 @@
xml = f.read()
soup = BeautifulSoup(xml)
dfs(soup,LayerTree, layerTreeRoot)
+
+def test(xml,LayerTree,layerTreeRoot):
+ f = open('/home/sudeep/in3.xml','w')
+ f.write(xml)
+ f.close()
+ f = open('/home/sudeep/in3.xml','r')
+ xml1=f.read()
+ '''
+ #xml1=xml
+ #xml='<root> '+xml1+' </root>'
+ a=xml1.find('<WMT_MS_Capabilities')
+ print 'a1='+str(a)
+ if(a==-1):
+ print 'a2='+str(a)
+ a=xml1.find('<wmt_ms_capabilities')
+ if(a==-1):
+ print 'a3='+str(a)
+ print 'serious mix up'
+ return
+ print 'a4='+str(a)
+ #print xml1[a:]
+ '''
+ dom=parseString(xml1)
+ root=dom.firstChild
+ lData = {}
+ global key
+ key = 0
+ dfs1(dom,LayerTree,layerTreeRoot,lData)
+ return lData
+
def dfs(root,LayerTree, ltr):
+
if not hasattr(root, 'contents'):
print root.string
return
@@ -155,6 +195,66 @@
dfs(child, LayerTree, id)
return
+def getAttributeLayers(node, attribute):
+ Attribute = attribute.capitalize()
+ l=node.getElementsByTagName(attribute)
+ g=None
+ if(len(l)>0):
+ g=l[0].firstChild
+ else:
+ l=node.getElementsByTagName(Attribute)
+ if(len(l)>0):
+ g=l[0].firstChild
+ if(g is not None):
+ return unicode(g.nodeValue)
+ else:
+ return None
+
+def dfs1(node,LayerTree, ltr,lData):
+ global key
+ if ( hasattr(node,'data')):
+ return
+ id = ltr
+ if(hasattr(node,'tagName')):
+ if(node.tagName == 'Layer' or node.tagName == 'layer'):
+ name = getAttributeLayers(node, 'name')
+ if(name is not None):
+ lData[str(key)] = newLayerData()
+ title = getAttributeLayers(node, 'title')
+ abstract = getAttributeLayers(node, 'abstract')
+ if(title is None):
+ title = unicode('')
+ else:
+ title = ':'+title
+
+ if(abstract is None):
+ abstract = unicode('')
+ else:
+ abstract = ':'+abstract
+
+ description = unicode(str(key)+'-'+name+title+abstract)
+ id = LayerTree.AppendItem(ltr,description)
+
+ SRS = node.getElementsByTagName('SRS')
+ srsList = []
+ for srs in SRS:
+ #print srs.toxml()
+ #print srs.firstChild.nodeValue
+ srsList += [str(srs.firstChild.nodeValue)[5:]]
+ print srsList
+ lData[str(key)].name = name
+ lData[str(key)].abstract = abstract
+ lData[str(key)].title = title
+ lData[str(key)].srsList = srsList
+ key = key + 1
+
+
+ for child in node.childNodes:
+ dfs1(child,LayerTree,id,lData)
+ return
+
+
+
def parseGrass_Region(grassRegion, dir):
grassRegion = 'n-s resol: 26.266417; n-s resol3: 100; rows: 533; north: 4928000.0; t-b resol: 1; zone: 13; bottom: 0; rows3: 140; west: 590000.0; top: 1; cols: 698; cols3: 190; depths: 1; e-w resol: 27.220630; proj: 1; e-w resol3: 100; east: 609000.0; south: 4914000.0;'
width = '698'
Modified: grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py 2011-08-28 19:53:58 UTC (rev 47925)
+++ grass-addons/grass7/gui/wxpython/wx.wms/wmsmenu.py 2011-08-28 20:51:26 UTC (rev 47926)
@@ -35,6 +35,14 @@
from LoadConfig import loadConfigFile
+class newLayerData():
+ name = None
+ title = None
+ abstract = None
+ srsList = None
+
+
+
class LayerData():
name = None
title = None
@@ -77,6 +85,33 @@
class Message():
pass
+class ManageLayerTree():
+
+ def getAllChild(self,LayerTree, parentId):
+ children = []
+ currentchild,obj = LayerTree.GetFirstChild(parentId)
+ while(1):
+ if(not currentchild.IsOk()):
+ break
+ children += [currentchild]
+ nextchild = LayerTree.GetNextSibling(currentchild)
+ currentchild = nextchild
+ return children
+
+ def layerTreeItemDFS(self,parent,LayerTree,nodeId):
+ if(not nodeId.IsOk()):
+ return
+ currentLayerDetails = LayerTree.GetItemText(nodeId)
+ currentLayerName = (currentLayerDetails.split(':')[0]).split('-')[1]
+ currentLayerKey = (currentLayerDetails.split(':')[0]).split('-')[0]
+ parent.epsgList.Append('<'+currentLayerName+'>')
+ listEPSG = parent.layerDataDict1[currentLayerKey].srsList
+ parent.epsgList.AppendItems(listEPSG)
+ parent.layersString += ',' + currentLayerName
+ allChild = self.getAllChild(LayerTree, nodeId)
+ for child in allChild:
+ self.layerTreeItemDFS(parent,LayerTree,child)
+
class wmsFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: wmsFrame.__init__
@@ -131,6 +166,7 @@
self.Bind(wx.EVT_CLOSE, self.OnQuit)
self.AddServerisClosed = True
self.layerName = ""
+ self.layerDataDict1 = {}
self.selectedEPSG = None
def __set_properties(self):
@@ -215,9 +251,11 @@
return
layerDataDict = parsexml2(xml)
ld = LayerData()
- ld.appendLayerTree(layerDataDict, self.LayerTree, self.layerTreeRoot)
+ #ld.appendLayerTree(layerDataDict, self.LayerTree, self.layerTreeRoot)
self.keyToEPSGCodes = ld.setKeyToEPSGCodes(layerDataDict)
self.selectedEPSG = None
+ self.layerDataDict1 = test(xml,self.LayerTree,self.layerTreeRoot)
+ print self.layerDataDict1
self.LayerTree.Expand(self.layerTreeRoot)
except HTTPError, e:
message = 'The server couldn\'t fulfill the request.'
@@ -272,12 +310,12 @@
return
bbox = self.getBBOXParameters()
- bbox = '584344,397868,585500,398500'
+ #bbox = '584344,397868,585500,398500'
self.url_in = self.selectedURL
getMap_request_url = self.url_in
getMap_request_url += '?service=WMS&request=GetMap&version=1.1.1&format=image/png&width=800&height=600&srs=EPSG:'+self.selectedEPSG+'&layers='
getMap_request_url += self.layerName+'&bbox='+bbox
-
+ print getMap_request_url
req = Request(getMap_request_url)
try:
message = 'GetMaps request sent. Waiting for response...'
@@ -374,6 +412,9 @@
def OnServerListEnter(self, event): # wxGlade: wmsFrame.<event_handler>
event.Skip()
+
+
+
def OnLayerTreeSelChanged(self, event): # wxGlade: wmsFrame.<event_handler>"
self.epsgList.Clear()
@@ -381,7 +422,23 @@
self.selectedLayerList = []
keys =[]
self.layerName = ""
+ print len(self.LayerTree.GetSelections())
+ res = ''
+ self.layersString=''
+ manageLT = ManageLayerTree()
for sellayer in self.LayerTree.GetSelections():
+ #res = res + ','+self.LayerTree.GetItemText(sellayer)
+ manageLT.layerTreeItemDFS(self,self.LayerTree, sellayer)
+
+
+ #print child
+ print self.layersString[1:]
+ self.layerName = self.layersString[1:]
+ print self.layerDataDict1
+ self.selectedEPSG = None
+
+ '''
+ for sellayer in self.LayerTree.GetSelections():
layerNameString = self.LayerTree.GetItemText(sellayer)
layerNameStringList = layerNameString.split(':')
if(len(layerNameStringList)==0):
@@ -403,7 +460,7 @@
self.layerName = self.layerName[1:]
self.selectedEPSG = None
-
+ '''
event.Skip()
def OnAddServer(self, event): # wxGlade: wmsFrame.<event_handler>
@@ -483,6 +540,7 @@
# end of class wmsFrame
def DisplayWMSMenu():
+ #print os.environ
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
wms_Frame = wmsFrame(None, -1, "")
More information about the grass-commit
mailing list