Changeset 8681 in josm for trunk/scripts
- Timestamp:
- 2015-08-22T21:35:05+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/taginfoextract.groovy
r8671 r8681 7 7 * groovy -cp dist/josm-custom.jar scripts/taginfoextract.groovy -t mappaint 8 8 * groovy -cp dist/josm-custom.jar scripts/taginfoextract.groovy -t presets 9 * groovy -cp dist/josm-custom.jar scripts/taginfoextract.groovy -t external_presets 9 10 */ 10 11 import groovy.json.JsonBuilder 11 12 import java.awt.image.BufferedImage13 import java.nio.file.FileSystems14 import java.nio.file.Files15 import java.nio.file.Path16 17 import javax.imageio.ImageIO18 19 12 import org.openstreetmap.josm.Main 20 13 import org.openstreetmap.josm.data.Version … … 29 22 import org.openstreetmap.josm.gui.mappaint.Environment 30 23 import org.openstreetmap.josm.gui.mappaint.LineElemStyle 24 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference 31 25 import org.openstreetmap.josm.gui.mappaint.MultiCascade 32 import org.openstreetmap.josm.gui.mappaint. MapPaintStyles.IconReference26 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.SimpleKeyValueCondition 33 27 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource 34 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.SimpleKeyValueCondition35 28 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector 36 29 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser 30 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference 37 31 import org.openstreetmap.josm.gui.tagging.TaggingPreset 38 32 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems … … 41 35 import org.openstreetmap.josm.io.CachedFile 42 36 import org.openstreetmap.josm.tools.Utils 37 38 import javax.imageio.ImageIO 39 import java.awt.image.BufferedImage 40 import java.nio.file.FileSystems 41 import java.nio.file.Files 42 import java.nio.file.Path 43 43 44 44 class taginfoextract { … … 187 187 } else if (options.t == 'presets') { 188 188 script.run_presets() 189 } else if (options.t == 'external_presets') { 190 script.run_external_presets() 189 191 } else { 190 192 System.err.println 'Invalid type ' + options.t … … 235 237 void run_presets() { 236 238 init() 239 def presets = TaggingPresetReader.readAll(input_file, true) 240 def tags = convert_presets(presets. "", true) 241 write_json("JOSM main presets", "Tags supported by the default presets in the OSM editor JOSM", tags) 242 } 243 244 def convert_presets(Iterable<TaggingPreset> presets, String descriptionPrefix, boolean addImages) { 237 245 def tags = [] 238 def presets = TaggingPresetReader.readAll(input_file, true)239 246 for (TaggingPreset preset : presets) { 240 247 for (TaggingPresetItems.KeyedItem item : Utils.filteredCollection(preset.data, TaggingPresetItems.KeyedItem.class)) { … … 247 254 for (String value : values) { 248 255 def tag = [ 249 description: preset.name, 256 description: descriptionPrefix + preset.name, 250 257 key: item.key, 251 258 value: value, 252 259 object_types: preset.types.collect {it == TaggingPresetType.CLOSEDWAY ? "area" : it.toString().toLowerCase()}, 253 260 ] 254 if (preset.iconName) tag += [icon_url: find_image_url(preset.iconName)] 261 if (addImages && preset.iconName) tag += [icon_url: find_image_url(preset.iconName)] 255 262 tags += tag 256 263 } 257 264 } 258 265 } 259 260 write_json("JOSM main presets", "Tags supported by the default presets in the OSM editor JOSM", tags) 266 return tags 267 } 268 269 void run_external_presets() { 270 init() 271 def sources = new TaggingPresetPreference.TaggingPresetSourceEditor().loadAndGetAvailableSources() 272 def tags = [] 273 for (def source : sources) { 274 if (source.url.startsWith("resource")) { 275 // default presets 276 continue; 277 } 278 try { 279 println "Loading ${source.url}" 280 def presets = TaggingPresetReader.readAll(source.url, false) 281 def t = convert_presets(presets, source.title + " ", false) 282 println "Converting ${t.size()} presets of ${source.title}" 283 tags += t 284 } catch (Exception ex) { 285 System.err.println("Skipping ${source.url} due to error") 286 ex.printStackTrace() 287 } 288 } 289 write_json("JOSM user presets", "Tags supported by the user contributed presets in the OSM editor JOSM", tags) 261 290 } 262 291 … … 325 354 def init() { 326 355 Main.initApplicationPreferences() 356 Main.determinePlatformHook() 327 357 Main.pref.enableSaveOnPut(false) 328 358 Main.setProjection(Projections.getProjectionByCode("EPSG:3857"))
Note:
See TracChangeset
for help on using the changeset viewer.