Last active
March 6, 2018 15:14
-
-
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
This file contains 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
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