gvSIG feature requests #4164
Scripting: createShape without filename
Status: | Closed | % Done: | 0% | |
---|---|---|---|---|
Priority: | Normal | Spent time: | - | |
Assignee: | ||||
Category: | - | |||
Target version: | 2.3.0-2429 (rev. org.gvsig.desktop-2.0.135, NOT USABLE) | |||
gvSIG version: | 2.3.0 | Add-on resolve version: | ||
Keywords: | Add-on resolve build: | |||
Has patch: | Proyecto: | |||
Add-on name: | Unknown | Hito: | ||
Add-on version: |
Description
Función para crear capas sin precisar nombre, solo el esquema.
La función createShape llama a getTempFile si no se le aporta filename.
Si no se aporta nombre a la capa se crea un path localizado en tmp-andami/gvscripting
Añadir a utils la función getTempFile(name, ext)
Añadida función para asegurarnos que la capa es única.
Joaquin, dejo de tu parte ver si acceder a tmp-andami así sería correcto, o si haría falta crear una dentro de esa /gvscripting/
Dejo ahí el trozo de código de la posible solución
Todo en el fichero /gvsig2_3_0/utils.py
import tempfile import os import time def getTempFile(name, ext): gvtempdir = os.path.join(tempfile.gettempdir(),"tmp-andami") tempdir = os.path.join(gvtempdir,"gvscripting") if not os.path.isdir(tempdir): os.makedirs(tempdir) n = 0 while True: f = os.path.join(tempdir,"%s-%x%s%s" % (name,time.time(),n,ext)) if os.path.exists(f): n +=1 else: return f def createShape(definition, filename=None, geometryType=None, CRS="CRS:84"): """ Return new shape layer :param definition: layer data definition :type definition: Schema :param filename: absolute path for shape files. :type filename: string :param geometryType: geometry type for shape :type geometryType: string :return: new shape layer :rtype: Layer """ geomattr = definition.getDefaultGeometryAttribute() if filename == None: filename = getTempFile("gvtmp", ".shp") if geomattr == None: raise RuntimeException("Can't create a shp without geometry attribute") if geometryType == None : geometryType = geomattr.getGeomType().getType() else: if geometryType != geomattr.getGeomType().getType(): raise RuntimeException("Can't create a shp, geoemtry mismatch.") return createLayer( definition, "FilesystemExplorer", "Shape", shpFile=filename, CRS=CRS, geometryType = geometryType )
Associated revisions
refs #4164, modificada la funcion createshape para que el nombre del shape sea opcional y cree uno temporal en caso de que no se le indique.
History
#1
Updated by Joaquín del Cerro Murciano over 8 years ago
- Target version set to 2.3.0-2447-final (rev. org.gvsig.desktop-2.0.153)
#2
Updated by Joaquín del Cerro Murciano over 8 years ago
- Target version changed from 2.3.0-2447-final (rev. org.gvsig.desktop-2.0.153) to 2.3.0-2429 (rev. org.gvsig.desktop-2.0.135, NOT USABLE)
- Assignee set to Joaquín del Cerro Murciano
- Status changed from New to Fixed
#3
Updated by Álvaro Anguix about 8 years ago
- Status changed from Fixed to Closed