ACON
Home/Topics |
Commands
ShapeFile Functions
These ShapeFile functions are based on the ShapeLib library available at
shapelib.maptools.org. These bindings
presented here are similar to, but not identical to the original C library.
The ShapeFile functions include:
Shp_Dbf_Create,
DBF_Create,
DBF_Open,
DBF_Close,
DBF_Read_String_Attribute,
DBF_Get_Field_Info,
DBF_Get_Field_Count,
DBF_Get_Record_Count,
DBF_Write_Integer_Attribute,
DBF_Write_Double_Attribute,
DBF_Write_String_Attribute,
DBF_Add_Field,
SHP_Create,
SHP_Open,
SHP_Close,
SHP_Create_Object,
SHP_Destroy_Object,
SHP_Create_Simple_Object,
SHP_Write_Object,
SHP_Read_Object, and
SHP_Get_Info.
This command creates a Point Shapefile and matching DBF attribute file.
- There are 4 parameters:
- ShapefileName - name of the shapefile to create.
- lonVector - a vector containing the longitude values.
- latVector - a vector containing the latitude values.
- attributenameMatrix - a character matrix providing the names of the attributes
associated with each data point.
SHP_DBF_Create(shapefilename,lonVector,latVector,attributenameMatrix);
lon = -66.5 -65 -64.;
lat = 44 44.3 46;
catch = 10 20 30.;
species = strfold(";Cod Cod Haddock";);
attributes = strfold(";Catch species";);
// Create a shape file with 3 data points, and 2 attributes per point
SHP_DBF_Create("C:/myShapeFile",lon,lat,attributes);
This command creates a DBF attribute file (commonly used as the dual to a shapefile).
- There is 1 parameter:
- dfbfilename - name of the dbf file to create.
A handle to the open file is returned.
DBFHandle = DBF_Create(dbffilename);
dbfhdl = DBF_Create("C:/myDBFfile");
This command opens an existing DBF attribute file (commonly used as the dual to a shapefile).
A handle to the open file is returned.
- There are 2 parameter:
- dfbfilename - name of the dbf file to open.
- accessflag - type of access; "rb" (read-only binary) and "rb+" (read/write binary).
DBFHandle = DBF_Open(dbffilename,accessflag);
dbfhdl = DBF_Open("C:/myDBFfile","rb");
This command closes a DBF attribute file (commonly used as the dual to a shapefile).
- There is 1 parameter:
- dfbhandle - The DBF handle of the dbf file to close.
DBF_Close(dbfhandle);
DBF_Close(dbfhdl);
This command closes a DBF attribute file (commonly used as the dual to a shapefile).
- There are 3 parameters:
- dfbhandle - The DBF handle of the dbf file to use.
- shapenumber - The record number from which the field is read.
- fieldnumber - The field number of the field to read.
textstring = DBF_Read_String_Attribute(dbfhandle,shapenumber,fieldnumber);
a = DBF_Read_String_Attribute(dbfhandle,0,0); // read the 1st field from the 1st row
This command returns information about a field in a DBF attribute file (commonly used as the dual to a shapefile).
An enclosed vector is returned containing 3 elements: the name of the field, the width of the field,
and the number of decimal places for a non-integer numeric field.
- There are 2 parameters:
- dfbhandle - The DBF handle of the dbf file to use.
- fieldnumber - The field number of the field to read.
enclosedvector = DBF_Get_Field_Info(dbfhandle,fieldnumber);
enclosedvector = DBF_Get_Field_Info(dbfhandle,0); // read the 1st field information
print(enclosedvector[1]);
TEST
print(enclosedvector[2]);
10
print(enclosedvector[3]);
0
This command returns the number of fields in a DBF attribute file (commonly used as the dual to a shapefile).
- There is 1 parameter:
- dfbhandle - The DBF handle of the dbf file to use.
nfields = DBF_Get_Field_Count(dbfhandle);
nfields = DBF_Get_Field_Count(dbfhandle); // read the number of fields
This command returns the number of records in a DBF attribute file (commonly used as the dual to a shapefile).
- There is 1 parameter:
- dfbhandle - The DBF handle of the dbf file to use.
nrecords = DBF_Get_Record_Count(dbfhandle);
nrecords = DBF_Get_Record_Count(dbfhandle); // read the number of records
This command writes an integer to a DBF attribute file (commonly used as the dual to a shapefile).
- There are 4 parameters:
- dfbhandle - The DBF handle of the dbf file to use.
- shapenumber - The record number to which the field is written.
- fieldnumber - The field number of the field to write.
- value - The integer value to write.
result = DBF_Write_Integer_Attribute(dbfhandle,shapenumber,fieldnumber,value);
result = DBF_Write_Integer_Attribute(dbfhandle,0,0,621); // write the value 621 as the 1st attribute in the 1st row
This command writes an floating point value (double) to a DBF attribute file (commonly used as the dual to a shapefile).
- There are 4 parameters:
- dfbhandle - The DBF handle of the dbf file to use.
- shapenumber - The record number to which the field is written.
- fieldnumber - The field number of the field to write.
- value - The value to write.
result = DBF_Write_Double_Attribute(dbfhandle,shapenumber,fieldnumber,value);
result = DBF_Write_Double_Attribute(dbfhandle,0,0,3.1415); // write the value 3.1415 as the 1st attribute in the 1st row
This command writes an string value to a DBF attribute file (commonly used as the dual to a shapefile).
- There are 4 parameters:
- dfbhandle - The DBF handle of the dbf file to use.
- shapenumber - The record number to which the field is written.
- fieldnumber - The field number of the field to write.
- value - The value to write.
result = DBF_Write_String_Attribute(dbfhandle,shapenumber,fieldnumber,value);
result = DBF_Write_String_Attribute(dbfhandle,0,0,"TEST"); // write "TEST" as the 1st attribute in the 1st row
This command creates a SHP file.
- There are 2 parameters:
- shpfilename - name of the shp file to create.
- shptype - type shp file to create: 1 = point, 3 = arc, 5 = polygon, 8 = multipoint.
A handle to the open file is returned.
SHPHandle = SHP_Create(shpfilename,shptype);
shphdl = SHP_Create("C:/mySHPfile",1);
This command opens an existing SHP attribute file.
A handle to the open file is returned.
- There are 2 parameter:
- dfbfilename - name of the shp file to open.
- accessflag - type of access; "rb" (read-only binary) and "rb+" (read/write binary).
SHPHandle = SHP_Open(shpfilename,accessflag);
shphdl = SHP_Open("C:/mySHPfile","rb");
This command closes a SHP attribute file.
- There is 1 parameter:
- shphandle - The SHP handle of the shp file to close.
SHP_Close(shpfilhandle);
SHP_Close(shphdl);
This command creates a shape object in memory that can be written to a shape file.
A handle to the object is returned.
- There are 7 to 9 parameters:
- shapetype - type of shape to create: 1 = point, 3 = arc, 5 = polygon, 8 = multipoint.
- shapeid - integer id of shape to create.
- nparts - number of parts in the shape.
- partstart - integer value giving the part start index.
- parttype - integer part type of the part being created.
- x vector - vector of x coordinates.
- y vector - vector of y coordinates.
- z vector - optional vector of z coordinates.
- m vector - optional vector of measure values.
shpObject = SHP_Create_Object(type,shapeID,nparts,partstart,parttype,x vector,y vector[,z vector[,m vector]]);
myShpObject = SHP_Create_Object(1,1,0,$null,$null,-66 -67 -65.5,43 44 45.6,1 2 3.);
This command removes a shape object from memory.
- There is 1 parameter:
- shapeobject - The handle of the shape object to remove.
SHP_Destroy_Object(shapeobject);
SHP_Destroy_Object(shapeobject);
This command creates a shape object in memory that can be written to a shape file.
A handle to the object is returned.
- There are 3 or 4 parameters:
- shapetype - type of shape to create: 1 = point, 3 = arc, 5 = polygon, 8 = multipoint.
- x vector - vector of x coordinates.
- y vector - vector of y coordinates.
- z vector - optional vector of z coordinates.
shpObject = SHP_Create_Simple_Object(type,x vector,y vector[,z vector]);
myShpObject = SHP_Create_Simple_Object(1,-66 -67 -65.5,43 44 45.6,1 2 3.);
This command writes a shape object to a shape file.
- There are 3 parameters:
- shphandle - The SHP handle of the shp file to use.
- shapeindex - index of the shape to write. Use -1 to create a new entry.
- shpobject - Handle to the shape object that is to be written.
SHP_Write_Object(ShapeHandle,Shapeindex,ShapeObject);
SHP_Write_Object(shphdl,-1,myShpObj);
This command reads a shape object from a shape file into memory. The object returned is an
enclosed vector with 18 elements.
The elements of the returned object are:
object[1] = nSHPType
object[2] = nShapeId
object[3] = nParts
object[4] = panPartStart integer vector
object[5] = panPartType integer vector
object[6] = nVertices
object[7] = padfX double vector
object[8] = padfY double vector
object[9] = padfZ double vector
object[10] = padfM double vector
object[11] = dfXMin
object[12] = dfYMin
object[13] = dfZMin
object[14] = dfMMin
object[15] = dfXMax
object[16] = dfYMax
object[17] = dfZMax
object[18] = dfMMax
- There are 2 parameters:
- shphandle - The SHP handle of the shp file to use.
- shapeindex - index of the shape to read.
SHP_Read_Object(ShapeHandle,Shapeindex);
myObj = SHP_Read_Object(shphdl,0);
This command reads summary info from a shape file into memory. The object returned is an
enclosed vector with 4 elements.
The elements of the returned object are:
object[1] = number of entities
object[2] = Shapefile type
object[3] = vector of 4 values containing the minimum values for x,y,z and m
object[4] = vector of 4 values containing the maximum values for x,y,z and m
- There is 1 parameter:
- shphandle - The SHP handle of the shp file to use.
SHP_Get_Info(ShapeHandle);
myInfo = SHP_Get_Info(shphdl);
ACON
Home/Topics |
Commands
|