GXSHP class

class GXSHP(handle=0)

GXSHP class.

The GXSHP class is used to create ESRI shape files.

Note:

Shape files contain a single “geometry” type, e.g. points, arcs or polygons. They may be accompanied by a DBF file containing attribute data.

add_double_field(field, dec)

Add a REAL type data field to a shape file

Parameters:
  • field (str) – Field name
  • dec (int) – Number of decimal places
Returns:

Index of the new field

Return type:

int

New in version 6.3.

License: Geosoft Open License

Note: The returned field index should be used with the SetXXX_SHP functions to set individual data values.

add_int_field(field)

Add an INT type data field to a shape file

Parameters:field (str) – Field name
Returns:Index of the new field
Return type:int

New in version 6.3.

License: Geosoft Open License

Note: The returned field index should be used with the SetXXX_SHP functions to set individual data values.

add_string_field(field, width)

Add a string type data field to a shape file

Parameters:
  • field (str) – Field name
  • width (int) – Maximum number of characters in the string
Returns:

Index of the new field

Return type:

int

New in version 6.3.

License: Geosoft Open License

Note: The returned field index should be used with the SetXXX_SHP functions to set individual data values.

append_item()

Append the current item and data to an old GXSHP object.

New in version 7.2.

License: Geosoft Open License

Note: The currently stored GXSHP item and data are written to the GXSHP geometry and data files. (If no data fields have been defined, then the data file is not written).

classmethod create(name, type)

Create a new GXSHP object

Parameters:
Returns:

GXSHP object

Return type:

GXSHP

New in version 6.3.

License: Geosoft Open License

Note: The file name is used to create the various files. The file type and extension are added:

e.g. “filename.shp”,
“filename.dbf”

The following geometry types are currently supported:

Type Required geometry function.

SHP_GEOM_TYPE_POINT set_point SHP_GEOM_TYPE_ARC set_arc SHP_GEOM_TYPE_POLYGON set_polygon

SHP_GEOM_TYPE_POINTZ set_point_z SHP_GEOM_TYPE_ARCZ set_arc_z SHP_GEOM_TYPE_POLYGONZ set_polygon_z

find_field(field)

Find the index for a data field.

Parameters:field (str) – Field name
Returns:The index, -1 if not found.
Return type:int

New in version 6.3.

License: Geosoft Open License

is_null()

Check if this is a null (undefined) instance

Returns:True if this is a null (undefined) instance, False otherwise.
Return type:bool
max_id_num()

Get the max ID number.

Returns:The max ID number.
Return type:int

New in version 7.2.

License: Geosoft Open License

classmethod null()

A null (undefined) instance of GXSHP

Returns:A null GXSHP
Return type:GXSHP
num_fields()

Get the field number.

Returns:The field number.
Return type:int

New in version 7.2.

License: Geosoft Open License

num_records()

Get the record number.

Returns:The record number.
Return type:int

New in version 7.2.

License: Geosoft Open License

classmethod open(name)

Open an old GXSHP object

Parameters:name (str) – File name
Returns:GXSHP object
Return type:GXSHP

New in version 7.2.

License: Geosoft Open License

set_arc(vv_x, vv_y)

Write an XY arc (polyline) item.

Parameters:
  • vv_x (GXVV) – X locations
  • vv_y (GXVV) – Y locations

New in version 6.3.

License: Geosoft Open License

Note: Can ONLY be used for SHP_GEOM_TYPE_ARC files.

set_arc_z(vv_x, vv_y, vv_z)

Write an XYZ arc (polyline) item.

Parameters:
  • vv_x (GXVV) – X locations
  • vv_y (GXVV) – Y locations
  • vv_z (GXVV) – Z locations

New in version 6.3.

License: Geosoft Open License

Note: Can ONLY be used for SHP_GEOM_TYPE_ARCZ files.

set_double(index, val)

Set a data value to a real.

