Created
July 29, 2012 20:44
-
-
Save walkermatt/3201750 to your computer and use it in GitHub Desktop.
Simple Loader prep class to import KML police.uk neighbourhood boundaries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A class used to manipulate Police KML data, used with prepgml4ogr.py. | |
""" | |
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