|
9 | 9 | # same directory as the script file.
|
10 | 10 | #
|
11 | 11 | # To generate TSV file go to https://planetarynames.wr.usgs.gov/AdvancedSearch
|
12 |
| -# Select System: MARS and target: Mars; |
| 12 | +# Select System: MARS and target: Mars; |
13 | 13 | # Under "Columns to include": add column 'Feature Type Code';
|
14 | 14 | # Click 'Search'
|
15 |
| -# Scroll down to the bottom and click 'TSV (tab separated values) for importing into other spread sheets' |
16 |
| -# Save the file as SearchResults in the same directory as this script. |
| 15 | +# Scroll down to the bottom and click 'TSV (tab separated values) for importing into other spread sheets' |
| 16 | +# Save the file as SearchResults in the same directory as this script. |
17 | 17 | # Usage : 'python tsv2xml.py' and the resulting file landmarks.xml is fit for use with MSP
|
18 | 18 | # when put in the correct directory
|
19 | 19 |
|
20 |
| -# TODO: |
| 20 | +# TODO: |
21 | 21 | # Insert doctype - <!DOCTYPE landmark-list SYSTEM "conf/dtd/landmarks.dtd">
|
22 | 22 | # Add parameters
|
23 | 23 | # Refactor
|
24 | 24 |
|
25 | 25 | from xml.dom.minidom import Document
|
26 | 26 | from decimal import Decimal
|
27 | 27 |
|
28 |
| -# Initialize types |
| 28 | +# Initialize types |
29 | 29 | xmldoc = Document()
|
30 | 30 | # in case we don't have a key line (bad!), assume some default field indices
|
31 | 31 | index_feature_name = 0
|
|
39 | 39 | index_approval = 8
|
40 | 40 | index_origin = 9
|
41 | 41 |
|
42 |
| -# Add introductory comments |
| 42 | +# Add introductory comments |
43 | 43 | introcomment1 = xmldoc.createComment("Landmark coordinates from USGS Astrogeology Research Program")
|
44 | 44 | introcomment2 = xmldoc.createComment("https://planetarynames.wr.usgs.gov/AdvancedSearch")
|
45 | 45 | introcomment3 = xmldoc.createComment("Landmarks to be displayed in the user interface. ")
|
46 | 46 | xmldoc.appendChild(introcomment1)
|
47 | 47 | xmldoc.appendChild(introcomment2)
|
48 | 48 | xmldoc.appendChild(introcomment3)
|
49 |
| - |
| 49 | + |
50 | 50 | # Create the base XML element
|
51 | 51 | landmarks = xmldoc.createElement("landmark-list")
|
52 | 52 | #landmarks.setAttribute("xmlns", "http://mars-sim.sourceforge.net/landmarks")
|
|
61 | 61 | tsvlinelist = f.readlines() # fill a list with TSV lines
|
62 | 62 |
|
63 | 63 | # Main parsing loop
|
64 |
| -for tsvline in tsvlinelist: |
| 64 | +for tsvline in tsvlinelist: |
65 | 65 | if tsvline == "\n":
|
66 | 66 | print "Skipped empty line..." # ignore empty lines
|
67 | 67 | elif "Feature_Name" in tsvline:
|
|
81 | 81 | else:
|
82 | 82 | print "Found data line, parsing..." #ready to move data into XML DOM
|
83 | 83 | valuelist = tsvline.split("\t") # explode into a list of values
|
84 |
| - |
| 84 | + |
85 | 85 | landmark = xmldoc.createElement("landmark")
|
86 |
| - |
| 86 | + |
87 | 87 | namestring = valuelist[index_feature_name]
|
88 | 88 | namestring = namestring.replace('[', '')
|
89 | 89 | namestring = namestring.replace(']', '')
|
90 | 90 | landmark.setAttribute("name", namestring) # Feature_Name
|
91 |
| - |
| 91 | + |
92 | 92 | landmark.setAttribute("diameter", valuelist[index_diameter]) # Diameter of feature
|
93 | 93 | # Center_Longitude
|
94 | 94 | if Decimal(valuelist[index_long]) > 180:
|
95 | 95 | landmark.setAttribute("longitude", str((360 - Decimal(valuelist[index_long])))+" W")
|
96 | 96 | else:
|
97 |
| - landmark.setAttribute("longitude", str((Decimal(valuelist[index_long])))+" E") |
| 97 | + landmark.setAttribute("longitude", str((Decimal(valuelist[index_long])))+" E") |
98 | 98 | # Center_Latitude
|
99 | 99 | if Decimal(valuelist[index_lat]) < 0:
|
100 | 100 | landmark.setAttribute("latitude", str(abs(Decimal(valuelist[index_lat])))+" S")
|
|
107 | 107 | landmarks.appendChild(landmark)
|
108 | 108 |
|
109 | 109 |
|
110 |
| -# Add fixed external data for artificial objects (from Google Mars and Wikipedia) |
| 110 | +# Add fixed external data for artificial objects |
| 111 | +# Source: https://en.wikipedia.org/wiki/List_of_artificial_objects_on_Mars#Table_of_objects |
111 | 112 | artobjcomment = xmldoc.createComment("Artificial Objects")
|
112 | 113 | landmarks.appendChild(artobjcomment)
|
113 | 114 |
|
114 |
| -artobjarray =[["Beagle 2 Lander", "90.0 E", "10.6 N", "0.1"], |
115 |
| - ["Mars 2 Lander", "47.0 E", "45.0 S", "0.1"], |
116 |
| - ["Mars 3 Lander", "158.0 W", "45.0 S", "0.1"], |
117 |
| - ["Mars 6 Lander", "19.5 W", "23.9 S", "0.1"], |
118 |
| - ["Mars Pathfinder Rover", "33.3 W", "19.3 N", "0.1"], |
119 |
| - ["Mars Polar Lander", "164.7 E", "76.7 S", "0.1"], |
120 |
| - ["MSL Curiosity Rover", "137.2 E", "4.3 S", "0.1"], |
121 |
| - ["MER Spirit Rover", "175.47 E", "14.57 S", "0.1"], |
122 |
| - ["MER Opportunity Rover", "5.53 W", "1.95 S", "0.1"], |
123 |
| - ["Phoenix Mars Lander", "125.7 W", "68.22 N", "0.1"], |
124 |
| - ["Viking Lander 1", "48.0 W", "22.5 N", "0.1"], |
125 |
| - ["Viking Lander 2", "133.7 E", "47.9 N", "0.1"]] |
126 |
| - |
127 |
| -for artobj in artobjarray: |
| 115 | +artobjarray =[["Mars 2", "313.0 W", "45.0 S", "0.1"], |
| 116 | + ["Mars 3", "158.0 W", "45.0 S", "0.1"], |
| 117 | + ["Mars 6", "19.42 W", "23.9 S", "0.1"], |
| 118 | + ["Viking 1 Lander", "48.222 W", "22.697 N", "0.1"], |
| 119 | + ["Viking 2 Lander", "225.99 W", "48.269 N", "0.1"], |
| 120 | + ["Mars Pathfinder + Sojourner Rover", "33.55 W", "19.33 N", "0.1"], |
| 121 | + ["Mars Polar Lander + Deep Space 2", "195.0 W", "76.0 S", "0.1"], |
| 122 | + ["Beagle 2", "90.4295 E", "11.5265 N", "0.1"], |
| 123 | + ["Spirit Rover (MER-A)", "175.4785 E", "14.5718 S", "0.1"], |
| 124 | + ["Opportunity Rover (MER-B)", "354.4734 E", "1.9462 S", "0.1"], |
| 125 | + ["Phoenix Mars Lander", "125.9 W", "68.15 N", "0.1"], |
| 126 | + ["Mars Science Laboratory (Curiosity)", "137.2 E", "4.6 S", "0.1"], |
| 127 | + ["Schiaparelli EDM Lander", "357.5 E", "0.2 N", "0.1"], |
| 128 | + ["inSight Lander", "135.0 E", "4.5 N", "0.1"]] |
| 129 | + |
| 130 | +for artobj in artobjarray: |
128 | 131 | landmark = xmldoc.createElement("landmark")
|
129 |
| - landmark.setAttribute("name", artobj[0]) |
130 |
| - landmark.setAttribute("longitude", artobj[1]) |
131 |
| - landmark.setAttribute("latitude", artobj[2]) |
132 |
| - landmark.setAttribute("diameter", artobj[3]) |
133 |
| - landmark.setAttribute("approvaldate", "N/A") |
| 132 | + landmark.setAttribute("name", artobj[0]) |
| 133 | + landmark.setAttribute("longitude", artobj[1]) |
| 134 | + landmark.setAttribute("latitude", artobj[2]) |
| 135 | + landmark.setAttribute("diameter", artobj[3]) |
| 136 | + landmark.setAttribute("approvaldate", "N/A") |
134 | 137 | landmark.setAttribute("type", "AO") # artificial object
|
135 |
| - landmark.setAttribute("origin", "N/A") |
| 138 | + landmark.setAttribute("origin", "N/A") |
136 | 139 |
|
137 | 140 | landmarks.appendChild(landmark)
|
138 | 141 |
|
139 | 142 | f.close() # close our TSV file stream nicely
|
140 |
| - |
| 143 | + |
141 | 144 | # Write out the final XML data to file landmarks.xml
|
142 | 145 | f = open('landmarks.xml', 'w')
|
143 | 146 | xmldoc.writexml(f, encoding= 'utf-8', indent=" ",addindent=" ",newl="\n")
|
|
0 commit comments