Parameters:
  • index (int) – Data field index
  • val (float) – Input real value

New in version 6.3.

License: Geosoft Open License

Note: The input value is converted to the field’s data type.

set_int(index, val)

Set a data value to a int.

Parameters:
  • index (int) – Data field index
  • val (int) – Input int value

New in version 6.3.

License: Geosoft Open License

Note: The input value is converted to the field’s data type.

set_ipj(ipj)

Set a GXSHP object’s projection.

Parameters:ipj (GXIPJ) – Input GXIPJ

New in version 6.3.

License: Geosoft Open License

Note: If the GXSHP object has a projection, and it is not IPJ_TYPE_NONE, then it will be output to a file with the .prj extension when the first object is output. This function should be called BEFORE the first object is written.

set_point(x, y)

Write an XY point item.

Parameters:
  • x (float) – X location
  • y (float) – Y location

New in version 6.3.

License: Geosoft Open License

Note: Can ONLY be used for SHP_GEOM_TYPE_POINT files.

set_point_z(x, y, z)

Write an XYZ point item.

Parameters:
  • x (float) – X location
  • y (float) – Y location
  • z (float) – Z location

New in version 6.3.

License: Geosoft Open License

Note: Can ONLY be used for SHP_GEOM_TYPE_POINTZ files.

set_polygon(vv_x, vv_y, inclusive)

Write an XY polygon item.

Parameters:
  • vv_x (GXVV) – X locations
  • vv_y (GXVV) – Y locations
  • inclusive (bool) – True for outer ring polygon (inclusive/island), False for inner ring (exclusive/hole)

New in version 6.3.

License: Geosoft Open License

Note: Can ONLY be used for SHP_GEOM_TYPE_POLYGON files.

set_polygon_z(vv_x, vv_y, vv_z, inclusive)

Write an XYZ polygon item.

Parameters:
  • vv_x (GXVV) – X locations
  • vv_y (GXVV) – Y locations
  • vv_z (GXVV) – Z locations
  • inclusive (int) – True for outer ring polygon (inclusive/island), False for inner ring (exclusive/hole)

New in version 6.3.

License: Geosoft Open License

Note: Can ONLY be used for SHP_GEOM_TYPE_POLYGONZ files.

set_string(index, str_val)

Set a data value to a string.

Parameters:
  • index (int) – Data field index
  • str_val (str) – Input string value

New in version 6.3.

License: Geosoft Open License

Note: The input string is converted to the field’s data type.

type()

Get the GXSHP object’s geometry type.

Returns:The GXSHP object’s geometry type (SHP_GEOM_TYPE constants)
Return type:int

New in version 7.2.

License: Geosoft Open License

write_item()

Output the current item and data.

New in version 6.3.

License: Geosoft Open License

Note: The currently stored GXSHP item and data are written to the GXSHP geometry and data files. (If no data fields have been defined, then the data file is not written).

SHP_GEOM_TYPE constants

Shape file geometry types

SHP_GEOM_TYPE_POINT

Single (X, Y) point

gxapi.SHP_GEOM_TYPE_POINT = 1
SHP_GEOM_TYPE_ARC

Arc (polyline) multiple (X, Y) points.

gxapi.SHP_GEOM_TYPE_ARC = 3
SHP_GEOM_TYPE_POLYGON

Polygon. Multiple (X, Y) points.

gxapi.SHP_GEOM_TYPE_POLYGON = 5
SHP_GEOM_TYPE_POINTZ

Single (X, Y, Z) point

gxapi.SHP_GEOM_TYPE_POINTZ = 11
SHP_GEOM_TYPE_ARCZ

Arc (polyline) multiple (X, Y, Z) points.

gxapi.SHP_GEOM_TYPE_ARCZ = 13
SHP_GEOM_TYPE_POLYGONZ

Polygon. Multiple (X, Y, Z) points.

gxapi.SHP_GEOM_TYPE_POLYGONZ = 15