// The lines with # are to run on grass command console, the others are for python console

# v.in.ogr input='G:\Jessica\TCC\SIG\bando de dados\Tabelas\boreholes.shp' layer=boreholes output=boreholes

import sys, os, numpy, argparse
import grass.script as g
import grass.script.setup as gsetup

g.run_command('v.buffer', input='boreholes', output='boreholesGrassBuffer', type='point', distance='0.01')
# d.vect map=boreholesGrassBuffer@Map2

gisbase = os.environ['GISBASE']
gisdb='C:\Users\Vulcan\Documents\grassdata'  // change this for your database path
location='SantaCatarina'                     // set this to your location
mapset='Map2'								 // set this to your mapset
gsetup.init(gisbase, gisdb, location, mapset)
mapWithAttrTable = "boreholes@Map2"
mapWithBuffer = "boreholesGrassBuffer@Map2"
tableAsString = g.read_command('v.db.select', map = mapWithAttrTable, columns = "COTA,PROF_,COTA_TOPO,COTA_BASE,PROF_BASE,ESP_BASE", flags = 'c')

boreholes=tableAsString.split('\n')
boreholes=[i.split(',') for i in boreholes]

boreholesList = []

for item in boreholes:
    boreholesList.append(item[0].split('|'))

del boreholesList[-1]

for i in range(len(boreholesList)):
    name = "bore"+str(i)
    g.run_command('v.extract',input=mapWithBuffer, list=i+1, output='tmp',type='area', quiet=True, overwrite=True)
    g.run_command('v.extrude', input='tmp', output=name, zshift=float(boreholesList[i][2]),height= float(boreholesList[i][5]),overwrite=True)
    g.run_command('g.remove', type='vector', name='tmp', flags = 'f')
    g.run_command('d.vect', map=name+'@Map2')
