GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
write_pg.c File Reference

Vector library - write vector feature (PostGIS format) More...

#include <inttypes.h>
#include <string.h>
#include <grass/vector.h>
#include <grass/glocale.h>
#include "local_proto.h"
#include "pg_local_proto.h"
Include dependency graph for write_pg.c:

Go to the source code of this file.

Macros

#define WKBSRIDFLAG   0x20000000
 
#define TOPOGEOM_COLUMN   "topo"
 
#define USE_TOPO_STMT   0
 
#define NOPG_UNUSED
 

Functions

off_t V1_write_line_pg (struct Map_info *Map NOPG_UNUSED, int type NOPG_UNUSED, const struct line_pnts *points NOPG_UNUSED, const struct line_cats *cats NOPG_UNUSED)
 Writes feature on level 1 (PostGIS interface) More...
 
off_t V2_write_line_pg (struct Map_info *Map NOPG_UNUSED, int type NOPG_UNUSED, const struct line_pnts *points NOPG_UNUSED, const struct line_cats *cats NOPG_UNUSED)
 Writes feature on topological level (PostGIS interface) More...
 
off_t V1_rewrite_line_pg (struct Map_info *Map NOPG_UNUSED, off_t offset, int type, const struct line_pnts *points NOPG_UNUSED, const struct line_cats *cats NOPG_UNUSED)
 Rewrites feature at the given offset (level 1) (PostGIS interface, internal use only) More...
 
off_t V2_rewrite_line_pg (struct Map_info *Map NOPG_UNUSED, off_t line, int type, const struct line_pnts *points NOPG_UNUSED, const struct line_cats *cats UNUSED)
 Rewrites feature at topological level (PostGIS interface, internal use only) More...
 
int V1_delete_line_pg (struct Map_info *Map NOPG_UNUSED, off_t offset NOPG_UNUSED)
 Deletes feature at the given offset (level 1) More...
 
int V2_delete_line_pg (struct Map_info *Map NOPG_UNUSED, off_t line NOPG_UNUSED)
 Deletes feature on topological level (PostGIS interface) More...
 
off_t V2__write_node_pg (struct Map_info *Map, const struct line_pnts *points)
 Writes node on topological level (PostGIS Topology interface, internal use only) More...
 
off_t V2__write_area_pg (struct Map_info *Map, const struct line_pnts **points, int nparts, const struct line_cats *cats)
 Writes area on topological level (PostGIS Simple Features interface, internal use only) More...
 
int V2__update_area_pg (struct Map_info *Map, const struct line_pnts **points, int nparts, int cat)
 Updates simple features geometry from GRASS-like topo. More...
 
int Vect__define_topo_relation (const struct Format_info_pg *pg_info, int topo_id, int element_id)
 
int Vect__insert_face_pg (struct Map_info *Map, int area)
 Insert new face to the 'face' table (topo only) More...
 

Detailed Description

Vector library - write vector feature (PostGIS format)

Higher level functions for reading/writing/manipulating vectors.

Write subroutine inspired by OGR PostgreSQL driver.

Todo:

PostGIS version of V2__delete_area_cats_from_cidx_nat()

function to delete corresponding entry in fidx

PostGIS version of V2__add_area_cats_to_cidx_nat

(C) 2012-2014 by Martin Landa, and 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.

Author
Martin Landa <landa.martin gmail.com>

Definition in file write_pg.c.

Macro Definition Documentation

◆ NOPG_UNUSED

#define NOPG_UNUSED

Definition at line 83 of file write_pg.c.

◆ TOPOGEOM_COLUMN

#define TOPOGEOM_COLUMN   "topo"

Definition at line 35 of file write_pg.c.

◆ USE_TOPO_STMT

#define USE_TOPO_STMT   0

