[nona.net home]
not logged inlog in
> home> software> ext_shapelib> usage> shp_create
functions
creating a new shapefile

ext_shapelib - shp_create()

shp_create() - creating a shape file ::
shp_create() creates a new shape file of the given type, and adds attribute fileds to the respective *.dbf file. If the given file did already exist, it is overwritten by the new (empty) file. shp_create() returns a shapefile handle which can subsequently be used by other ext_shapelib functions.
$resource = shp_create($filepath, $shapetype, $dbfarray);
$filepath - path name of file(s) to create ::
$filepath contains the file path of the shape file to be created. Since shapefiles consist of 3 files (.shp, .shx, .dbf), only the file name without any of these 3 extensions should be given as argument.
$shapetype - type of shapefile to be created ::
$shapetype contains the shapefile type to be created. Type definitions are available as constants, available shapefile types are:
SHPT_NULL - null shapes
SHPT_POINT - point shapes
SHPT_ARC - arc line shapes
SHPT_POLYGON - polygon shapes
SHPT_MULTIPOINT - multiple point shapes
SHPT_POINTZ - point shapes with Z coordinate
SHPT_ARCZ - arc shapes with Z coordinates
SHPT_POLYGONZ - polygon shapes with Z coordinates
SHPT_MULTIPOINTZ - multipoint shapes with Z coordinates
$dbfarray - attribute definitions ::
$dbfarray contains definitions of attribute fields to be added to the shapefile's dbf database. $dbfarray has to be an array of hashes, with each key of the hashes defining the name of an attribute (database field). Corresponding values of the hash define field type, length and precision (optional). An example of an attribute definition follows:
$dbfarrary = array(
  "SIZE" => array(SHPFT_DOUBLE, 5, 2), // type, length, precision
  "AGE" => array(SHPFT_INTEGER, 4),  // type, length
  "NAME" => array(SHPFT_STRING, 20)  // type, length
);
When given to shp_create, the above array would create an attribute database containing a double field named "SIZE" with a length of 5 bytes and a precision of 2, an integer "AGE" field of length 4 and a string attribute named "NAME" of length 20.
$resource - return value ::
shp_create returns a shapefile resource in case of success. The resource is to be used in subsequent calls to other ext_shapelib functions. shp_create returns 0 in case of failure.