示例#1
0
def rebuild_osm(filepath,context):
    from io_osm.osm_types import OSM
    if debug:
        debugger.start(log)
    if debug:
        debugger.debug("OSM import started: %r..." % filepath)
        debugger.debug("parsing xml to dom ...")

    # deactive undo for better performance and less memory usage
    global_undo = context.user_preferences.edit.use_global_undo
    context.user_preferences.edit.use_global_undo = False

    xml = parse(filepath)

    root = xml.documentElement

    # quit edit mode if enabled and deselect all objects
    editMode(context.scene,False)
    deselectObjects(context.scene)

    osm = OSM(root)
    if profiler:
        import profile
        import time
        profile.runctx('osm.generate(True)',{'debug':debug,'debugger':debugger,'log':log},{'osm':osm},'profile_results_'+time.strftime("%y-%m-%d-%H-%M-%S"))
    else:
        osm.generate(True)
        
    xml.unlink()

    # reset undo preference
    context.user_preferences.edit.use_global_undo = global_undo
示例#2
0
def rebuild_osm(filepath, context):
    from io_osm.osm_types import OSM
    if debug:
        debugger.start(log)
    if debug:
        debugger.debug("OSM import started: %r..." % filepath)
        debugger.debug("parsing xml to dom ...")

    # deactive undo for better performance and less memory usage
    global_undo = context.user_preferences.edit.use_global_undo
    context.user_preferences.edit.use_global_undo = False

    xml = parse(filepath)

    root = xml.documentElement

    # quit edit mode if enabled and deselect all objects
    editMode(context.scene, False)
    deselectObjects(context.scene)

    osm = OSM(root)
    if profiler:
        import profile
        import time
        profile.runctx('osm.generate(True)', {
            'debug': debug,
            'debugger': debugger,
            'log': log
        }, {'osm': osm},
                       'profile_results_' + time.strftime("%y-%m-%d-%H-%M-%S"))
    else:
        osm.generate(True)

    xml.unlink()

    # reset undo preference
    context.user_preferences.edit.use_global_undo = global_undo
示例#3
0
def load_osm(filepath, operator, context):
    from io_osm.osm_types import OSM
    if debug:
        debugger.start(log)
    if debug:
        debugger.debug("OSM import started: %r..." % filepath)
        debugger.debug("parsing xml to dom ...")

    # deactive undo for better performance and less memory usage
    global_undo = context.user_preferences.edit.use_global_undo
    context.user_preferences.edit.use_global_undo = False

    xml = parse(filepath)

    root = xml.documentElement

    # quit edit mode if enabled and deselect all objects
    editMode(context.scene, False)
    deselectObjects(context.scene)

    osm = OSM(root)
    if profiler:
        import profile
        import time
        profile.runctx('osm.generate(False)', {
            'debug': debug,
            'debugger': debugger,
            'log': log
        }, {'osm': osm},
                       'profile_results_' + time.strftime("%y-%m-%d-%H-%M-%S"))
    else:
        osm.generate(False)

    # everything went fine, so store filename
    bpy.context.scene.osm.file = filepath

    xml.unlink()

    if operator.create_tag_list:
        tag_list = ''
        tags = {}

        # get tags in nodes
        for id in osm.nodes:
            node = osm.nodes[id]
            for tag in node.tags:
                v = 'NODE:\t' + tag + ' = ' + node.tags[tag].value
                if v not in tags:
                    tags[v] = 1
                else:
                    tags[v] += 1

        # get tags in ways
        for id in osm.ways['by_id']:
            way = osm.ways['by_id'][id]
            for tag in way.tags:
                v = 'WAY:\t' + tag + ' = ' + way.tags[tag].value
                if v not in tags:
                    tags[v] = 1
                else:
                    tags[v] += 1

        for tag in OrderedDict(
                sorted(tags.items(), key=lambda t: t[1], reverse=True)):
            tag_list += "%s (%dx)\n" % (tag, tags[tag])

        if "tags.txt" not in bpy.data.texts:
            bpy.data.texts.new('tags.txt')
        bpy.data.texts['tags.txt'].from_string(tag_list)

    # reset undo preference
    context.user_preferences.edit.use_global_undo = global_undo
示例#4
0
def load_osm(filepath, operator, context):
    from io_osm.osm_types import OSM
    if debug:
        debugger.start(log)
    if debug:
        debugger.debug("OSM import started: %r..." % filepath)
        debugger.debug("parsing xml to dom ...")

    # deactive undo for better performance and less memory usage
    global_undo = context.user_preferences.edit.use_global_undo
    context.user_preferences.edit.use_global_undo = False

    xml = parse(filepath)

    root = xml.documentElement

    # quit edit mode if enabled and deselect all objects
    editMode(context.scene,False)
    deselectObjects(context.scene)
    
    osm = OSM(root)
    if profiler:
        import profile
        import time
        profile.runctx('osm.generate(False)',{'debug':debug,'debugger':debugger,'log':log},{'osm':osm},'profile_results_'+time.strftime("%y-%m-%d-%H-%M-%S"))
    else:
        osm.generate(False)

    # everything went fine, so store filename
    bpy.context.scene.osm.file = filepath

    xml.unlink()

    if operator.create_tag_list:
        tag_list = ''
        tags = {}

        # get tags in nodes
        for id in osm.nodes:
            node = osm.nodes[id]
            for tag in node.tags:
                v = 'NODE:\t'+tag+' = '+node.tags[tag].value
                if v not in tags:
                    tags[v] = 1
                else:
                    tags[v]+=1

        # get tags in ways
        for id in osm.ways['by_id']:
            way = osm.ways['by_id'][id]
            for tag in way.tags:
                v = 'WAY:\t'+tag+' = '+way.tags[tag].value
                if v not in tags:
                    tags[v] = 1
                else:
                    tags[v]+=1

        for tag in OrderedDict(sorted(tags.items(),key=lambda t: t[1], reverse=True)):
            tag_list+="%s (%dx)\n" % (tag,tags[tag])
                    

        if "tags.txt" not in bpy.data.texts:
            bpy.data.texts.new('tags.txt')
        bpy.data.texts['tags.txt'].from_string(tag_list)

    # reset undo preference
    context.user_preferences.edit.use_global_undo = global_undo