[Gvsig_english] 3D vector layers

Óscar Martínez omartinez at gvsig.com
Tue Oct 18 18:13:32 CEST 2016


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

# encoding: utf-8

import gvsig
from gvsig import geom

def main(*args):

     layer = gvsig.currentLayer()
     features = layer.features()

     #Create schema based on a existing schema
     sch = gvsig.createFeatureType(layer.getSchema())
     #We modified the geometry field of that schema for the geometry type that we want
     sch.getDefaultGeometryAttribute().setGeometryType(geom.POINT, geom.D3)

     #new shape
     shp = gvsig.createShape(sch, prefixname="points3d")
     
     for feature in features:

         g = feature.geometry()
         #print g.getX(), g.getY(), feature.get("z")
         
         z = float(feature.get("z")) # z field convert to a float number (in my case was a string field)
         point3d = geom.createPoint(geom.D3, g.getX(), g.getY(), z)

         values = feature.getValues()
         values["GEOMETRY"] = point3d
         
         shp.append(values)

     shp.commit()
     gvsig.currentView().addLayer(shp)

- 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)

# encoding: utf-8

import gvsig

from gvsig import geom

def main(*args):

     layer = gvsig.currentLayer()

     features = layer.features()

     #Create schema based on a existing schema

     sch = gvsig.createFeatureType(layer.getSchema())

     #We modified the geometry field of that schema for the geometry type that we want

     sch.getDefaultGeometryAttribute().setGeometryType(geom.CURVE, geom.D3)

     #new shape

     shp = gvsig.createShape(sch, prefixname="linepol3d")

     

     for feature in features:

         z = float(feature.get("z")) # z field convert to a float number

         g = feature.geometry()

         # we will create a python list with all the vertexes

         linevertexes = []

         # access to the vertexes of the geometry (line or pol is the same way)

         for vertex in g:

             p1 = geom.createPoint(geom.D3, vertex.getX(), vertex.getY(), z)

             linevertexes.append(p1)

         # create 3dline with this vertexes

         line3d = geom.createLine(geom.D3, linevertexes)

         print line3d

         

         values = feature.getValues()

         values["GEOMETRY"] = line3d

         

         shp.append(values)

     shp.commit()

     gvsig.currentView().addLayer(shp)



Best regards,
Óscar

El 12/10/16 a las 14:44, Silvia Franceschi escribió:
> Dear all,
> sorry for asking here, but I can not find any information about the 
> possibility to handle 3D vector layers (as shapefiles) in gvSIG.
> Is it possible to create/modify a 3D vector layer (point, line) in gvSIG?
>
> I have two types of data to modify:
> - 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.
>
> Any idea on how I can do?
>
> Thanks,
>
> Silvia
>
> -- 
> ing. Silvia Franceschi
> Via Latemar, 22
> 38030 Castello di Fiemme (TN)
>
> tel: 0039 -3384501332
>
>
> _______________________________________________
> Gvsig_internacional mailing list
> Gvsig_internacional at listserv.gva.es
>
> To see the archives, edit your preferences or unsubscribe from this mailing list, please access this url:
>
> https://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.gva.es/pipermail/gvsig_internacional/attachments/20161018/b7f42a61/attachment.html>


More information about the Gvsig_internacional mailing list