VECAddField and VECCreateLayer

Demonstrate how to create a new vector layer and how to add new fields.

Code

 local int segment_num 
 local int tfid, int i
 local int count
 local string fieldname
 local string fieldtype
 local string fieldformat 
 local string temp_file

 try

    temp_file = "./my.pix"
    delete temp_file noerror
    call CopyFile( GetPCIHOME() + "/demo/irvine.pix", \
                 temp_file)

    tfid = DBOpen(temp_file, "r+")

    segment_num =VECCreateLayer(tfid, "My New VectorLayer", "My description")

    print "Layer: ", segment_num, VECGetLayerName(tfid, segment_num), \
       VECGetLayerDesc(tfid, segment_num)

    call VECAddField(tfid, segment_num, "Name", "String", "%32s")
    call VECAddField(tfid, segment_num, "ID", "Integer")

    count = VECGetFieldCount(tfid, segment_num)
    for i = 1 to count
        fieldname =   VECGetFieldName(tfid, segment_num, i)
        fieldtype =   VECGetFieldType(tfid, segment_num, i)
        fieldformat = VECGetFieldFormat(tfid, segment_num, i)


        print "Field ", fieldname, "Type :", fieldtype, \
                   " Format: ", fieldformat
    endfor

    call DBClose(tfid)
 onerror
   print "Error: "+ GetLastErrorMessage()
 endonerror

Output

Creating segment: 29  [ 116: @Vector:Vector        ]        2 Blocks long
Layer: 29My New VectorLayerMy description
Field NameType :String Format: %32s
Field IDType :Integer Format: %d

© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.