Beispiel #1
0
def buildReducedTreeFromLayers(root, layers):
  folders = dict()
  for path,layer in layers:
    dirname = os.path.dirname(path)
    leafs = folders.get(dirname,None)
    if leafs == None:
      leafs=list()
      folders[dirname] = leafs
    leafs.append((path,layer))
  paths = folders.keys()
  paths.sort()

  for path in paths:
    # select icon and insert in tree
    folderPath = folders[path]
    if not os.path.isdir(path):
        properIcon = getIconByPath(gvsig.getResource(__file__,"images","Database.png"))
        if path=="":
            i18n = ToolsLocator.getI18nManager()
            path=i18n.getTranslation("_Services")
        folder = DefaultMutableTreeNode(DataGroup(path,path,properIcon))
    else:
        properIcon = getIconByName("librarybrowser-folder")
        folder = DefaultMutableTreeNode(DataGroup(path,path,properIcon))
    
    root.insert(folder, root.getChildCount())
    for pathLayer,layer in folderPath:
      leaf = DefaultMutableTreeNode(DataLayer(pathLayer,layer))
      folder.insert(leaf, folder.getChildCount())
Beispiel #2
0
def createTreeModel(mapContext, reducedTree=True):
  i18n = ToolsLocator.getI18nManager()
  root = DefaultMutableTreeNode(i18n.getTranslation("_Root"))
  localLayers = DefaultMutableTreeNode(DataFolder(i18n.getTranslation("_Local_layers"),None))
  remoteLayers = DefaultMutableTreeNode(DataFolder(i18n.getTranslation("_Remote_layers"),None))
  root.insert(localLayers, root.getChildCount())
  root.insert(remoteLayers, root.getChildCount())
  layers = list()
  remotes = list()

  for layer in iter(mapContext.deepiterator()):
    getDataStore = getattr(layer,"getDataStore",None)
    if getDataStore == None:
      continue
    if getDataStore() == None:
        # asumimos que es raster
        uri = layer.getURI()
        if uri != None:
            layers.append((uri.getPath(),layer))
        else:
            remotes.append((layer.getName(), layer))
        continue
    
    params = getDataStore().getParameters()
    getFile = getattr(params, "getFile", None)
    if getFile != None and getFile() !=None:
      getTable = getattr(params, "getTable", None)
      if  getTable != None and getTable() !=None:
        layers.append((os.path.join(getFile().getAbsolutePath(),getTable()),layer))
      else:
        layers.append((getFile().getAbsolutePath(),layer))
    else:
      remotes.append((layer.getName(), layer))
  layers.sort(cmp = lambda x,y: cmp(x[0],y[0]))

  if reducedTree:
    buildReducedTreeFromLayers(localLayers,layers)
    buildReducedTreeFromLayers(remoteLayers,remotes)
  else:
    for path,layer in layers:
      buildTreeFromPath(localLayers,path,layer)
    
  model = DefaultTreeModel(root)
  return model
Beispiel #3
0
def createTreeModel(mapContext, reducedTree=True):
    i18n = ToolsLocator.getI18nManager()

    root = DefaultMutableTreeNode(i18n.getTranslation("_Selection"))

    rootSelected = DefaultMutableTreeNode(
        DataGroup(i18n.getTranslation("_Selected")))
    rootSelectable = DefaultMutableTreeNode(
        DataGroup(i18n.getTranslation("_Selectable")))
    rootNotSelectable = DefaultMutableTreeNode(
        DataGroup(i18n.getTranslation("_Not_selectable")))

    root.insert(rootSelected, root.getChildCount())
    root.insert(rootSelectable, root.getChildCount())
    root.insert(rootNotSelectable, root.getChildCount())

    for layer in iter(mapContext.deepiterator()):
        if not isinstance(layer, SingleLayer):
            continue
        store = layer.getDataStore()
        if isinstance(
                store,
                DefaultFeatureStore) and store.getSelection().getSize() != 0:
            newNode = DefaultMutableTreeNode(DataLayer(layer.getName(), layer))

            fset = layer.getDataStore().getSelection()
            for f in fset:
                newFeature = DefaultMutableTreeNode(
                    FeatureDataLayerNode(layer.getName(), layer, f))
                newNode.insert(newFeature, newNode.getChildCount())
            rootSelected.insert(newNode, 0)
        elif isinstance(store, DefaultFeatureStore):
            newNode = DefaultMutableTreeNode(DataLayer(layer.getName(), layer))
            rootSelectable.insert(newNode, 0)
        else:
            newNode = DefaultMutableTreeNode(DataLayer(layer.getName(), layer))
            rootNotSelectable.insert(newNode, 0)

    model = DefaultTreeModel(root)
    return model
def createTreeModel(mapContext, reducedTree=True):
    i18n = ToolsLocator.getI18nManager()
    root = DefaultMutableTreeNode(i18n.getTranslation("_Visibility"))

    rootWithVisibility = DefaultMutableTreeNode(
        DataGroup(i18n.getTranslation("_Visible")))
    rootWithoutVisibility = DefaultMutableTreeNode(
        DataGroup(i18n.getTranslation("_Out_of_Scale_Range")))
    rootNotVisibility = DefaultMutableTreeNode(
        DataGroup(i18n.getTranslation("_Not_Visible")))

    root.insert(rootWithVisibility, root.getChildCount())
    root.insert(rootWithoutVisibility, root.getChildCount())
    root.insert(rootNotVisibility, root.getChildCount())

    for layer in iter(mapContext.deepiterator()):
        if not isinstance(layer, SingleLayer):
            continue
        try:
            envelope = layer.getFullEnvelope()
            insideViewportEnvelope = mapContext.getViewPort().getEnvelope(
            ).intersects(envelope)
        except:
            insideViewportEnvelope = True

        if layer.isWithinScale(mapContext.getScaleView()) and layer.isVisible(
        ) and insideViewportEnvelope:
            newNode = DefaultMutableTreeNode(DataLayer(layer.getName(), layer))
            rootWithVisibility.insert(newNode, 0)

        elif not layer.isWithinScale(
                mapContext.getScaleView()) and layer.isVisible():
            newNode = DefaultMutableTreeNode(DataLayer(layer.getName(), layer))
            rootWithoutVisibility.insert(newNode, 0)

        else:  # layer.isVisible()==False:
            newNode = DefaultMutableTreeNode(DataLayer(layer.getName(), layer))
            rootNotVisibility.insert(newNode, 0)

    model = DefaultTreeModel(root)
    return model