[GRASS-SVN] r48270 - in grass/trunk/lib/vector: Vlib diglib
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 13 15:21:33 EDT 2011
Author: martinl
Date: 2011-09-13 12:21:33 -0700 (Tue, 13 Sep 2011)
New Revision: 48270
Modified:
grass/trunk/lib/vector/Vlib/read.c
grass/trunk/lib/vector/Vlib/read_ogr.c
grass/trunk/lib/vector/Vlib/write_nat.c
grass/trunk/lib/vector/Vlib/write_ogr.c
grass/trunk/lib/vector/diglib/plus_line.c
Log:
vlib: fix Vect_rewrite_line_ogr()
various minor fixes in reading/writing features
Modified: grass/trunk/lib/vector/Vlib/read.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read.c 2011-09-13 16:48:54 UTC (rev 48269)
+++ grass/trunk/lib/vector/Vlib/read.c 2011-09-13 19:21:33 UTC (rev 48270)
@@ -102,7 +102,7 @@
struct line_pnts *line_p, struct line_cats *line_c, int line)
{
- G_debug(3, "Vect_read_line() line=%d", line);
+ G_debug(3, "Vect_read_line() line = %d", line);
if (!VECT_OPEN(Map))
G_fatal_error("Vect_read_line(): %s", _("vector map is not opened"));
Modified: grass/trunk/lib/vector/Vlib/read_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read_ogr.c 2011-09-13 16:48:54 UTC (rev 48269)
+++ grass/trunk/lib/vector/Vlib/read_ogr.c 2011-09-13 19:21:33 UTC (rev 48270)
@@ -266,17 +266,16 @@
int eType, line;
OGRGeometryH hGeom2;
- /* Read coors if hGeom is a simple element (wkbPoint, wkbLineString) otherwise
- * descend to geometry specified by offset[offset] */
+ /* Read coors if hGeom is a simple element (wkbPoint,
+ * wkbLineString) otherwise descend to geometry specified by
+ * offset[offset] */
- G_debug(4, "read_line() offset = %ld", offset);
-
eType = wkbFlatten(OGR_G_GetGeometryType(hGeom));
- G_debug(4, "OGR Geometry of type: %d", eType);
+ G_debug(4, "OGR geometry type: %d", eType);
switch (eType) {
case wkbPoint:
- G_debug(4, "Point");
+ G_debug(4, "\t->Point");
if (Points) {
Vect_append_point(Points, OGR_G_GetX(hGeom, 0), OGR_G_GetY(hGeom, 0),
OGR_G_GetZ(hGeom, 0));
@@ -285,7 +284,7 @@
break;
case wkbLineString:
- G_debug(4, "LineString");
+ G_debug(4, "\t->LineString");
if (Points) {
nPoints = OGR_G_GetPointCount(hGeom);
for (i = 0; i < nPoints; i++) {
@@ -301,7 +300,7 @@
case wkbMultiLineString:
case wkbMultiPolygon:
case wkbGeometryCollection:
- G_debug(4, " more geoms -> part %d", Map->fInfo.ogr.offset[offset]);
+ G_debug(4, " \t->more geoms -> part %d", Map->fInfo.ogr.offset[offset]);
hGeom2 = OGR_G_GetGeometryRef(hGeom, Map->fInfo.ogr.offset[offset]);
line = read_line(Map, hGeom2, offset + 1, Points);
if (eType == wkbPolygon || wkbMultiPolygon)
@@ -402,7 +401,8 @@
int type;
OGRGeometryH hGeom;
- G_debug(4, "V1_read_line_ogr() offset = %lu", (long) offset);
+ G_debug(4, "V1_read_line_ogr() offset = %lu offset_num = %lu",
+ (long) offset, (long) Map->fInfo.ogr.offset_num);
if (offset >= Map->fInfo.ogr.offset_num)
return -2;
@@ -419,7 +419,7 @@
if (line_p != NULL) {
/* Read feature to cache if necessary */
if (Map->fInfo.ogr.feature_cache_id != FID) {
- G_debug(4, "Read feature (FID = %ld) to cache.", FID);
+ G_debug(4, "Read feature (FID = %ld) to cache", FID);
if (Map->fInfo.ogr.feature_cache) {
OGR_F_Destroy(Map->fInfo.ogr.feature_cache);
}
Modified: grass/trunk/lib/vector/Vlib/write_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_nat.c 2011-09-13 16:48:54 UTC (rev 48269)
+++ grass/trunk/lib/vector/Vlib/write_nat.c 2011-09-13 19:21:33 UTC (rev 48270)
@@ -157,12 +157,11 @@
if (plus->built >= GV_BUILD_AREAS) {
if (type == GV_BOUNDARY) {
-
+ struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
+
/* Delete neighbour areas/isles */
- first = 1;
+ first = TRUE;
for (s = 0; s < 2; s++) { /* for each node */
- struct P_topo_b *topo = (struct P_topo_b *)Line->topo;
-
node = (s == 0 ? topo->N1 : topo->N2);
G_debug(3,
" delete neighbour areas/isles: %s node = %d",
@@ -176,9 +175,11 @@
}
G_debug(3, " number of boundaries at node = %d", n);
- if (n > 2) { /* more than 2 boundaries at node ( >= 2 old + 1 new ) */
- /* Line above (to the right), it is enough to check to the right, because if area/isle
- * exists it is the same to the left */
+ if (n > 2) {
+ /* more than 2 boundaries at node ( >= 2 old + 1 new ) */
+ /* Line above (to the right), it is enough to check to
+ the right, because if area/isle
+ exists it is the same to the left */
if (!s)
next_line =
dig_angle_next_line(plus, line, GV_RIGHT,
@@ -192,7 +193,8 @@
NLine = plus->Line[abs(next_line)];
topo = (struct P_topo_b *)NLine->topo;
if (next_line > 0) /* the boundary is connected by 1. node */
- area = topo->right; /* we are interested just in this side (close to our line) */
+ /* we are interested just in this side (close to our line) */
+ area = topo->right;
else if (next_line < 0) /* the boundary is connected by 2. node */
area = topo->left;
@@ -202,7 +204,7 @@
Vect_get_area_box(Map, area, &box);
if (first) {
Vect_box_copy(&abox, &box);
- first = 0;
+ first = FALSE;
}
else
Vect_box_extend(&abox, &box);
@@ -219,9 +221,9 @@
}
}
/* Build new areas/isles.
- * It's true that we deleted also adjacent areas/isles, but
- * if they form new one our boundary must participate, so
- * we need to build areas/isles just for our boundary */
+ * It's true that we deleted also adjacent areas/isles, but
+ * if they form new one our boundary must participate, so
+ * we need to build areas/isles just for our boundary */
for (s = 0; s < 2; s++) {
side = (s == 0 ? GV_LEFT : GV_RIGHT);
G_debug(3, " build area/isle on side = %d", side);
@@ -233,7 +235,7 @@
Vect_get_area_box(Map, area, &box);
if (first) {
Vect_box_copy(&abox, &box);
- first = 0;
+ first = FALSE;
}
else
Vect_box_extend(&abox, &box);
@@ -243,7 +245,7 @@
Vect_get_isle_box(Map, -area, &box);
if (first) {
Vect_box_copy(&abox, &box);
- first = 0;
+ first = FALSE;
}
else
Vect_box_extend(&abox, &box);
@@ -251,8 +253,9 @@
new_area[s] = area;
}
/* Reattach all centroids/isles in deleted areas + new area.
- * Because isles are selected by box it covers also possible new isle created above */
- if (!first) { /* i.e. old area/isle was deleted or new one created */
+ * Because isles are selected by box it covers also possible
+ * new isle created above */
+ if (!first) { /* i.e. old area/isle was deleted or new one created */
/* Reattach isles */
if (plus->built >= GV_BUILD_ATTACH_ISLES)
Vect_attach_isles(Map, &abox);
@@ -325,7 +328,7 @@
{
off_t offset;
- if (dig_fseek(&(Map->dig_fp), 0L, SEEK_END) == -1) /* set to end of file */
+ if (dig_fseek(&(Map->dig_fp), 0L, SEEK_END) == -1) /* set to end of file */
return -1;
offset = dig_ftell(&(Map->dig_fp));
Modified: grass/trunk/lib/vector/Vlib/write_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_ogr.c 2011-09-13 16:48:54 UTC (rev 48269)
+++ grass/trunk/lib/vector/Vlib/write_ogr.c 2011-09-13 19:21:33 UTC (rev 48270)
@@ -31,9 +31,9 @@
static int write_attributes(dbDriver *, int, const struct field_info *,
OGRLayerH, OGRFeatureH);
-void V2__add_line_to_topo_ogr(struct Map_info *Map, int line,
- const struct line_pnts *points,
- const struct line_cats *cats)
+static void V2__add_line_to_topo_ogr(struct Map_info *Map, int line,
+ const struct line_pnts *points,
+ const struct line_cats *cats)
{
/* recycle code from build_ogr */
G_warning("feature not yet implemented, coming soon...");
@@ -59,6 +59,7 @@
int i, cat, ret;
struct field_info *Fi;
+ struct Format_info_ogr *fInfo;
OGRGeometryH Ogr_geometry;
OGRFeatureH Ogr_feature;
@@ -85,7 +86,8 @@
}
}
- Ogr_featuredefn = OGR_L_GetLayerDefn(Map->fInfo.ogr.layer);
+ fInfo = &(Map->fInfo.ogr);
+ Ogr_featuredefn = OGR_L_GetLayerDefn(fInfo->layer);
Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
/* determine matching OGR feature geometry type */
@@ -166,14 +168,24 @@
OGR_F_SetGeometry(Ogr_feature, Ogr_geometry);
/* write attributes */
- if (cat > -1 && Map->fInfo.ogr.dbdriver) {
- write_attributes(Map->fInfo.ogr.dbdriver,
- cat, Fi, Map->fInfo.ogr.layer, Ogr_feature);
+ if (cat > -1 && fInfo->dbdriver) {
+ write_attributes(fInfo->dbdriver,
+ cat, Fi, fInfo->layer, Ogr_feature);
G_free(Fi);
}
/* write feature into layer */
- ret = OGR_L_CreateFeature(Map->fInfo.ogr.layer, Ogr_feature);
+ ret = OGR_L_CreateFeature(fInfo->layer, Ogr_feature);
+ /* update offset array */
+ if (fInfo->offset_num >= fInfo->offset_alloc) {
+ fInfo->offset_alloc += 1000;
+ fInfo->offset = (int *) G_realloc(fInfo->offset,
+ fInfo->offset_alloc *
+ sizeof(int));
+ }
+ /* how to deal with OGRNullFID ? */
+ fInfo->offset[fInfo->offset_num] = (int)OGR_F_GetFID(Ogr_feature);
+
/* destroy */
OGR_G_DestroyGeometry(Ogr_geometry);
OGR_F_Destroy(Ogr_feature);
@@ -181,7 +193,7 @@
if (ret != OGRERR_NONE)
return -1;
- return Map->fInfo.ogr.offset_num++;
+ return fInfo->offset_num++;
}
/*!
@@ -206,6 +218,7 @@
line = 0;
G_debug(3, "V2_write_line_ogr()");
+
offset = V1_write_line_ogr(Map, type, points, cats);
if (offset < 0)
return -1;
@@ -269,8 +282,9 @@
\brief Rewrites feature to 'coor' file (topology level) - internal use only
\param Map pointer to Map_info structure
+ \param line feature id
\param type feature type
- \param line feature id
+ \param offset unused
\param points feature geometry
\param cats feature categories
@@ -280,9 +294,14 @@
off_t V2_rewrite_line_ogr(struct Map_info *Map, int line, int type, off_t offset,
const struct line_pnts *points, const struct line_cats *cats)
{
+ if (type != V2_read_line_ogr(Map, NULL, NULL, line)) {
+ G_warning(_("Unable to rewrite feature (incompatible feature types)"));
+ return -1;
+ }
+
V2_delete_line_ogr(Map, line);
- return (V2_write_line_ogr(Map, type, points, cats));
+ return V2_write_line_ogr(Map, type, points, cats);
}
/*!
@@ -329,7 +348,7 @@
static struct line_cats *Cats = NULL;
static struct line_pnts *Points = NULL;
- G_debug(3, "V2_delete_line_nat(), line = %d", (int) line);
+ G_debug(3, "V2_delete_line_ogr(), line = %d", (int) line);
type = first = 0;
Line = NULL;
@@ -350,7 +369,7 @@
Points = Vect_new_line_struct();
}
- type = V2_read_line_nat(Map, Points, Cats, line);
+ type = V2_read_line_ogr(Map, Points, Cats, line);
/* Update category index */
if (plus->update_cidx) {
Modified: grass/trunk/lib/vector/diglib/plus_line.c
===================================================================
--- grass/trunk/lib/vector/diglib/plus_line.c 2011-09-13 16:48:54 UTC (rev 48269)
+++ grass/trunk/lib/vector/diglib/plus_line.c 2011-09-13 19:21:33 UTC (rev 48270)
@@ -82,13 +82,12 @@
lp = Points->n_points - 1;
G_debug(3, "Register node %f,%f", Points->x[lp], Points->y[lp]);
- node =
- dig_find_node(plus, Points->x[lp], Points->y[lp], Points->z[lp]);
+ node = dig_find_node(plus, Points->x[lp], Points->y[lp],
+ Points->z[lp]);
G_debug(3, "node = %d", node);
if (node == 0) {
- node =
- dig_add_node(plus, Points->x[lp], Points->y[lp],
- Points->z[lp]);
+ node = dig_add_node(plus, Points->x[lp], Points->y[lp],
+ Points->z[lp]);
G_debug(3, "Add new node: %d", node);
}
else {
More information about the grass-commit
mailing list