Skip to content

Instantly share code, notes, and snippets.

@james-morrison-mowi
Last active March 6, 2018 15:14
Show Gist options
  • Save james-morrison-mowi/5de7f6bc65abe52fdf0f5a4f3554d393 to your computer and use it in GitHub Desktop.
Save james-morrison-mowi/5de7f6bc65abe52fdf0f5a4f3554d393 to your computer and use it in GitHub Desktop.
Function for reading cage xml data from NewDEPOMOD and bringing it into a Pandas DataFrame and generating a csv file which can be read into QGIS as a delmited text layer
import xml.etree.ElementTree as ET
import pandas as pd
def read_cage_xml(cages_xml_file_path):
xml_cages = ET.fromstring(open(cages_xml_file_path).read())
cage_details = []
for x in xml_cages[0]:
if (x.tag[-4:]) == 'cage':
cage_details.append({'easting':float(x[1].text),'northing':float(x[2].text),'cageType':x[0].text,'length':x[4].text,'width':x[5].text})
cages_df = pd.DataFrame(cage_details)
cages_df.to_csv(cages_xml_file_path[:-3] + '.csv')
return cages_df
read_cage_xml('path/to/cages.xml')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment