Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple Loader prep class to import KML neighbourhood boundaries
A class used to manipulate Police KML data, used with
import os
from lxml import etree
class prep_kml():
def __init__(self, inputfile):
self.inputfile = inputfile
self.infile = os.path.basename(inputfile)
self.feat_types = ['Placemark']
def get_feat_types(self):
return self.feat_types
def prepare_feature(self, feat_str):
# Parse the xml string into something useful
feat_elm = etree.fromstring(feat_str)
feat_elm = self._prepare_feat_elm(feat_elm)
return etree.tostring(feat_elm, encoding='UTF-8', pretty_print=True).decode('utf_8')
def _prepare_feat_elm(self, feat_elm):
feat_elm = self._add_filename_elm(feat_elm)
return feat_elm
def _add_filename_elm(self, feat_elm):
# Create an element with the neighbourhood code
elm = etree.SubElement(feat_elm, "name")
elm.text = self.infile[:-4]
# Set the description attribute to the name of the
# directory that the file is within as this is the force name
elm = etree.SubElement(feat_elm, "description")
elm.text = os.path.split(os.path.split(self.inputfile)[0])[-1]
return feat_elm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.