Cargando capas

loadShapeFile(shpFile, **parameters):

Add an existing shape file to the view. Returns Layer shape file

Parámetros:
  • shpFile – absolute file path to the shape
  • CRS (string) – projection code
  • gvViewName (string) – name of the view where to be loaded
  • gvLayerName (string) – name of the layer inside gvsig
Type:

shpFile: string

Devuelve:

shape

loadRasterFile(filename, **parameters):

Add an existing raster file to the view. Returns Layer Raster file.

param str filename:
 absolute file path to the raster
Parámetros:
  • CRS (string) – projection code
  • gvViewName (string) – name of the view where to be loaded
  • gvLayerName (string) – name of the layer inside gvsig
Devuelve:

raster layer

Recursos en rutas relativas

En nuestros scripts siempre tenemos acceso al un objeto denominada script de tipo DefaultScriptingScript. Esta clase hace referencia a la ejecución del propio script y no tiene que ser importada.

Una de las funciones que contiene nos será muy útil cuando tengamos extensiones con datos a los que tener acceso. Nos va a permitir acceder a datos contenidos en la carpeta de ejecución del script de forma relativa.

Siendo que si tenemos una carpeta denominada /datos/ al mismo nivel que nuestro script, podremos acceder a los datos de ella mediante script.getResource("datos/capa.shp") por ejemplo. Tener en cuenta que esta función devuelve un objeto Java del tipo java.io.File. Para sacar su ruta en formato string usaremos getPath() o para sacar su uri usaremos .toURI()

Ejemplo de uso:

from gvsig import *

def main(*args):

        file_raster = script.getResource("/data/mdt_jaen.tif") #return java.io.File
        path_raster = file_raster.getPath()

Capas Vectoriales

Para cargar capas vectoriales usaremos la función :py:func:loadShapeFile(). Esta es una función de apoyo que llama a la función createLayer() más genérica.

Ejemplo:

from gvsig import *
from java.io import File

def main(*args):

        # Get resource path
        xfile = script.getResource("/data/jaen.shp")
        shape_path = xfile.getPath()

        # loadShapeFile function
        s1 = loadShapeFile(shape_path)

        # LoadLayer function
        s2 = loadLayer("Shape", shpFile=xfile, CRS="EPSG:25830")

Capas Raster

Para cargar capas raster usaremos la función :py:func:loadRasterFile(). Esta es una función de apoyo que llama a la función createLayer() más genérica.

Ejemplo:

from gvsig import *

def main(*args):

        # Load Raster File
        raster_path = script.getResource("/data/mdt_jaen.tif").getPath()
        r1 = loadRasterFile(raster_path)

        raster_uri = script.getResource("/data/mdt_jaen.tif").toURI()
        r2 = loadLayer("Gdal Store", uri=raster_uri)

Si necesitamos transformar una ruta a formato uri podemos hacerlo apoyándonos en la clase de Java: java.io.File:

from gvsig import *
from java.io import File

def main(*args):

        # Load Raster File
        raster_path = script.getResource("/data/mdt_jaen.tif").getPath()

        # Path to URI
        uri = File(raster_path).toURI()