[HOME][CONTENTS][DOWNLOAD][PREV][NEXT]


SHAPE DATA PROCESSING

In addition to gcanvas, XBit provides map objects to create and edit maps.  An XBit map object is an encapsulation of code and data with both C and Tcl API.  A map object can receive data from either scripts or files.  Two types of map objects are implemented.  The first is a shape object that is used to process graphic components of a map.  Currently, a shape object can read data from and write data to a shape (.shp) file.  The second is a gtable object that is used to process additional attributes of a map.  Currently, a gtable object can read data from and write data to a table (.dbf) file.  Map projection can be done using projection objects implemented with the integration of the PROJ package.

Create A Shape Object.  A shape object is created using Tcl command 

shape.create shapeObject ?options?
where shapeObject is a new Tcl command to identify and interface to an instantiated shape object via Tcl scripts. Options for creating a shape object include -file and -update.  Option -file specifies a shape (.shp) file to initialize the shape object.  Option -update can be configured to either 0 or 1.  When a client opens a shape object via its C API, it can add a call back function for the updating event.  When option -update is set to 1, a shape object will invoke call back functions of its clients whenever its contents have been changed. 

Edit A Shape Object.  The first thing to do to edit a new shape object is to create a shape object with a proper shape type.  It can be done by specifying an existing shape file for the option -file or by initializing a shape object using the command

shapeObject initialize shapeID
where shapeID speicifies an interested shape type.  The supported shape types are POINT, POLYLINE, POLYGON, MULTIPOINT, POINTZ, POLYLINEZ, POLYGONZ, MULTIPOINTZ, POINTM, POLYLINEM, POLYGONM, MULTIPOINTM and MULTIPATCH.  The command shapeObject intialize shapeID will erase all records of the current shape object and makes an empty shape object of the specified shape type.

To add or insert a shape record, use the following two commands

shapeObject add verticeList ?partList? ?mvalueList? ?zvalueList? ?typeList?
shapeObject insert index verticeList ?partList? ?mvalueList? ?zvalueList? ?typeList?
where index is the position to insert the record, verticesList is a list of x and y coordinates; partList is a list of integers to specify the number of vertices in each part sequencially partitioned in verticesList; mvalueList is a list of values to specify the measurement of each part; zvalueList is a list of values to specify the z value of each vertice; typeList is a list of integers to specify the type of patch of each part for a MULTIPATCH shape object.

To delete a shape record, use the following two commands

shapeObject deleteshape ?index? ...
shapeObject purge
The command shapeObject deleteshape ?index?... marks specified record as deleted status, but it does not physically erase them.  A shape record of deleted status will not participate shape record selection and will not be displayed in a gcanvas.  The command shapeObject purge will physically erase the deleted records. To undelete a shaped record and change it back to a selected record, use the following command
shapeObject undeleteshape ?index?...
To save a shape object to a disk file, use the following command
shapeObject save fileName [selected]
where selected is a flag to save only the selected records if set to 1.  If selected is 0 or not provided, all records will be saved to the output shape file.

To retrieve vertex coordinates of a shape object record, use the following command

set vertexLists  [shapObject vertex index ?index?...]
The returned vertexLists is a list of items.  Each item is a list of coordinates of a specified shape object record.

To retrieve multi-component definitions of vertices, use the following command

set partLists [shapeObject part index ?index?...]
The returned partLists is a list of items.  Each item is a list of integers to define vertices of a multi-part shape record.

To retrieve vertex along with part definition, use the following command

set vpartLists [shapeObject vpart index ?index?...]
The returned vpartLists is a list of items.  Each item is a list of vertices plus a list of part definition and can be directly used by a gcanvas widget to create a proper canvas item.

Disassemble A Shape Object.  To access to individual records of a shape object, it may be convinient to convert a shape object into canvas items.  A user can use any existng canvas tools to edit individual shape records after disassembling them into canvas's items.  There are two methods to disassemble a shape object into canvas items. 

The first method is to retrieve vertices of each shape record and to create a proper canvas item using the retrieval vertices.  This method works but is not efficient.  The following scripts show how to use the first method:

set total [shapeObject count]
for {set i 0} {$i < $total} {incr i} {
    set vpartList [shapeObject vpart $i]
    set coords [lindex $vpartList 0]
    eval gcanvasWidget create polygon $coords
}
It is assumed that the shapeObject is of POLYGON type.

The second method is to create an object item of gcanvas using the shape object and then to invoke the gcanvas disassemble command.  The following scripts show the second method:

set id [gcanvaWidget createobject 0 0 -object shapeObject]
gcanvasWidget disassemble id
Assemble A Shape Object.  To create a shape object with items of a gcanvas widget, invoke the gcanvas assemble command. 
gcanvasWidget assemble shapeObject typeindex ?index?...
where shapeObject is a shape object, type is the type of shape object to assemble, index is the item's index or tag.  The following scripts show how to assemble gcanvas items into three different shape objects:
shape.create pointObject
shape.create lineObject
shape.create polygonObject
gcanvasWidget assemble pointObject POINT all
gcanvasWidget assemble lineObject POLYLINE all
gcanvasWidget assemble polygonObject POLYGON all
Projection Transformation.  To describe/define the map projection of a shape object, use the following command:
shapeObject projdef projection_definition
where projection_definition is a string for a map projection definition.  For longitude and latitude coordinate systems,  a valid projection_definition string is either longlat or latlong for {longitude, latitude} and {latitude, longitude} coordinates respectively.  For other map projections, a valid projection_definition may be the same as the argument string used by the command proj of the popular PROJ package.  For example, the following script defines a UTM projection:
shapeObject projdef "+proj=utm +zone=10"
To make a map projection of a shape object, use the following command
shapeObject projection projection_definition
To make a reversed map projection, i.e., to convert the coordinates of a shape object from a specific map projection back to longitude and latitude, use the following command
shapeObject projection reverse
Component Selection.  To select components or records of a shape object, use the following command:
shapeObject select index ?index?...
To select specified shape components or records and unselect others, use the following command:
shapeObject selectonly index ?index?...
To select components or records of a shape object with its tabular attributes, use the following command:
shapeObject match tableObject
It is an efficient way for selecting shape object components.

[HOME][CONTENTS][DOWNLOAD]


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

1