Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from xml.etree.ElementTree import ElementTree
- import xml.etree
- import re
- namespaces = {
- 'ogc': "http://www.opengis.net/ogc",
- 'sld': "http://www.opengis.net/sld"
- }
- def updatesForAge():
- ### Age
- ret = ""
- mydoc = ElementTree(file=r"CGI-inspire-AgeTextURI-CGMW.sld")
- for e in mydoc.findall('//sld:Rule',namespaces):
- #print e.get('sld:Name').text
- nodecontent = xml.etree.ElementTree.tostring(e)
- #print nodecontent
- m_id = re.search('.*(h.*inspire.*?)</',nodecontent)
- if m_id is not None:
- idstr=m_id.groups(0)[0]
- m_rgb = re.search('.*rgb\((\d+),(\d+),(\d+)\)</',nodecontent)
- if m_rgb is not None:
- #print m_rgb.groups()
- #print "R%s G%s B%s" % ( m_rgb.groups()[0] , m_rgb.groups()[1], m_rgb.groups()[2] )
- ret += "update portrayal.GeochronologicEraValue set R=%s, G=%s, B=%s where id='%s'\n" % (
- m_rgb.groups()[0] , m_rgb.groups()[1], m_rgb.groups()[2], idstr
- )
- return ret
- ### Lithology
- def updatesForLithology():
- ret = ""
- mydoc = ElementTree(file=r"CGI-INSPIRE-lithologyTextURI-INSPIREcols.sld")
- for e in mydoc.findall('//sld:Rule',namespaces):
- #print e.get('sld:Name').text
- nodecontent = xml.etree.ElementTree.tostring(e)
- #print nodecontent
- m_id = re.search('.*(h.*inspire.*?)</',nodecontent)
- if m_id is not None:
- idstr=m_id.groups(0)[0]
- m_rgb = re.search('.*#([a-fA-F0-9]{6})</',nodecontent)
- if m_rgb is not None:
- #print m_rgb.groups()
- #print "R%s G%s B%s" % ( m_rgb.groups()[0] , m_rgb.groups()[1], m_rgb.groups()[2] )
- #print "update portrayal.GeochronologicEraValue set R=%s, G=%s, B=%s where id='%s'" % (
- # in der lithology-SLD stehen nur Hex-HTML-Farben drinnen. Die müssen nach R G B umgerechnet werden.
- (r, g, b) = map(lambda x: int(x,16), (m_rgb.groups()[0][0:2], m_rgb.groups()[0][2:4],m_rgb.groups()[0][4:6]))
- ret += "update portrayal.LithologyValue set R=%s, G=%s, B=%s where id='%s'\n" % (
- r,g,b, idstr
- )
- return ret
- if __name__ == "__main__":
- print updatesForAge()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement