[GRASS-SVN] r60692 - grass/trunk/vector/v.out.ogr
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 3 10:57:55 PDT 2014
Author: hcho
Date: 2014-06-03 10:57:55 -0700 (Tue, 03 Jun 2014)
New Revision: 60692
Modified:
grass/trunk/vector/v.out.ogr/attrb.c
grass/trunk/vector/v.out.ogr/export_areas.c
grass/trunk/vector/v.out.ogr/export_lines.c
grass/trunk/vector/v.out.ogr/main.c
Log:
v.out.ogr
1. Fixed counting # features written without category and related messages.
2. Fixed multi-feature export by checking all available cats, not just the first one.
3. Fixed multi-feature area export with no category.
Modified: grass/trunk/vector/v.out.ogr/attrb.c
===================================================================
--- grass/trunk/vector/v.out.ogr/attrb.c 2014-06-03 14:44:18 UTC (rev 60691)
+++ grass/trunk/vector/v.out.ogr/attrb.c 2014-06-03 17:57:55 UTC (rev 60692)
@@ -138,10 +138,7 @@
OGR_F_SetFieldInteger(Ogr_feature, ogrfieldnum, cat);
}
}
- else {
- /* G_warning ("Line without cat of layer %d", field); */
- nocat++;
- }
+ /* else G_warning ("Line without cat of layer %d", field); */
/*
db_free_string(&dbstring);
Modified: grass/trunk/vector/v.out.ogr/export_areas.c
===================================================================
--- grass/trunk/vector/v.out.ogr/export_areas.c 2014-06-03 14:44:18 UTC (rev 60691)
+++ grass/trunk/vector/v.out.ogr/export_areas.c 2014-06-03 17:57:55 UTC (rev 60692)
@@ -94,6 +94,7 @@
if (j == -1) {
if (cat >= 0)
continue; /* cat(s) exists */
+ (*n_nocat)++;
}
else {
if (Cats->field[j] == field)
@@ -125,11 +126,11 @@
int *n_noatt, int *n_nocat)
{
int i, n_exported, area;
- int cat, lcat, ncats_field, line, type, findex, ipart;
+ int cat, ncats_field, line, type, findex, ipart;
struct line_pnts *Points;
struct line_cats *Cats;
- struct ilist *cat_list, *line_list;
+ struct ilist *cat_list, *line_list, *lcats;
OGRGeometryH Ogr_geometry, Ogr_geometry_part;
OGRFeatureH Ogr_feature;
@@ -139,6 +140,7 @@
Cats = Vect_new_cats_struct();
cat_list = Vect_new_list();
line_list = Vect_new_list();
+ lcats = Vect_new_list();
n_exported = 0;
@@ -155,7 +157,12 @@
ncats_field = Vect_cidx_get_unique_cats_by_index(In, findex, cat_list);
G_debug(1, "n_cats = %d for layer %d", ncats_field, field);
+ if (donocat)
+ G_message(_("Exporting features with category..."));
+
for (i = 0; i < cat_list->n_values; i++) {
+ G_percent(i, cat_list->n_values - 1, 5);
+
cat = cat_list->value[i];
/* find all centroids with given category */
Vect_cidx_find_all(In, field, GV_CENTROID, cat, line_list);
@@ -171,11 +178,11 @@
/* get centroid's category */
Vect_read_line(In, NULL, Cats, line);
/* check for category consistency */
- Vect_cat_get(Cats, field, &lcat);
- if (lcat > 0 && lcat != cat)
+ Vect_field_cat_get(Cats, field, lcats);
+ if (!Vect_val_in_list(lcats, cat))
G_fatal_error(_("Unable to create multi-feature. "
- "Invalid category %d (should be %d)"),
- lcat, cat);
+ "Category %d not found in line %d, field %d"),
+ cat, line, field);
/* find correspoding area */
area = Vect_get_centroid_area(In, line);
@@ -210,6 +217,9 @@
OGR_G_DestroyGeometry(Ogr_geometry);
}
+ if (donocat)
+ G_message(_("Exporting features without category..."));
+
/* check lines without category, if -c flag is given write them as
* one multi-feature */
Ogr_geometry = OGR_G_CreateGeometry(wkbtype);
@@ -232,15 +242,18 @@
}
/* find correspoding area */
+ line = Vect_get_next_line_id(In);
area = Vect_get_centroid_area(In, line);
if (area == 0)
- continue;
+ continue;
/* create polygon from area */
Ogr_geometry_part = create_polygon(In, area, Points);
/* add part */
OGR_G_AddGeometryDirectly(Ogr_geometry, Ogr_geometry_part);
+
+ (*n_nocat)++;
}
if (!OGR_G_IsEmpty(Ogr_geometry)) {
@@ -267,6 +280,7 @@
Vect_destroy_cats_struct(Cats);
Vect_destroy_list(cat_list);
Vect_destroy_list(line_list);
+ Vect_destroy_list(lcats);
return n_exported;
}
Modified: grass/trunk/vector/v.out.ogr/export_lines.c
===================================================================
--- grass/trunk/vector/v.out.ogr/export_lines.c 2014-06-03 14:44:18 UTC (rev 60691)
+++ grass/trunk/vector/v.out.ogr/export_lines.c 2014-06-03 17:57:55 UTC (rev 60692)
@@ -115,6 +115,7 @@
if (j == -1) {
if (cat >= 0)
continue; /* cat(s) exists */
+ (*n_nocat)++;
}
else {
if (Cats->field[j] == field)
@@ -147,11 +148,11 @@
int *n_noatt, int *n_nocat)
{
int i, n_exported;
- int cat, lcat, ncats_field, line, type, findex, ipart;
+ int cat, ncats_field, line, type, findex, ipart;
struct line_pnts *Points;
struct line_cats *Cats;
- struct ilist *cat_list, *line_list;
+ struct ilist *cat_list, *line_list, *lcats;
OGRGeometryH Ogr_geometry;
OGRFeatureH Ogr_feature;
@@ -161,6 +162,7 @@
Cats = Vect_new_cats_struct();
cat_list = Vect_new_list();
line_list = Vect_new_list();
+ lcats = Vect_new_list();
n_exported = 0;
@@ -199,12 +201,12 @@
type = Vect_read_line(In, Points, Cats, line);
/* check for category consistency */
- Vect_cat_get(Cats, field, &lcat);
- if (lcat > 0 && lcat != cat)
+ Vect_field_cat_get(Cats, field, lcats);
+ if (!Vect_val_in_list(lcats, cat))
G_fatal_error(_("Unable to create multi-feature. "
- "Invalid category %d (should be %d)"),
- lcat, cat);
-
+ "Category %d not found in line %d, field %d"),
+ cat, line, field);
+
/* add part */
add_part(Ogr_geometry, wkbtype_part,
type == GV_LINE && force_poly, Points);
@@ -253,6 +255,8 @@
/* add part */
add_part(Ogr_geometry, wkbtype_part,
type == GV_LINE && force_poly, Points);
+
+ (*n_nocat)++;
}
if (!OGR_G_IsEmpty(Ogr_geometry)) {
@@ -279,6 +283,7 @@
Vect_destroy_cats_struct(Cats);
Vect_destroy_list(cat_list);
Vect_destroy_list(line_list);
+ Vect_destroy_list(lcats);
return n_exported;
}
Modified: grass/trunk/vector/v.out.ogr/main.c
===================================================================
--- grass/trunk/vector/v.out.ogr/main.c 2014-06-03 14:44:18 UTC (rev 60691)
+++ grass/trunk/vector/v.out.ogr/main.c 2014-06-03 17:57:55 UTC (rev 60692)
@@ -58,8 +58,8 @@
dbString dbstring;
dbColumn *Column;
- int n_feat; /* number of written features */
- int n_nocat, n_noatt, n_nocatskip; /* number of features without cats/atts written/skip */
+ int n_feat; /* number of written features */
+ int n_nocat, n_noatt; /* number of features without cats/atts written/skip */
/* OGR */
int drn;
@@ -698,7 +698,7 @@
Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
- n_feat = n_nocat = n_noatt = n_nocatskip = 0;
+ n_feat = n_nocat = n_noatt = 0;
if (OGR_L_TestCapability(Ogr_layer, OLCTransactions))
OGR_L_StartTransaction(Ogr_layer);
@@ -715,7 +715,7 @@
Ogr_featuredefn, Ogr_layer,
Fi, Driver, ncol, colctype,
colname, doatt, flags.nocat->answer ? TRUE : FALSE,
- &n_noatt, &n_nocatskip);
+ &n_noatt, &n_nocat);
}
/* Areas (run always to count features of different type) */
@@ -729,7 +729,7 @@
Ogr_featuredefn, Ogr_layer,
Fi, Driver, ncol, colctype,
colname, doatt, flags.nocat->answer ? TRUE : FALSE,
- &n_noatt, &n_nocatskip);
+ &n_noatt, &n_nocat);
}
/*
@@ -759,22 +759,23 @@
}
/* Summary */
- if (n_nocat > 0)
- G_important_message(_n("%d feature without category was written",
- "%d features without category were written",
- n_nocat), n_nocat);
if (n_noatt > 0)
G_important_message(_n("%d feature without attributes was written",
"%d features without attributes were written",
n_noatt), n_noatt);
- if (n_nocatskip > 0)
- G_warning(_n("%d feature without category was skipped. "
- "Features without category are written only when -%c flag is given.",
- "%d features without category were skipped. "
- "Features without category are written only when -%c flag is given.",
- n_nocatskip),
- n_nocatskip, flags.cat->key);
+ if (n_nocat > 0) {
+ if (donocat)
+ G_important_message(_n("%d feature without category was written",
+ "%d features without category were written",
+ n_nocat), n_nocat);
+ else
+ G_warning(_n("%d feature without category was skipped. "
+ "Features without category are written only when -%c flag is given.",
+ "%d features without category were skipped. "
+ "Features without category are written only when -%c flag is given.",
+ n_nocat), n_nocat, flags.cat->key);
+ }
/* Enable this? May be confusing that for area type are not
* reported all boundaries/centroids. OTOH why should be
More information about the grass-commit
mailing list