GPS Test KML to CSV

As part of surveying my local cemetery, I am using an Android app called GPS Test by Chartcross.

I start with list a list of graves in my cemetery I need to get GPS coordinates for.



I then gather those by taking samples with the app and changing the names of the points to the GraveID from my report.


I export the KML file from the app and transfer it to my PC.  (I used Google Drive as my go-between, but any method will do, such as Bluetooth transfer.)

I modified the code slightly from my previous post, MyMaps to Spreadsheet, KML to CSV and back (rvnllc.com).  

import sys
import xml.etree.ElementTree as ET
# KML namespace
ns = {"": "http://www.opengis.net/kml/2.2",
      "gpstestkml":"http://www.chartcross.co.uk/XML/GPXDATA/1/0"}
# Where is "coordinates" in each Placemark?
wherecoords = 'Point/coordinates'
# Where is "TimeStamp" in each Placemark?
wherets = 'TimeStamp/when'
# Where is accuracy in each Placemark?
whereacc = 'ExtendedData/gpstestkml:accuracy'
  
kmlfile = sys.argv[1]
placemarksprocessed =0
csvfile = kmlfile.split(sep='.')[0] + '.csv'
print("CSV file: " + csvfile)
fout = open(csvfile,'w')
print ('GraveID,TimeStamp,Lat,Long,Accuracy')
print ('GraveID,TimeStamp,Lat,Long,Accuracy',file=fout)
tree = ET.parse(kmlfile)
root = tree.getroot()
#Document Level
docelem=root.find('Document',ns)
#Folder Level
folelem=docelem.find('Folder',ns)

for placemark in folelem.findall('Placemark',ns): 
    
    TStamp = placemark.find(wherets,ns).text.strip("Z").replace("T"," ")
    graveid = placemark.find('name',ns).text.split("@")[0].strip()
    coords = placemark.find(wherecoords,ns).text.split(",")
    accrcy = placemark.find(whereacc,ns).text
    
    print (graveid,TStamp,coords[1],coords[0],accrcy,sep=',')
    print (graveid,TStamp,coords[1],coords[0],accrcy,sep=',',file=fout)
    placemarksprocessed =  placemarksprocessed + 1
        
fout.close()
print ('Placemarks processed: ' ,placemarksprocessed)

The above converts from this:


To this:

Now that it's in CSV format, I can upload the data to my database application.

Helpful Links:

Bob's Tech Corner

"GPS Test KML to CSV"

https://bobstech.rvnllc.com

Bob Nightingale, info@rvnllc.com

Created 28-DEC-2020



Comments

  1. Cyberpunk City was one other distinctive title we discovered – named after the trending video game. Click right here to explore one 카지노사이트 of the best free slots available at Red Dog Casino. There are seven completely different deposit strategies supported at this site.

    ReplyDelete

Post a Comment

Popular posts from this blog

MyMaps to Spreadsheet, KML to CSV and back

vim my way