123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #!/usr/bin/env python
- ############################################################################
- #
- # MODULE: v.to.3d
- #
- # AUTHOR: Martin Landa, CTU in Prague, Czech Republic
- #
- # PURPOSE: Transform 2D vectors to 3D vectors
- # (frontend to v.transform)
- #
- # COPYRIGHT: (c) 2008 Martin Landa, and the GRASS Development Team
- # This program is free software under the GNU General Public
- # License (>=v2). Read the file COPYING that comes with GRASS
- # for details.
- #
- #############################################################################
- #%Module
- #% description: Performs transformation of 2D vector features to 3D.
- #% keywords: vector, transformation, 3D
- #%End
- #%Option
- #% key: input
- #% type: string
- #% required: yes
- #% multiple: no
- #% key_desc: name
- #% description: Name of input vector map
- #% gisprompt: old,vector,vector
- #%End
- #%Option
- #% key: output
- #% type: string
- #% required: yes
- #% multiple: no
- #% key_desc: name
- #% description: Name for output vector map
- #% gisprompt: new,vector,vector
- #%End
- #%Option
- #% key: height
- #% type: double
- #% required: no
- #% multiple: no
- #% description: Fixed height for 3D vector features
- #%End
- #%Option
- #% key: layer
- #% type: integer
- #% required: no
- #% multiple: no
- #% label: Layer number
- #% description: A single vector map can be connected to multiple database tables. This number determines which table to use.
- #% answer: 1
- #% gisprompt: old_layer,layer,layer
- #%End
- #%Option
- #% key: column
- #% type: string
- #% required: no
- #% multiple: no
- #% key_desc: name
- #% description: Name of attribute column used for height
- #% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
- #%End
- import sys
- import os
- import grass
- def main():
- input = options['input']
- output = options['output']
- layer = options['layer']
- column = options['column']
- height = options['height']
-
- map3d = int(grass.parse_key_val(grass.read_command('v.info', map = input, flags = 't'))['map3d'])
-
- if map3d == 1:
- grass.fatal("Vector map <%s> is 3D" % input)
-
- if height:
- if column:
- grass.fatal("Either 'height' or 'column' parameter have to be used")
- # fixed height
- grass.run_command('v.transform', input = input, output = output,
- zshift = height)
- else:
- if not column:
- grass.fatal("Either 'height' or 'column' parameter have to be used")
- # attribute height, check column type
- try:
- coltype = grass.vector_columns(map = input, layer = layer)[column]
- except KeyError:
- grass.fatal("Column <%s> not found" % column)
-
- if coltype not in ('INTEGER',
- 'DOUBLE PRECISION'):
- grass.fatal("Column type must be numeric")
-
- f = grass.vector_layer_db(map = input, layer = layer)
- table = f['table']
-
- columns = "zshift:%s" % column
- grass.run_command('v.transform', input = input, output = output,
- layer = layer, columns = columns,
- table = table)
- grass.vector_history(map = output)
- return 0
-
- if __name__ == "__main__":
- options, flags = grass.parser()
- sys.exit(main())
|