NZRS / wavetrace

Radio propagation modelling
GNU Affero General Public License v3.0
61 stars 22 forks source link

Code review ideas: python xml libs instead of grep/echo/sed code #15

Open ghost opened 8 years ago

ghost commented 8 years ago

kml2wld.sh contains this code

imgcoord=$(grep -A 10 "$imgname" "$path/$bn.kml") north=$(echo $imgcoord | sed 's/^.*<north>\([0-9-][0-9\.]*\)<\/north>.*/\1/') south=$(echo $imgcoord | sed 's/^.*<south>\([0-9-][0-9\.]*\)<\/south>.*/\1/') east=$(echo $imgcoord | sed 's/^.*<east>\([0-9-][0-9\.]*\)<\/east>.*/\1/') west=$(echo $imgcoord | sed 's/^.*<west>\([0-9-][0-9\.]*\)<\/west>.*/\1/')

Fast, full of zen, fairly self documenting, but a nightmare for a python dev to debug.

The kml could be opened with an xml parser (ElementTree XML API has been build into python since 2.5 AFAIK) and much of the manipulation could be done in pure python.

jamiesgithub commented 8 years ago

Agreed....

This was half implemented with this:

https://github.com/NZRS/KMLOverlay2GIS/blob/master/KMLOverlay2GIS.py