[GRASS-SVN] r64214 - in grass/trunk: include/defs lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 16 03:09:54 PST 2015
Author: mmetz
Date: 2015-01-16 03:09:54 -0800 (Fri, 16 Jan 2015)
New Revision: 64214
Modified:
grass/trunk/include/defs/vector.h
grass/trunk/lib/vector/Vlib/write.c
grass/trunk/lib/vector/Vlib/write_nat.c
grass/trunk/lib/vector/Vlib/write_ogr.c
grass/trunk/lib/vector/Vlib/write_pg.c
grass/trunk/lib/vector/Vlib/write_sfa.c
Log:
Vlib: fix vector IO, enable level 1 fns
Modified: grass/trunk/include/defs/vector.h
===================================================================
--- grass/trunk/include/defs/vector.h 2015-01-16 10:56:51 UTC (rev 64213)
+++ grass/trunk/include/defs/vector.h 2015-01-16 11:09:54 UTC (rev 64214)
@@ -253,16 +253,16 @@
struct line_cats *);
off_t Vect_write_line(struct Map_info *, int, const struct line_pnts *,
const struct line_cats *);
+off_t Vect_rewrite_line(struct Map_info *, off_t, int, const struct line_pnts *,
+ const struct line_cats *);
+int Vect_delete_line(struct Map_info *, off_t);
+int Vect_restore_line(struct Map_info *, off_t);
int Vect_get_num_dblinks(const struct Map_info *);
/* Level 2 only */
int Vect_read_line(const struct Map_info *, struct line_pnts *, struct line_cats *,
int);
-off_t Vect_rewrite_line(struct Map_info *, int, int, const struct line_pnts *,
- const struct line_cats *);
-int Vect_delete_line(struct Map_info *, int);
-int Vect_restore_line(struct Map_info *, int, off_t);
int Vect_line_alive(const struct Map_info *, int);
int Vect_node_alive(const struct Map_info *, int);
@@ -554,7 +554,7 @@
int V2_delete_line_sfa(struct Map_info *, int);
int V2_delete_line_pg(struct Map_info *, int);
int V1_restore_line_nat(struct Map_info *, off_t);
-int V2_restore_line_nat(struct Map_info *, int, off_t);
+int V2_restore_line_nat(struct Map_info *, int);
off_t V1_write_line_nat(struct Map_info *, int, const struct line_pnts *,
const struct line_cats *);
off_t V1_write_line_ogr(struct Map_info *, int, const struct line_pnts *,
@@ -567,17 +567,17 @@
const struct line_cats *);
off_t V2_write_line_pg(struct Map_info *, int, const struct line_pnts *,
const struct line_cats *);
-off_t V1_rewrite_line_nat(struct Map_info *, int, int, off_t,
+off_t V1_rewrite_line_nat(struct Map_info *, off_t, int,
const struct line_pnts *, const struct line_cats *);
-off_t V1_rewrite_line_ogr(struct Map_info *, int, int, off_t,
+off_t V1_rewrite_line_ogr(struct Map_info *, off_t, int,
const struct line_pnts *, const struct line_cats *);
-off_t V1_rewrite_line_pg(struct Map_info *, int, int, off_t,
+off_t V1_rewrite_line_pg(struct Map_info *, off_t, int,
const struct line_pnts *, const struct line_cats *);
-off_t V2_rewrite_line_nat(struct Map_info *, int, int, off_t,
+off_t V2_rewrite_line_nat(struct Map_info *, int, int,
const struct line_pnts *, const struct line_cats *);
-off_t V2_rewrite_line_sfa(struct Map_info *, int, int, off_t,
+off_t V2_rewrite_line_sfa(struct Map_info *, int, int,
const struct line_pnts *, const struct line_cats *);
-off_t V2_rewrite_line_pg(struct Map_info *, int, int, off_t,
+off_t V2_rewrite_line_pg(struct Map_info *, int, int,
const struct line_pnts *, const struct line_cats *);
/* Build topology */
Modified: grass/trunk/lib/vector/Vlib/write.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write.c 2015-01-16 10:56:51 UTC (rev 64213)
+++ grass/trunk/lib/vector/Vlib/write.c 2015-01-16 11:09:54 UTC (rev 64214)
@@ -135,7 +135,7 @@
static int (*Vect_restore_line_array[][3]) () = {
{
- restore_dummy, restore_dummy, V2_restore_line_nat}
+ restore_dummy, V1_restore_line_nat, V2_restore_line_nat}
#ifdef HAVE_OGR
, {
restore_dummy, restore_dummy, restore_dummy}
@@ -183,21 +183,16 @@
G_debug(3, "Vect_write_line(): name = %s, format = %d, level = %d",
Map->name, Map->format, Map->level);
- if (!VECT_OPEN(Map)) {
- G_warning(_("Vector map <%s> is not opened"), Vect_get_name(Map));
+ if (!check_map(Map))
return -1;
- }
-
- if (!(Map->plus.update_cidx)) {
- Map->plus.cidx_up_to_date = FALSE; /* category index will be outdated */
- }
offset =
- (*Vect_write_line_array[Map->format][Map->level]) (Map, type, points,
- cats);
+ (*Vect_write_line_array[Map->format][Map->level]) (Map, type,
+ points, cats);
if (offset < 0)
- G_warning(_("Unable to write feature in vector map <%s>"), Vect_get_name(Map));
+ G_warning(_("Unable to write feature in vector map <%s>"),
+ Vect_get_name(Map));
return offset;
}
@@ -213,41 +208,31 @@
old feature is deleted and new is written.
\param Map pointer to Map_info structure
- \param line feature id
+ \param line feature id (level 2) or feature offset (level 1)
\param type feature type (GV_POINT, GV_LINE, ...)
\param points feature geometry
\param cats feature categories
- \return new feature offset
+ \return new feature id (on level 2) (or 0 when build level < GV_BUILD_BASE)
+ \return offset into file where the feature starts (on level 1)
\return -1 on error
*/
-off_t Vect_rewrite_line(struct Map_info *Map, int line, int type,
+off_t Vect_rewrite_line(struct Map_info *Map, off_t line, int type,
const struct line_pnts *points, const struct line_cats *cats)
{
- off_t ret, offset;
-
+ off_t ret;
+
+ G_debug(3, "Vect_rewrite_line(): name = %s, format = %d, level = %d, line/offset = %"PRI_OFF_T,
+ Map->name, Map->format, Map->level, line);
+
if (!check_map(Map))
return -1;
- if (line < 1 || line > Map->plus.n_lines) {
- G_warning(_("Attempt to access feature with invalid id (%d)"), line);
- return -1;
- }
-
- if (!(Map->plus.update_cidx)) {
- Map->plus.cidx_up_to_date = FALSE; /* category index will be outdated */
- }
-
- offset = Map->plus.Line[line]->offset;
-
- G_debug(3, "Vect_rewrite_line(): name = %s, line = %d, offset = %lu",
- Map->name, line, offset);
-
ret = (*Vect_rewrite_line_array[Map->format][Map->level]) (Map, line, type,
- offset,
points, cats);
if (ret == -1)
- G_warning(_("Unable to rewrite feature %d in vector map <%s>"), line, Vect_get_name(Map));
+ G_warning(_("Unable to rewrite feature/offset %lu in vector map <%s>"),
+ line, Vect_get_name(Map));
return ret;
}
@@ -260,33 +245,25 @@
A warning is printed on error.
\param Map pointer to Map_info structure
- \param line feature id
+ \param line feature id (level 2) or feature offset (level 1)
\return 0 on success
\return -1 on error
*/
-int Vect_delete_line(struct Map_info *Map, int line)
+int Vect_delete_line(struct Map_info *Map, off_t line)
{
int ret;
- G_debug(3, "Vect_delete_line(): name = %s, line = %d", Map->name, line);
+ G_debug(3, "Vect_delete_line(): name = %s, line/offset = %"PRI_OFF_T,
+ Map->name, line);
if (!check_map(Map))
return -1;
-
- if (line < 1 || line > Map->plus.n_lines) {
- G_warning(_("Attempt to access feature with invalid id (%d)"), line);
- return -1;
- }
- if (!(Map->plus.update_cidx)) {
- Map->plus.cidx_up_to_date = FALSE; /* category index will be outdated */
- }
-
ret = (*Vect_delete_line_array[Map->format][Map->level]) (Map, line);
if (ret == -1)
- G_warning(_("Unable to delete feature %d from vector map <%s>"),
+ G_warning(_("Unable to delete feature/offset %lu from vector map <%s>"),
line, Vect_get_name(Map));
return ret;
@@ -306,28 +283,20 @@
\return 0 on success
\return -1 on error
*/
-int Vect_restore_line(struct Map_info *Map, int line, off_t offset)
+int Vect_restore_line(struct Map_info *Map, off_t line)
{
int ret;
- G_debug(3, "Vect_restore_line(): name = %s, line = %d", Map->name, line);
+ G_debug(3, "Vect_restore_line(): name = %s,level = %d, line/offset = %"PRI_OFF_T,
+ Map->name, Map->level, line);
if (!check_map(Map))
return -1;
- if (line < 1 || line > Map->plus.n_lines) {
- G_warning(_("Attempt to access feature with invalid id (%d)"), line);
- return -1;
- }
+ ret = (*Vect_restore_line_array[Map->format][Map->level]) (Map, line);
- if (!(Map->plus.update_cidx)) {
- Map->plus.cidx_up_to_date = 0;
- }
-
- ret = (*Vect_restore_line_array[Map->format][Map->level]) (Map, line, offset);
-
if (ret == -1)
- G_warning(_("Unable to restore feature %d in vector map <%s>"),
+ G_warning(_("Unable to restore feature/offset %lu in vector map <%s>"),
line, Vect_get_name(Map));
return ret;
@@ -339,12 +308,6 @@
G_warning(_("Vector map <%s> is not opened"), Vect_get_name(Map));
return 0;
}
-
- if (Map->level < 2) {
- G_warning(_("Vector map <%s> is not opened on topology level"),
- Vect_get_name(Map));
- return 0;
- }
if (Map->mode != GV_MODE_RW && Map->mode != GV_MODE_WRITE) {
G_warning(_("Vector map <%s> is not opened in write mode"),
Modified: grass/trunk/lib/vector/Vlib/write_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_nat.c 2015-01-16 10:56:51 UTC (rev 64213)
+++ grass/trunk/lib/vector/Vlib/write_nat.c 2015-01-16 11:09:54 UTC (rev 64214)
@@ -67,7 +67,10 @@
off_t offset;
G_debug(3, "V2_write_line_nat(): type=%d", type);
-
+
+ if (!(Map->plus.update_cidx)) {
+ Map->plus.cidx_up_to_date = FALSE; /* category index will be outdated */
+ }
/* write feature to 'coor' file */
offset = V1_write_line_nat(Map, type, points, cats);
if (offset < 0)
@@ -87,25 +90,24 @@
Old feature is deleted (marked as dead), and a new feature written.
\param Map pointer to Map_info structure
- \param line feature id to be rewritten
\param offset feature offset
\param type feature type (GV_POINT, GV_LINE, ...)
\param points feature geometry
\param cats feature categories
- \return feature offset (rewriten feature)
+ \return feature offset (rewritten feature)
\return -1 on error
*/
-off_t V1_rewrite_line_nat(struct Map_info *Map, int line, int type, off_t offset,
+off_t V1_rewrite_line_nat(struct Map_info *Map, off_t offset, int type,
const struct line_pnts *points, const struct line_cats *cats)
{
int old_type;
static struct line_pnts *old_points = NULL;
static struct line_cats *old_cats = NULL;
-
- G_debug(3, "V1_rewrite_line_nat(): line = %d offset = %lu",
- line, (unsigned long) offset);
+ G_debug(3, "V1_rewrite_line_nat(): offset = %"PRI_OFF_T,
+ offset);
+
/* First compare numbers of points and cats with tha old one */
if (!old_points) {
old_points = Vect_new_line_struct();
@@ -137,7 +139,7 @@
/*!
\brief Rewrites feature to 'coor' file at topological level (internal use only)
- Note: Topology must be built at level >= GV_BUILD_BASE
+ Note: requires topology level >= GV_BUILD_BASE.
Note: Function returns feature id, but is defined as off_t for
compatibility with level 1 functions.
@@ -149,10 +151,10 @@
\param points feature geometry
\param cats feature categories
- \return new feature id
+ \return new feature id or 0 (build level < GV_BUILD_BASE)
\return -1 on error
*/
-off_t V2_rewrite_line_nat(struct Map_info *Map, int line, int type, off_t old_offset,
+off_t V2_rewrite_line_nat(struct Map_info *Map, int line, int type,
const struct line_pnts *points, const struct line_cats *cats)
{
/* TODO: this is just quick shortcut because we have already V2_delete_nat()
@@ -162,7 +164,7 @@
* angles not changed etc.) */
int old_type;
- off_t offset;
+ off_t offset, old_offset;
struct Plus_head *plus;
static struct line_cats *old_cats = NULL;
static struct line_pnts *old_points = NULL;
@@ -177,6 +179,17 @@
return V2_write_line_nat(Map, type, points, cats);
}
+ if (line < 1 || line > plus->n_lines) {
+ G_warning(_("Attempt to access feature with invalid id (%d)"), line);
+ return -1;
+ }
+
+ if (!(plus->update_cidx)) {
+ plus->cidx_up_to_date = FALSE; /* category index will be outdated */
+ }
+
+ old_offset = plus->Line[line]->offset;
+
/* read the line */
if (!old_points) {
old_points = Vect_new_line_struct();
@@ -229,7 +242,7 @@
char rhead;
struct gvfile *dig_fp;
- G_debug(3, "V1_delete_line_nat(): offset = %lu", (unsigned long) offset);
+ G_debug(3, "V1_delete_line_nat(): offset = %"PRI_OFF_T, offset);
dig_set_cur_port(&(Map->head.port));
dig_fp = &(Map->dig_fp);
@@ -258,7 +271,7 @@
/*!
\brief Deletes feature at topological level (internal use only)
- Note: Topology must be built at level >= GV_BUILD_BASE
+ Note: requires topology level >= GV_BUILD_BASE.
\param pointer to Map_info structure
\param line feature id
@@ -283,23 +296,26 @@
G_warning(_("Attempt to access feature with invalid id (%d)"), line);
return -1;
}
-
+
Line = Map->plus.Line[line];
if (Line == NULL) {
G_warning(_("Attempt to access dead feature %d"), line);
return -1;
}
+ if (!(plus->update_cidx)) {
+ plus->cidx_up_to_date = FALSE; /* category index will be outdated */
+ }
+
/* read the line */
if (!Points) {
Points = Vect_new_line_struct();
- }
- if (!Cats) {
Cats = Vect_new_cats_struct();
}
+
type = V2_read_line_nat(Map, Points, Cats, line);
- if (type < 0)
- return -1;
+ if (type <= 0)
+ return -1;
/* delete feature from coor file */
if (0 != V1_delete_line_nat(Map, Line->offset))
@@ -326,7 +342,7 @@
char rhead;
struct gvfile *dig_fp;
- G_debug(3, "V1_restore_line_nat(), offset = %lu", (unsigned long) offset);
+ G_debug(3, "V1_restore_line_nat(), offset = %"PRI_OFF_T, offset);
dig_set_cur_port(&(Map->head.port));
dig_fp = &(Map->dig_fp);
@@ -357,18 +373,18 @@
/*!
\brief Restores feature at topological level (internal use only)
- Note: This function requires build level >= GV_BUILD_BASE.
+ Note: requires topology level >= GV_BUILD_BASE.
\param Map pointer to Map_info structure
\param line feature id
- \param offset feature offset
\return 0 on success
\return -1 on error
*/
-int V2_restore_line_nat(struct Map_info *Map, int line, off_t offset)
+int V2_restore_line_nat(struct Map_info *Map, int line)
{
int type;
+ off_t offset;
struct Plus_head *plus;
struct P_line *Line;
static struct line_cats *Cats = NULL;
@@ -388,6 +404,12 @@
G_warning(_("Attempt to access alive feature %d"), line);
return -1;
}
+
+ if (!(plus->update_cidx)) {
+ plus->cidx_up_to_date = 0;
+ }
+
+ offset = Line->offset;
/* restore feature in 'coor' file */
if (0 != V1_restore_line_nat(Map, offset))
Modified: grass/trunk/lib/vector/Vlib/write_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_ogr.c 2015-01-16 10:56:51 UTC (rev 64213)
+++ grass/trunk/lib/vector/Vlib/write_ogr.c 2015-01-16 11:09:54 UTC (rev 64214)
@@ -86,11 +86,11 @@
\return -1 on error
*/
off_t V1_rewrite_line_ogr(struct Map_info *Map,
- int line, int type, off_t offset,
+ off_t offset, int type,
const struct line_pnts *points, const struct line_cats *cats)
{
- G_debug(3, "V1_rewrite_line_ogr(): line=%d type=%d offset=%"PRI_OFF_T,
- line, type, offset);
+ G_debug(3, "V1_rewrite_line_ogr(): type=%d offset=%"PRI_OFF_T,
+ type, offset);
#ifdef HAVE_OGR
if (type != V1_read_line_ogr(Map, NULL, NULL, offset)) {
G_warning(_("Unable to rewrite feature (incompatible feature types)"));
Modified: grass/trunk/lib/vector/Vlib/write_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_pg.c 2015-01-16 10:56:51 UTC (rev 64213)
+++ grass/trunk/lib/vector/Vlib/write_pg.c 2015-01-16 11:09:54 UTC (rev 64214)
@@ -176,12 +176,12 @@
\return -1 on error
*/
off_t V1_rewrite_line_pg(struct Map_info * Map,
- int line, int type, off_t offset,
+ off_t offset, int type,
const struct line_pnts * points,
const struct line_cats * cats)
{
- G_debug(3, "V1_rewrite_line_pg(): line=%d type=%d offset=%"PRI_OFF_T,
- line, type, offset);
+ G_debug(3, "V1_rewrite_line_pg(): type=%d offset=%"PRI_OFF_T,
+ type, offset);
#ifdef HAVE_POSTGRES
if (type != V1_read_line_pg(Map, NULL, NULL, offset)) {
G_warning(_("Unable to rewrite feature (incompatible feature types)"));
@@ -215,18 +215,19 @@
\return offset where feature was rewritten
\return -1 on error
*/
-off_t V2_rewrite_line_pg(struct Map_info *Map, int line, int type, off_t old_offset,
+off_t V2_rewrite_line_pg(struct Map_info *Map, int line, int type,
const struct line_pnts *points, const struct line_cats *cats)
{
- G_debug(3, "V2_rewrite_line_pg(): line=%d type=%d offset=%"PRI_OFF_T,
- line, type, old_offset);
+ G_debug(3, "V2_rewrite_line_pg(): line=%d type=%d",
+ line, type);
#ifdef HAVE_POSTGRES
const char *schema_name, *table_name, *keycolumn;
char *stmt, *geom_data;
struct Format_info_pg *pg_info;
struct P_line *Line;
-
+ off_t offset;
+
geom_data = NULL;
stmt = NULL;
pg_info = &(Map->fInfo.pg);
@@ -241,7 +242,12 @@
G_warning(_("Attempt to access dead feature %d"), line);
return -1;
}
+ offset = Line->offset;
+ if (!(Map->plus.update_cidx)) {
+ Map->plus.cidx_up_to_date = FALSE; /* category index will be outdated */
+ }
+
if (!Points)
Points = Vect_new_line_struct();
@@ -283,7 +289,7 @@
/* update topology
note: offset is not changed */
- return add_line_to_topo_pg(Map, old_offset, type, points);
+ return add_line_to_topo_pg(Map, offset, type, points);
#else
G_fatal_error(_("GRASS is not compiled with PostgreSQL support"));
return -1;
@@ -396,7 +402,11 @@
G_warning(_("Attempt to access dead feature %d"), line);
return -1;
}
-
+
+ if (!(Map->plus.update_cidx)) {
+ Map->plus.cidx_up_to_date = FALSE; /* category index will be outdated */
+ }
+
Vect__execute_pg(pg_info->conn, "BEGIN");
if (Line->type & GV_POINTS) {
@@ -1338,7 +1348,11 @@
pg_info = &(Map->fInfo.pg);
plus = &(Map->plus);
-
+
+ if (!(plus->update_cidx)) {
+ plus->cidx_up_to_date = FALSE; /* category index will be outdated */
+ }
+
/* check type for nodes */
if (is_node && type != GV_POINT) {
G_warning(_("Invalid feature type (%d) for nodes"), type);
@@ -2732,7 +2746,7 @@
\brief Add line to native and PostGIS topology
\param Map vector map
- \param line feature id to remove from topo
+ \param offset ???
\param type feature type
\param Points feature vertices
Modified: grass/trunk/lib/vector/Vlib/write_sfa.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_sfa.c 2015-01-16 10:56:51 UTC (rev 64213)
+++ grass/trunk/lib/vector/Vlib/write_sfa.c 2015-01-16 11:09:54 UTC (rev 64214)
@@ -72,7 +72,11 @@
}
if (offset < 0)
return -1;
-
+
+ if (!(plus->update_cidx)) {
+ plus->cidx_up_to_date = FALSE; /* category index will be outdated */
+ }
+
/* Update topology */
if (plus->built >= GV_BUILD_BASE) {
dig_line_box(points, &box);
@@ -145,11 +149,11 @@
\return offset where line was rewritten
\return -1 on error
*/
-off_t V2_rewrite_line_sfa(struct Map_info *Map, int line, int type, off_t offset,
+off_t V2_rewrite_line_sfa(struct Map_info *Map, int line, int type,
const struct line_pnts *points, const struct line_cats *cats)
{
- G_debug(3, "V2_rewrite_line_sfa(): line=%d type=%d offset=%"PRI_OFF_T,
- line, type, offset);
+ G_debug(3, "V2_rewrite_line_sfa(): line=%d type=%d",
+ line, type);
if (line < 1 || line > Map->plus.n_lines) {
G_warning(_("Attempt to access feature with invalid id (%d)"), line);
@@ -205,6 +209,10 @@
return -1;
}
+ if (!(plus->update_cidx)) {
+ plus->cidx_up_to_date = FALSE; /* category index will be outdated */
+ }
+
if (plus->built >= GV_BUILD_BASE) {
Line = Map->plus.Line[line];
More information about the grass-commit
mailing list