Advertisement
Guest User

create SQL updates for RGB values from SLD

a guest
Aug 7th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1. from xml.etree.ElementTree import ElementTree
  2. import xml.etree
  3. import re
  4.  
  5. namespaces = {
  6. 'ogc': "http://www.opengis.net/ogc",
  7. 'sld': "http://www.opengis.net/sld"
  8. }
  9.  
  10. def updatesForAge():
  11.     ### Age
  12.     ret = ""
  13.     mydoc = ElementTree(file=r"CGI-inspire-AgeTextURI-CGMW.sld")
  14.     for e in mydoc.findall('//sld:Rule',namespaces):
  15.         #print e.get('sld:Name').text
  16.         nodecontent = xml.etree.ElementTree.tostring(e)
  17.         #print nodecontent
  18.         m_id = re.search('.*(h.*inspire.*?)</',nodecontent)
  19.         if m_id is not None:
  20.             idstr=m_id.groups(0)[0]
  21.         m_rgb = re.search('.*rgb\((\d+),(\d+),(\d+)\)</',nodecontent)
  22.         if m_rgb is not None:
  23.             #print m_rgb.groups()
  24.             #print "R%s G%s B%s" % ( m_rgb.groups()[0] , m_rgb.groups()[1], m_rgb.groups()[2] )
  25.             ret += "update portrayal.GeochronologicEraValue set R=%s, G=%s, B=%s where id='%s'\n" % (
  26.                 m_rgb.groups()[0] , m_rgb.groups()[1], m_rgb.groups()[2], idstr
  27.                 )
  28.     return ret
  29.  
  30.  
  31. ### Lithology
  32.  
  33. def updatesForLithology():
  34.     ret = ""
  35.     mydoc = ElementTree(file=r"CGI-INSPIRE-lithologyTextURI-INSPIREcols.sld")
  36.     for e in mydoc.findall('//sld:Rule',namespaces):
  37.         #print e.get('sld:Name').text
  38.         nodecontent = xml.etree.ElementTree.tostring(e)
  39.         #print nodecontent
  40.         m_id = re.search('.*(h.*inspire.*?)</',nodecontent)
  41.         if m_id is not None:
  42.             idstr=m_id.groups(0)[0]
  43.         m_rgb = re.search('.*#([a-fA-F0-9]{6})</',nodecontent)
  44.         if m_rgb is not None:
  45.             #print m_rgb.groups()
  46.             #print "R%s G%s B%s" % ( m_rgb.groups()[0] , m_rgb.groups()[1], m_rgb.groups()[2] )
  47.             #print "update portrayal.GeochronologicEraValue set R=%s, G=%s, B=%s where id='%s'" % (
  48.             # in der lithology-SLD stehen nur Hex-HTML-Farben drinnen. Die müssen nach R G B umgerechnet werden.
  49.             (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]))
  50.             ret += "update portrayal.LithologyValue set R=%s, G=%s, B=%s where id='%s'\n" % (
  51.                 r,g,b, idstr
  52.                 )
  53.     return ret
  54.  
  55. if __name__ == "__main__":
  56.     print updatesForAge()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement