|
GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
|
Vector library - Open existing or create new vector map (native or OGR/PostGIS format) More...
#include <stdlib.h>#include <stdio.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <grass/vector.h>#include <grass/glocale.h>#include "local_proto.h"#include "pg_local_proto.h"
Go to the source code of this file.
Macros | |
| #define | MAX_OPEN_LEVEL 2 |
| Number of levels. | |
Functions | |
| int | Vect_set_open_level (int level) |
| Predetermine level at which a vector map will be opened for reading. | |
| int | Vect__open_old (struct Map_info *Map, const char *name, const char *mapset, const char *layer, int update, int head_only, int is_tmp) |
| Open existing vector map for reading (internal use only) | |
| int | Vect_open_old (struct Map_info *Map, const char *name, const char *mapset) |
| Open existing vector map for reading. | |
| int | Vect_open_tmp_old (struct Map_info *Map, const char *name, const char *mapset) |
| Open existing temporary vector map for reading. | |
| int | Vect_open_old2 (struct Map_info *Map, const char *name, const char *mapset, const char *layer) |
| Open existing vector map for reading. | |
| int | Vect_open_update (struct Map_info *Map, const char *name, const char *mapset) |
| Open existing vector map for reading/writing. | |
| int | Vect_open_tmp_update (struct Map_info *Map, const char *name, const char *mapset) |
| Open existing temporary vector map for reading/writing. | |
| int | Vect_open_update2 (struct Map_info *Map, const char *name, const char *mapset, const char *layer) |
| Open existing vector map for reading/writing. | |
| int | Vect_open_old_head (struct Map_info *Map, const char *name, const char *mapset) |
| Reads only info about vector map (headers) | |
| int | Vect_open_old_head2 (struct Map_info *Map, const char *name, const char *mapset, const char *layer) |
| Reads only info about vector map (headers) | |
| int | Vect_open_update_head (struct Map_info *Map, const char *name, const char *mapset) |
| Open header file of existing vector map for updating (mostly for database link updates) | |
| int | Vect_open_new (struct Map_info *Map, const char *name, int with_z) |
| Create new vector map for reading/writing. | |
| int | Vect_open_tmp_new (struct Map_info *Map, const char *name, int with_z) |
| Create new temporary vector map. | |
| int | Vect_coor_info (struct Map_info *Map, struct Coor_info *Info) |
| Update Coor_info structure. | |
| const char * | Vect_maptype_info (struct Map_info *Map) |
| Gets vector map format (as string) | |
| int | Vect_maptype (struct Map_info *Map) |
| Gets vector map format. | |
| int | Vect_open_topo (struct Map_info *Map, int head_only) |
| Open topology file ('topo') | |
| int | Vect_open_sidx (struct Map_info *Map, int mode) |
| Open spatial index file ('sidx') | |
| char * | Vect__get_path (char *path, struct Map_info *Map) |
| Get map directory name (internal use only) | |
| char * | Vect__get_element_path (char *file_path, struct Map_info *Map, const char *element) |
| Get map element full path (internal use only) | |
Vector library - Open existing or create new vector map (native or OGR/PostGIS format)
Higher level functions for reading/writing/manipulating vectors.
(C) 2001-2015 by the GRASS Development Team
This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.
Definition in file vector/Vlib/open.c.
| #define MAX_OPEN_LEVEL 2 |
Number of levels.
2 with 2D topology
Definition at line 45 of file vector/Vlib/open.c.
Get map element full path (internal use only)
Allocate string should be freed by G_free().
| Map | pointer to Map_info struct |
| element | element name, eg. GV_TOPO_ELEMENT |
Definition at line 1507 of file vector/Vlib/open.c.
References G_file_name(), G_file_name_tmp(), GPATH_MAX, and Vect__get_path().
Referenced by V1_close_nat(), V1_open_new_nat(), V2_close_pg(), Vect__delete(), Vect__open_old(), Vect_cidx_open(), Vect_coor_info(), Vect_default_field_info(), Vect_open_sidx(), Vect_open_topo(), Vect_save_fidx(), and Vect_save_sidx().
Get map directory name (internal use only)
| file_path | path string buffer |
| Map | pointer to Map_info struct |
Definition at line 1476 of file vector/Vlib/open.c.
References _, G__temp_element(), G_fatal_error(), GPATH_MAX, GV_DIRECTORY, AMI_STREAM< T >::name(), and TRUE.
Referenced by V1_open_new_nat(), V1_open_old_nat(), Vect__get_element_path(), Vect__open_old(), Vect__read_head(), Vect__write_head(), Vect_cidx_open(), Vect_cidx_save(), Vect_open_sidx(), Vect_open_topo(), Vect_save_topo(), and Vect_write_dblinks().
| int Vect__open_old | ( | struct Map_info * | Map, |
| const char * | name, | ||
| const char * | mapset, | ||
| const char * | layer, | ||
| int | update, | ||
| int | head_only, | ||
| int | is_tmp | ||
| ) |
Open existing vector map for reading (internal use only)
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to open | |
| mapset | mapset name ("" for search path) | |
| layer | layer name (OGR format only) | |
| update | non-zero to open for update otherwise read-only mode | |
| head_only | read only header info from 'head', 'dbln', 'topo', 'cidx' is not opened. The header may be opened on level 2 only. | |
| is_tmp | non-zero code for temporary maps |
Definition at line 152 of file vector/Vlib/open.c.
References _, access, dig_free_plus(), dig_init_plus(), dig_read_frmt_ascii(), F_OK, FALSE, Map_info::format, G_debug(), G_fatal_error(), G_find_vector2(), G_fopen_modify(), G_fopen_old(), G_fseek(), G_gisdbase(), G_location(), G_mapset(), G_message(), G_name_is_fully_qualified(), G_projection(), G_set_verbose(), G_store(), G_verbose(), G_warning(), G_zero(), G_zone(), GMAPSET_MAX, GNAME_MAX, GPATH_MAX, GV_BUILD_ALL, GV_BUILD_NONE, GV_CIDX_ELEMENT, GV_FIDX_ELEMENT, GV_FORMAT_NATIVE, GV_FORMAT_OGR, GV_FORMAT_OGR_DIRECT, GV_FORMAT_POSTGIS, GV_FRMT_ELEMENT, GV_HEAD_ELEMENT, GV_HIST_ELEMENT, GV_MODE_READ, GV_MODE_RW, GV_SIDX_ELEMENT, GV_TOPO_ELEMENT, Map_info::head, Map_info::head_only, Map_info::level, Map_info::mapset, AMI_STREAM< T >::name(), name, NULL, strcasecmp, TRUE, unlink, V2_open_old_ogr(), V2_open_old_pg(), Vect__get_element_path(), Vect__get_path(), Vect__init_head(), Vect__open_topo_pg(), Vect__read_head(), Vect_build(), Vect_cidx_open(), Vect_get_full_name(), Vect_get_name(), Vect_get_zone(), Vect_hist_write(), Vect_new_dblinks_struct(), VECT_OPEN_CODE, Vect_open_sidx(), Vect_open_topo(), Vect_read_dblinks(), Vect_rewind(), Vect_set_proj(), Vect_set_zone(), and WITHOUT_Z.
Referenced by Vect__delete(), Vect_open_old(), Vect_open_old2(), Vect_open_old_head(), Vect_open_old_head2(), Vect_open_tmp_old(), Vect_open_tmp_update(), Vect_open_update(), Vect_open_update2(), and Vect_open_update_head().
Update Coor_info structure.
Definition at line 993 of file vector/Vlib/open.c.
References _, AMI_STREAM< T >::AMI_STREAM(), dig_fseek(), dig_ftell(), G_debug(), G_warning(), GPATH_MAX, GV_COOR_ELEMENT, GV_FORMAT_NATIVE, GV_FORMAT_OGR, GV_FORMAT_OGR_DIRECT, GV_FORMAT_POSTGIS, Vect__get_element_path(), and VECT_OPEN_CODE.
Referenced by V1_close_nat(), V1_open_old_nat(), Vect_close(), Vect_open_sidx(), and Vect_open_topo().
Gets vector map format.
Currently are implemented:
| Map | pointer to Map_info structure |
Definition at line 1087 of file vector/Vlib/open.c.
References GV_FORMAT_OGR, and GV_FORMAT_POSTGIS.
Referenced by Vect_fidx_dump().
Gets vector map format (as string)
Note: string is allocated by G_store(). Free allocated memory with G_free().
Currently are implemented:
| Map | pointer to Map_info structure |
Definition at line 1051 of file vector/Vlib/open.c.
References _, AMI_STREAM< T >::AMI_STREAM(), G_store(), GV_FORMAT_NATIVE, GV_FORMAT_OGR, GV_FORMAT_OGR_DIRECT, and GV_FORMAT_POSTGIS.
Referenced by Vect_fidx_dump().
Create new vector map for reading/writing.
By default list of updated features is not maintained, see Vect_set_updated() for details.
By default map format is native (GV_FORMAT_NATIVE). If OGR file is found in the current mapset then the map (ie. OGR layer) is created in given OGR datasource (GV_FORMAT_OGR). Similarly if PG file exists then the map (ie. PostGIS table) is created using PostGIS interface (GV_FORMAT_POSTGIS). The format of map is stored in Map->format.
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to be created | |
| with_z | WITH_Z for 3D vector data otherwise WITHOUT_Z |
Definition at line 938 of file vector/Vlib/open.c.
References G_debug(), and name.
Referenced by Vect_close().
Open existing vector map for reading.
This function is replaced by Vect_open_old2() to handle also direct OGR support.
Calls G_fatal_error() on failure.
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to open | |
| mapset | mapset name ("" for search path) |
Definition at line 581 of file vector/Vlib/open.c.
References FALSE, Map_info::mapset, name, NULL, and Vect__open_old().
Referenced by Gp_load_sites(), Gp_load_sites_thematic(), Gv_load_vect(), and Gv_load_vect_thematic().
| int Vect_open_old2 | ( | struct Map_info * | Map, |
| const char * | name, | ||
| const char * | mapset, | ||
| const char * | layer | ||
| ) |
Open existing vector map for reading.
Calls G_fatal_error() on failure.
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to open (datasource for direct OGR access) | |
| mapset | mapset name ("" for search path, "OGR" for direct OGR access) | |
| layer | layer name (OGR layer for direct OGR access) |
Definition at line 624 of file vector/Vlib/open.c.
References FALSE, Map_info::mapset, name, and Vect__open_old().
Reads only info about vector map (headers)
Reads from headers of 'head', 'dbln', 'topo' and 'cidx' file.
This function is replaced by Vect_open_old_head2() to handle also direct OGR support.
Calls G_fatal_error() on failure.
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to read | |
| mapset | mapset name ("" for search path) |
Definition at line 722 of file vector/Vlib/open.c.
References FALSE, Map_info::mapset, name, NULL, TRUE, and Vect__open_old().
Referenced by Vect_copy().
| int Vect_open_old_head2 | ( | struct Map_info * | Map, |
| const char * | name, | ||
| const char * | mapset, | ||
| const char * | layer | ||
| ) |
Reads only info about vector map (headers)
Reads from headers of 'head', 'dbln', 'topo' and 'cidx' file.
Calls G_fatal_error() on failure.
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to read (dsn for OGR) | |
| mapset | mapset name ("" for search path) | |
| layer | layer name (OGR format) | |
| name | name of vector map to open (datasource for direct OGR access) | |
| mapset | mapset name ("" for search path, "OGR" for direct OGR access) | |
| layer | layer name (OGR layer for direct OGR access) |
Definition at line 748 of file vector/Vlib/open.c.
References FALSE, Map_info::mapset, name, TRUE, and Vect__open_old().
Open spatial index file ('sidx')
| [in,out] | Map | pointer to Map_info |
| mode | 0 old, 1 update, 2 new |
Definition at line 1195 of file vector/Vlib/open.c.
References _, access, dig_file_init(), dig_Rd_spidx(), dig_Rd_spidx_head(), dig_spidx_free(), dig_spidx_init(), err(), F_OK, FALSE, G_debug(), G_fopen_old(), G_warning(), GPATH_MAX, GV_SIDX_ELEMENT, Plus_head::mode, AMI_STREAM< T >::name(), NULL, TRUE, Vect__get_element_path(), Vect__get_path(), and Vect_coor_info().
Referenced by Vect__open_old(), and Vect_build_partial().
Create new temporary vector map.
Temporary vector maps are stored in the current mapset (directory .tmp/<hostname>/vector). If the map already exists, it is overwritten.
Temporary vector maps are automatically deleted when closing the map (see Vect_close() for details).
If name is not given (is NULL), then the name is determined by process id (tmp_<pid>).
| [out] | Map | pointer to output Map_info struct |
| name | name for new vector map (or NULL) | |
| with_z | WITH_Z for 3D vector data otherwise WITHOUT_Z |
Definition at line 969 of file vector/Vlib/open.c.
Open existing temporary vector map for reading.
Temporary vector maps are stored in the current mapset (directory .tmp/<hostname>/vector).
Calls G_fatal_error() on failure.
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to open | |
| mapset | mapset name ("" for search path) |
Definition at line 604 of file vector/Vlib/open.c.
References FALSE, Map_info::mapset, name, NULL, TRUE, and Vect__open_old().
Open existing temporary vector map for reading/writing.
Temporary vector maps are stored in the current mapset (directory .tmp/<hostname>/vector).
By default list of updated features is not maintained, see Vect_set_updated() for details.
Calls G_fatal_error() on failure.
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to update | |
| mapset | mapset name |
Definition at line 675 of file vector/Vlib/open.c.
References FALSE, Map_info::mapset, name, NULL, TRUE, and Vect__open_old().
Open topology file ('topo')
| [in,out] | Map | pointer to Map_info structure |
| head_only | TRUE to read only header |
Definition at line 1114 of file vector/Vlib/open.c.
References _, access, dig_file_init(), dig_load_plus(), dig_Rd_Plus_head(), err(), F_OK, gvfile::file, G_debug(), G_fopen_old(), G_warning(), GPATH_MAX, GV_TOPO_ELEMENT, AMI_STREAM< T >::name(), NULL, Vect__get_element_path(), Vect__get_path(), and Vect_coor_info().
Referenced by Vect__open_old().
Open existing vector map for reading/writing.
This function is replaced by Vect_open_update2() to handle also direct OGR support.
By default list of updated features is not maintained, see Vect_set_updated() for details.
Calls G_fatal_error() on failure.
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to update | |
| mapset | mapset name |
Definition at line 649 of file vector/Vlib/open.c.
References FALSE, Map_info::mapset, name, NULL, TRUE, and Vect__open_old().
| int Vect_open_update2 | ( | struct Map_info * | Map, |
| const char * | name, | ||
| const char * | mapset, | ||
| const char * | layer | ||
| ) |
Open existing vector map for reading/writing.
By default list of updated features is not maintained, see Vect_set_updated() for details.
Calls G_fatal_error() on failure.
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to open (datasource for direct OGR access) | |
| mapset | mapset name ("" for search path, "OGR" for direct OGR access) | |
| layer | layer name (OGR layer for direct OGR access) |
Definition at line 698 of file vector/Vlib/open.c.
References FALSE, Map_info::mapset, name, TRUE, and Vect__open_old().
Open header file of existing vector map for updating (mostly for database link updates)
| [out] | Map | pointer to Map_info structure |
| name | name of vector map to update | |
| mapset | mapset name |
Definition at line 765 of file vector/Vlib/open.c.
References FALSE, Map_info::mapset, name, NULL, TRUE, and Vect__open_old().
Referenced by Vect_copy(), and Vect_rename().
Predetermine level at which a vector map will be opened for reading.
If it can't open that level, the open will fail. The specified level must be set before any call to open. The default is to try to open the highest level possible, and keep stepping down until success.
NOTE: This should only be used to set when you wish to force a lower level open. If you require a higher level, then just check the return to verify the level instead of forcing it. This is because future releases will have higher levels which will be downward compatible and which your programs should support by default.
| level | vector access level |
Definition at line 124 of file vector/Vlib/open.c.
References _, G_warning(), Map_info::level, and MAX_OPEN_LEVEL.
Referenced by Gp_load_sites(), Gp_load_sites_thematic(), Gv_load_vect(), Gv_load_vect_thematic(), Vect__delete(), Vect_copy(), and Vect_rename().