Changeset 8272 in josm
- Timestamp:
- 2015-04-25T23:57:19+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/taginfoextract.groovy
r7955 r8272 11 11 import javax.imageio.ImageIO 12 12 13 import groovy.json.JsonBuilder 13 14 import org.openstreetmap.josm.Main 14 15 import org.openstreetmap.josm.data.Version … … 235 236 collect_tags() 236 237 237 def datetime = new Date().format("yyyyMMdd'T'hhmmssZ") 238 output """{ 239 | "data_format": 1, 240 | "data_updated": "${datetime}", 241 | "project": { 242 | "name": "JOSM main mappaint style", 243 | "description": "Tags supported by the main mappaint style in the OSM editor JOSM", 244 | "project_url": "http://josm.openstreetmap.de/", 245 | "icon_url": "http://josm.openstreetmap.de/export/7770/josm/trunk/images/logo_16x16x8.png", 246 | "contact_name": "JOSM developer team", 247 | "contact_email": "josm-dev@openstreetmap.org" 248 | }, 249 | "tags": [ 250 |""".stripMargin() 251 // another optional field is "data_url": ... 252 253 def sep = "" 254 for (tag in tags) { 238 def tags = tags.collect { 239 def tag = it 255 240 def types = [] 256 241 def final_url = null … … 258 243 def node_url = new NodeChecker(tag).find_url(true) 259 244 if (node_url) { 260 types += ' "node"'245 types += 'node' 261 246 final_url = node_url 262 247 } 263 248 def way_url = new WayChecker(tag).find_url(final_url == null) 264 249 if (way_url) { 265 types += ' "way"'250 types += 'way' 266 251 if (!final_url) { 267 252 final_url = way_url … … 270 255 def area_url = new AreaChecker(tag).find_url(final_url == null) 271 256 if (area_url) { 272 types += ' "area"'257 types += 'area' 273 258 if (!final_url) { 274 259 final_url = area_url … … 276 261 } 277 262 278 output """${sep} { 279 | "key": "${tag[0]}", 280 | "value": "${tag[1]}", 281 | "object_types": ${types}""".stripMargin() 282 if (final_url != null) { 283 output """, 284 | "icon_url": "${final_url}" 285 | }""".stripMargin() 286 } else { 287 output """ 288 | }""".stripMargin() 289 } 290 sep = ",\n" 291 } 292 output """ 293 | ] 294 |} 295 |""".stripMargin() 263 def obj = [key: tag[0], value: tag[1]] 264 if (types) obj += [object_types: types] 265 if (final_url) obj += [icon_url: final_url] 266 obj 267 } 268 269 def json = get_json("JOSM main mappaint style", "Tags supported by the main mappaint style in the OSM editor JOSM", tags) 296 270 297 271 if (output_file != null) { 272 json.writeTo(output_file) 298 273 output_file.close() 299 } 274 } else { 275 print json.toPrettyString() 276 } 277 } 278 279 static JsonBuilder get_json(name, description, tags) { 280 def json = new JsonBuilder() 281 def project = [ 282 name: name, 283 description: description, 284 project_url: "http://josm.openstreetmap.de/", 285 icon_url: "http://josm.openstreetmap.de/export/7770/josm/trunk/images/logo_16x16x8.png", 286 contact_name: "JOSM developer team", 287 contact_email: "josm-dev@openstreetmap.org", 288 ] 289 json data_format: 1, data_updated: new Date().format("yyyyMMdd'T'hhmmssZ"), project: project, tags: tags 290 return json 300 291 } 301 292 … … 375 366 } 376 367 377 /**378 * Write the JSON output (either to file or to command line).379 */380 def output(x) {381 if (output_file != null) {382 output_file.write(x)383 } else {384 print x385 }386 }387 388 static def err_println(s) {389 System.err.println(s);390 }391 392 static def err_print(s) {393 System.err.print(s);394 }395 396 368 } 397 369
Note:
See TracChangeset
for help on using the changeset viewer.