[Gvsig_english] 3D vector layers
Antonio Falciano
antonio.falciano at gmail.com
Thu Oct 20 10:30:35 CEST 2016
Il 18/10/2016 18:13, Óscar Martínez ha scritto:
> Hi Silvia,
>
> Sorry with our last emails I forgot this one.
>
> So this two quick scripts:
>
> - a 2D point layer with a column of z of which I would create a 3D point
> layer
[...]
> - a 2D line layer with a column containing the elevation of each corner
> of the line which I would create a 3D line layer.
> (*This script will be useful for lines and for polygons*, becouse their
> geometry works in the same way)
[...]
Hi all,
alternatively, as stated in my first post, it's possible to use only one
script for all types of geometries (and eventually for other layer
formats different from ESRI Shapefile) using ogr2ogr:
# encoding: utf-8
from gvsig import *
import os
from gvsig import uselib
uselib.use_plugin("org.gvsig.gdal.app.mainplugin")
from org.gvsig.gdal.app.mainplugin.common import ogr2ogr
def main(*args):
layer = currentLayer()
zfield = "ID"
if layer != None:
# get the input layer path (2D)
datastore = layer.getDataStore()
inLayerPath = datastore.getFullName()
# get the output layer path (3D)
dirname = os.path.dirname(inLayerPath)
filename = os.path.basename(inLayerPath).split(".")[0]
# for instance, we use the same file extension of the input layer
# but it could be another OGR format (e.g. SpatiaLite)
extension = os.path.basename(inLayerPath).split(".")[1]
outLayerPath = os.path.join(dirname, filename + "_3D." + extension)
if extension.lower() == "shp":
format = "ESRI Shapefile"
#elif extension.lower() == "..."
# format = "..."
else:
print "Not implemented yet!"
ogr2ogr.main(["-f", format,
outLayerPath,
inLayerPath,
"-zfield", zfield,
"-overwrite"
])
loadShapeFile(outLayerPath)
Cheers,
Antonio
--
Antonio Falciano
http://www.linkedin.com/in/antoniofalciano
More information about the Gvsig_internacional
mailing list