Use SQL statements from PostGIS Topology extension (this options is quite slow. By default are used simple SQL statements (INSERT, UPDATE)

Definition at line 40 of file write_pg.c.

◆ WKBSRIDFLAG

#define WKBSRIDFLAG   0x20000000

Definition at line 33 of file write_pg.c.

Function Documentation

◆ V1_delete_line_pg()

int V1_delete_line_pg ( struct Map_info *Map  NOPG_UNUSED,
off_t offset  NOPG_UNUSED 
)

Deletes feature at the given offset (level 1)

Only for simple feature access. PostGIS Topology requires level 2.

Parameters
Mappointer Map_info structure
offsetfeature offset
Returns
0 on success
-1 on error

Definition at line 324 of file write_pg.c.

References _, Format_info_offset::array, Format_info_offset::array_num, Format_info_pg::conn, DB_SQL_MAX, Format_info_pg::fid_column, G_debug(), G_fatal_error(), G_warning(), Format_info_pg::inTransaction, Format_info_pg::offset, Format_info_pg::table_name, TRUE, and Vect__execute_pg().

◆ V1_rewrite_line_pg()

off_t V1_rewrite_line_pg ( struct Map_info *Map  NOPG_UNUSED,
off_t  offset,
int  type,
const struct line_pnts *points  NOPG_UNUSED,
const struct line_cats *cats  NOPG_UNUSED 
)

Rewrites feature at the given offset (level 1) (PostGIS interface, internal use only)

Only for simple feature access. PostGIS Topology requires level 2.

Todo:
Use UPDATE statement ?
Parameters
Mappointer to Map_info structure
offsetfeature offset
typefeature type (GV_POINT, GV_LINE, ...)
pointsfeature geometry
catsfeature categories
Returns
feature offset (rewritten feature)
-1 on error

Definition at line 190 of file write_pg.c.

◆ V1_write_line_pg()

off_t V1_write_line_pg ( struct Map_info *Map  NOPG_UNUSED,
int type  NOPG_UNUSED,
const struct line_pnts *points  NOPG_UNUSED,
const struct line_cats *cats  NOPG_UNUSED 
)

Writes feature on level 1 (PostGIS interface)

Notes for simple feature access:

  • centroids are not supported in PostGIS, pseudotopo holds virtual centroids
  • boundaries are not supported in PostGIS, pseudotopo treats polygons as boundaries

Notes for PostGIS Topology access:

  • centroids are stored as isolated nodes
  • boundaries are stored as edges
Parameters
Mappointer to Map_info structure
typefeature type (GV_POINT, GV_LINE, ...)
pointspointer to line_pnts structure (feature geometry)
catspointer to line_cats structure (feature categories)
Returns
feature offset into file
-1 on error

Definition at line 109 of file write_pg.c.

◆ V2__update_area_pg()

int V2__update_area_pg ( struct Map_info Map,
const struct line_pnts **  points,
int  nparts,
int  cat 
)

Updates simple features geometry from GRASS-like topo.

Parameters
Mappointer to Map_info structure
pointsfeature geometry (exterior + interior rings)
npartsnumber of parts including exterior ring
catarea category
Returns
0 on success
-1 on error

Definition at line 557 of file write_pg.c.

References _, Map_info::fInfo, G_warning(), line_pnts::n_points, Format_info::pg, and x.

◆ V2__write_area_pg()

off_t V2__write_area_pg ( struct Map_info Map,
const struct line_pnts **  points,
int  nparts,
const struct line_cats cats 
)

Writes area on topological level (PostGIS Simple Features interface, internal use only)

Parameters
Mappointer to Map_info structure
pointsfeature geometry (exterior + interior rings)
npartsnumber of parts including exterior ring
catsfeature categories
Returns
feature offset
-1 on error

Definition at line 540 of file write_pg.c.

Referenced by V2__write_area_sfa().

◆ V2__write_node_pg()

off_t V2__write_node_pg ( struct Map_info Map,
const struct line_pnts points 
)

Writes node on topological level (PostGIS Topology interface, internal use only)

The vector map must be open on level 2 at least with GV_BUILD_BASE. PostGIS Topology schema must be defined.

Parameters
Mappointer to Map_info structure
nodenode id (starts at 1)
pointspointer to line_pnts structure
Returns
0 on success
-1 on error

Definition at line 516 of file write_pg.c.

References Map_info::fInfo, Format_info::pg, and Format_info_pg::toposchema_name.

◆ V2_delete_line_pg()

int V2_delete_line_pg ( struct Map_info *Map  NOPG_UNUSED,
off_t line  NOPG_UNUSED 
)

Deletes feature on topological level (PostGIS interface)

Note: Topology must be built at level >= GV_BUILD_BASE

Calls V2_delete_line_sfa() for simple feature access.

Parameters
Mappointer to Map_info structure
linefeature id to be deleted
Returns
0 on success
-1 on error

Definition at line 387 of file write_pg.c.

◆ V2_rewrite_line_pg()

off_t V2_rewrite_line_pg ( struct Map_info *Map  NOPG_UNUSED,
off_t  line,
int  type,
const struct line_pnts *points  NOPG_UNUSED,
const struct line_cats *cats  UNUSED 
)

Rewrites feature at topological level (PostGIS interface, internal use only)

Note: Topology must be built at level >= GV_BUILD_BASE

Todo:

Handle also categories

Store original geometry in tmp table for restore

Parameters
Mappointer to Map_info structure
linefeature id
typefeature type (GV_POINT, GV_LINE, ...)
pointsfeature geometry
catsfeature categories (unused)
Returns
offset where feature was rewritten
-1 on error

Definition at line 229 of file write_pg.c.

◆ V2_write_line_pg()

off_t V2_write_line_pg ( struct Map_info *Map  NOPG_UNUSED,
int type  NOPG_UNUSED,
const struct line_pnts *points  NOPG_UNUSED,
const struct line_cats *cats  NOPG_UNUSED 
)

Writes feature on topological level (PostGIS interface)

Calls V2_write_line_sfa() for simple features access.

Parameters
Mappointer to Map_info structure
typefeature type (GV_POINT, GV_LINE, ...)
pointspointer to line_pnts structure (feature geometry)
catspointer to line_cats structure (feature categories)
Returns
feature offset into file
-1 on error

Definition at line 152 of file write_pg.c.

◆ Vect__define_topo_relation()

int Vect__define_topo_relation ( const struct Format_info_pg pg_info,
int  topo_id,
int  element_id 
)

Definition at line 2416 of file write_pg.c.

References DB_SQL_MAX.

◆ Vect__insert_face_pg()

int Vect__insert_face_pg ( struct Map_info Map,
int  area 
)

Insert new face to the 'face' table (topo only)

Parameters
Mappointer to Map_info struct
areaarea id (negative id for isles)
Returns
0 on error
area id on success (>0)

Definition at line 2563 of file write_pg.c.

References Format_info_pg::conn, bound_box::E, Map_info::fInfo, G_asprintf(), G_debug(), G_free(), bound_box::N, NULL, Format_info::pg, bound_box::S, Format_info_pg::srid, Format_info_pg::toposchema_name, Vect__execute_pg(), Vect_get_area_box(), Vect_get_isle_box(), and bound_box::W.