[GRASS-SVN] r44464 - grass/trunk/vector/v.out.ogr
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Nov 28 12:54:32 EST 2010
Author: mmetz
Date: 2010-11-28 09:54:31 -0800 (Sun, 28 Nov 2010)
New Revision: 44464
Modified:
grass/trunk/vector/v.out.ogr/main.c
Log:
format code
Modified: grass/trunk/vector/v.out.ogr/main.c
===================================================================
--- grass/trunk/vector/v.out.ogr/main.c 2010-11-28 17:40:34 UTC (rev 44463)
+++ grass/trunk/vector/v.out.ogr/main.c 2010-11-28 17:54:31 UTC (rev 44464)
@@ -34,7 +34,7 @@
int field;
struct GModule *module;
struct Options options;
- struct Flags flags;
+ struct Flags flags;
char buf[2000];
char key1[200], key2[200];
@@ -56,8 +56,8 @@
dbString dbstring;
dbColumn *Column;
- int fout, fskip; /* features written/ skip */
- int nocat, noatt, nocatskip; /* number of features without cats/atts written/skip */
+ int fout, fskip; /* features written/ skip */
+ int nocat, noatt, nocatskip; /* number of features without cats/atts written/skip */
/* OGR */
int drn, ogr_ftype = OFTInteger;
@@ -80,14 +80,13 @@
G_add_keyword(_("vector"));
G_add_keyword(_("export"));
G_add_keyword(_("ogr"));
-
+
module->description =
_("Converts a vector map to any of the supported OGR vector formats.");
-
+
/* parse & read options */
- parse_args(argc, argv,
- &options, &flags);
-
+ parse_args(argc, argv, &options, &flags);
+
/* parse dataset creation options */
i = 0;
while (options.dsco->answers[i]) {
@@ -109,73 +108,76 @@
}
/*
- If no output type specified: determine one automatically.
- Centroids, Boundaries and Kernels always have to be exported
- explicitely, using the "type=" option.
- */
+ If no output type specified: determine one automatically.
+ Centroids, Boundaries and Kernels always have to be exported
+ explicitely, using the "type=" option.
+ */
if (!flags.new->answer) {
/* open input vector (topology required) */
Vect_set_open_level(2);
Vect_open_old2(&In, options.input->answer, "", options.field->answer);
-
+
if (strcmp(options.type->answer, "auto") == 0) {
G_debug(2, "Automatic type determination.");
-
- options.type->answers = G_malloc(sizeof(char*) * 10);
+
+ options.type->answers = G_malloc(sizeof(char *) * 10);
G_zero(options.type->answers, sizeof(char *) * 10);
num_types = 0;
-
- if (Vect_get_num_primitives (&In, GV_POINT) > 0) {
+
+ if (Vect_get_num_primitives(&In, GV_POINT) > 0) {
options.type->answers[num_types++] = G_store("point");
G_debug(3, "Adding points to export list.");
}
-
- if (Vect_get_num_primitives (&In, GV_LINE) > 0 ) {
+
+ if (Vect_get_num_primitives(&In, GV_LINE) > 0) {
options.type->answers[num_types++] = G_store("line");
G_debug(3, "Adding lines to export list.");
}
-
- if (Vect_get_num_areas (&In) > 0) {
+
+ if (Vect_get_num_areas(&In) > 0) {
options.type->answers[num_types++] = G_store("area");
G_debug(3, "Adding areas to export list.");
}
-
+
/* Faces and volumes:
- For now, volumes will just be exported as sets of faces.
- */
- if (Vect_get_num_primitives (&In, GV_FACE) > 0) {
+ For now, volumes will just be exported as sets of faces.
+ */
+ if (Vect_get_num_primitives(&In, GV_FACE) > 0) {
options.type->answers[num_types++] = G_store("face");
G_debug(3, "Adding faces to export list.");
}
-
+
/* this check HAS TO FOLLOW RIGHT AFTER check for GV_FACE! */
- if ( Vect_get_num_volumes (&In) > 0) {
+ if (Vect_get_num_volumes(&In) > 0) {
G_warning(_("Volumes will be exported as sets of faces"));
if (num_types == 0) {
/* no other types yet? */
options.type->answers[num_types++] = G_store("volume");
G_debug(3, "Adding volumes to export list.");
- } else {
- if (strcmp(options.type->answers[num_types-1], "face") != 0) {
+ }
+ else {
+ if (strcmp(options.type->answers[num_types - 1], "face")
+ != 0) {
/* only put faces on export list if that's not the case already */
- options.type->answers[num_types++] = G_store("volume");
+ options.type->answers[num_types++] =
+ G_store("volume");
G_debug(3, "Adding volumes to export list.");
}
}
}
-
+
if (num_types == 0)
G_fatal_error(_("Unable to determine input map's vector feature type(s)."));
}
}
field = Vect_get_field_number(&In, options.field->answer);
-
+
/* check output feature type */
otype = Vect_option_to_types(options.type);
if (!options.layer->answer) {
- char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
+ char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
if (G_name_is_fully_qualified(options.input->answer, xname, xmapset))
options.layer->answer = G_store(xname);
@@ -234,11 +236,14 @@
/* create new OGR layer in datasource */
if (flags.new->answer) {
const char *name;
- name = options.layer->answer ? options.layer->answer : options.input->answer;
-
+
+ name =
+ options.layer->answer ? options.layer->answer : options.input->
+ answer;
+
create_ogr_layer(options.dsn->answer, options.format->answer, name,
- wkbtype, (const char **) papszDSCO, (const char **) papszLCO);
-
+ wkbtype, papszDSCO, papszLCO);
+
G_message(_("OGR layer <%s> created in datasource <%s> (format '%s')"),
name, options.dsn->answer, options.format->answer);
exit(EXIT_SUCCESS);
@@ -252,9 +257,10 @@
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
- if ((GV_AREA & otype) && Vect_get_num_islands(&In) > 0 && flags.cat->answer)
+ if ((GV_AREA & otype) && Vect_get_num_islands(&In) > 0 &&
+ flags.cat->answer)
G_warning(_("The map contains islands. With the -c flag, "
- "islands will appear as filled areas, not holes in the output map."));
+ "islands will appear as filled areas, not holes in the output map."));
/* Open OGR DSN */
G_debug(2, "driver count = %d", OGRGetDriverCount());
@@ -274,13 +280,16 @@
G_fatal_error(_("OGR driver <%s> not found"), options.format->answer);
Ogr_driver = OGRGetDriver(drn);
- if (flags.update->answer) {
- G_debug(1, "Update OGR data source");
- Ogr_ds = OGR_Dr_Open(Ogr_driver, options.dsn->answer, TRUE);
- } else {
- G_debug(1, "Create OGR data source");
- Ogr_ds = OGR_Dr_CreateDataSource(Ogr_driver, options.dsn->answer, papszDSCO);
+ if (flags.update->answer) {
+ G_debug(1, "Update OGR data source");
+ Ogr_ds = OGR_Dr_Open(Ogr_driver, options.dsn->answer, TRUE);
}
+ else {
+ G_debug(1, "Create OGR data source");
+ Ogr_ds =
+ OGR_Dr_CreateDataSource(Ogr_driver, options.dsn->answer,
+ papszDSCO);
+ }
CSLDestroy(papszDSCO);
if (Ogr_ds == NULL)
@@ -299,7 +308,7 @@
papszLCO = CSLSetNameValue(papszLCO, "OVERWRITE", "YES");
}
}
-
+
/* check if the map is 3d */
if (Vect_is_3d(&In)) {
/* specific check for ESRI ShapeFile */
@@ -336,8 +345,8 @@
G_debug(1, "Create OGR layer");
Ogr_layer =
- OGR_DS_CreateLayer(Ogr_ds, options.layer->answer, Ogr_projection, wkbtype,
- papszLCO);
+ OGR_DS_CreateLayer(Ogr_ds, options.layer->answer, Ogr_projection,
+ wkbtype, papszLCO);
CSLDestroy(papszLCO);
if (Ogr_layer == NULL)
G_fatal_error(_("Unable to create OGR layer"));
@@ -354,8 +363,8 @@
/* if we have no more than a 'cat' column, then that has to
be exported in any case */
if (flags.nocat->answer) {
- G_warning(_("Exporting 'cat' anyway, as it is the only attribute table field"));
- flags.nocat->answer=0;
+ G_warning(_("Exporting 'cat' anyway, as it is the only attribute table field"));
+ flags.nocat->answer = 0;
}
Ogr_field = OGR_Fld_Create("cat", OFTInteger);
OGR_L_CreateField(Ogr_layer, Ogr_field, 0);
@@ -368,7 +377,7 @@
if (!Driver)
G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
Fi->database, Fi->driver);
-
+
db_set_string(&dbstring, Fi->table);
if (db_describe_table(Driver, &dbstring, &Table) != DB_OK)
G_fatal_error(_("Unable to describe table <%s>"), Fi->table);
@@ -407,17 +416,19 @@
keycol = i;
G_debug(2, "%s x %s -> %s x %s -> keycol = %d", Fi->key,
db_get_column_name(Column), key1, key2, keycol);
-
+
if (!flags.nocat->answer) {
Ogr_field =
- OGR_Fld_Create(db_get_column_name(Column), ogr_ftype);
+ OGR_Fld_Create(db_get_column_name(Column), ogr_ftype);
OGR_L_CreateField(Ogr_layer, Ogr_field, 0);
OGR_Fld_Destroy(Ogr_field);
- } else {
+ }
+ else {
/* skip export of 'cat' field */
- if (strcmp (Fi->key, db_get_column_name(Column)) != 0) {
+ if (strcmp(Fi->key, db_get_column_name(Column)) != 0) {
Ogr_field =
- OGR_Fld_Create(db_get_column_name(Column), ogr_ftype);
+ OGR_Fld_Create(db_get_column_name(Column),
+ ogr_ftype);
OGR_L_CreateField(Ogr_layer, Ogr_field, 0);
OGR_Fld_Destroy(Ogr_field);
}
@@ -426,7 +437,6 @@
if (keycol == -1)
G_fatal_error(_("Key column <%s> not found"), Fi->key);
}
-
}
Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
@@ -453,8 +463,8 @@
if (Vect_get_num_primitives(&In, GV_CENTROID) > 0 &&
!(otype & GV_CENTROID) && !(otype & GV_AREA))
G_warning(_("%d centroid(s) found, but not requested to be exported. "
- "Verify 'type' parameter."), Vect_get_num_primitives(&In,
- GV_CENTROID));
+ "Verify 'type' parameter."), Vect_get_num_primitives(&In,
+ GV_CENTROID));
if (Vect_get_num_areas(&In) > 0 && !(otype & GV_AREA))
G_warning(_("%d areas found, but not requested to be exported. "
@@ -472,73 +482,89 @@
/* warn and eventually abort if there is nothing to be exported */
num_to_export = 0;
if (Vect_get_num_primitives(&In, GV_POINT) < 1 && (otype & GV_POINTS)) {
- G_warning(_("No points found, but requested to be exported. "
+ G_warning(_("No points found, but requested to be exported. "
"Will skip this feature type."));
- } else {
- if (otype & GV_POINT)
- num_to_export = num_to_export + Vect_get_num_primitives(&In, GV_POINT);
}
+ else {
+ if (otype & GV_POINT)
+ num_to_export =
+ num_to_export + Vect_get_num_primitives(&In, GV_POINT);
+ }
if (Vect_get_num_primitives(&In, GV_LINE) < 1 && (otype & GV_LINE)) {
- G_warning(_("No lines found, but requested to be exported. "
+ G_warning(_("No lines found, but requested to be exported. "
"Will skip this feature type."));
- } else {
- if (otype & GV_LINE)
- num_to_export = num_to_export + Vect_get_num_primitives(&In, GV_LINE);
}
+ else {
+ if (otype & GV_LINE)
+ num_to_export =
+ num_to_export + Vect_get_num_primitives(&In, GV_LINE);
+ }
- if (Vect_get_num_primitives(&In, GV_BOUNDARY) < 1 && (otype & GV_BOUNDARY)) {
- G_warning(_("No boundaries found, but requested to be exported. "
- "Will skip this feature type."));
- } else {
- if (otype & GV_BOUNDARY)
- num_to_export = num_to_export + Vect_get_num_primitives(&In, GV_BOUNDARY);
+ if (Vect_get_num_primitives(&In, GV_BOUNDARY) < 1 &&
+ (otype & GV_BOUNDARY)) {
+ G_warning(_("No boundaries found, but requested to be exported. "
+ "Will skip this feature type."));
}
+ else {
+ if (otype & GV_BOUNDARY)
+ num_to_export =
+ num_to_export + Vect_get_num_primitives(&In, GV_BOUNDARY);
+ }
if (Vect_get_num_areas(&In) < 1 && (otype & GV_AREA)) {
- G_warning(_("No areas found, but requested to be exported. "
+ G_warning(_("No areas found, but requested to be exported. "
"Will skip this feature type."));
- } else {
- if (otype & GV_AREA)
- num_to_export = num_to_export + Vect_get_num_areas(&In);
}
+ else {
+ if (otype & GV_AREA)
+ num_to_export = num_to_export + Vect_get_num_areas(&In);
+ }
- if (Vect_get_num_primitives(&In, GV_CENTROID) < 1 && (otype & GV_CENTROID)) {
- G_warning(_("No centroids found, but requested to be exported. "
- "Will skip this feature type."));
- } else {
- if (otype & GV_CENTROID)
- num_to_export = num_to_export + Vect_get_num_primitives(&In, GV_CENTROID);
+ if (Vect_get_num_primitives(&In, GV_CENTROID) < 1 &&
+ (otype & GV_CENTROID)) {
+ G_warning(_("No centroids found, but requested to be exported. "
+ "Will skip this feature type."));
}
+ else {
+ if (otype & GV_CENTROID)
+ num_to_export =
+ num_to_export + Vect_get_num_primitives(&In, GV_CENTROID);
+ }
if (Vect_get_num_primitives(&In, GV_FACE) < 1 && (otype & GV_FACE)) {
- G_warning(_("No faces found, but requested to be exported. "
+ G_warning(_("No faces found, but requested to be exported. "
"Will skip this feature type."));
- } else {
- if (otype & GV_FACE)
- num_to_export = num_to_export + Vect_get_num_primitives(&In, GV_FACE);
}
+ else {
+ if (otype & GV_FACE)
+ num_to_export =
+ num_to_export + Vect_get_num_primitives(&In, GV_FACE);
+ }
if (Vect_get_num_primitives(&In, GV_KERNEL) < 1 && (otype & GV_KERNEL)) {
- G_warning(_("No kernels found, but requested to be exported. "
+ G_warning(_("No kernels found, but requested to be exported. "
"Will skip this feature type."));
- } else {
- if (otype & GV_KERNEL)
- num_to_export = num_to_export + Vect_get_num_primitives(&In, GV_KERNEL);
}
+ else {
+ if (otype & GV_KERNEL)
+ num_to_export =
+ num_to_export + Vect_get_num_primitives(&In, GV_KERNEL);
+ }
if (Vect_get_num_volumes(&In) < 1 && (otype & GV_VOLUME)) {
- G_warning(_("No volumes found, but requested to be exported. "
+ G_warning(_("No volumes found, but requested to be exported. "
"Will skip this feature type."));
- } else {
- if (otype & GV_VOLUME)
- num_to_export = num_to_export + Vect_get_num_volumes(&In);
}
+ else {
+ if (otype & GV_VOLUME)
+ num_to_export = num_to_export + Vect_get_num_volumes(&In);
+ }
G_debug(1, "Requested to export %d features", num_to_export);
if (num_to_export < 1) {
- G_warning(_("Nothing to export"));
+ G_warning(_("Nothing to export"));
exit(EXIT_SUCCESS);
}
@@ -562,7 +588,7 @@
nocatskip++;
continue;
}
-
+
/* Geometry */
if (type == GV_LINE && flags.poly->answer) {
OGRGeometryH ring;
@@ -584,7 +610,8 @@
OGR_G_AddGeometryDirectly(Ogr_geometry, ring);
}
- else if ((type == GV_POINT) || ((type == GV_CENTROID) && (otype & GV_CENTROID))) {
+ else if ((type == GV_POINT) ||
+ ((type == GV_CENTROID) && (otype & GV_CENTROID))) {
Ogr_geometry = OGR_G_CreateGeometry(wkbPoint);
OGR_G_AddPoint(Ogr_geometry, Points->x[0], Points->y[0],
Points->z[0]);
@@ -613,7 +640,8 @@
continue;
}
- mk_att(cat, Fi, Driver, ncol, doatt, flags.nocat->answer, Ogr_feature, &noatt, &fout);
+ mk_att(cat, Fi, Driver, ncol, doatt, flags.nocat->answer,
+ Ogr_feature, &noatt, &fout);
OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
}
OGR_G_DestroyGeometry(Ogr_geometry);
@@ -671,7 +699,7 @@
OGR_G_AddGeometryDirectly(Ogr_geometry, ring);
}
- Ogr_feature = OGR_F_Create(Ogr_featuredefn);
+ Ogr_feature = OGR_F_Create(Ogr_featuredefn);
OGR_F_SetGeometry(Ogr_feature, Ogr_geometry);
/* Output one feature for each category */
@@ -687,7 +715,8 @@
continue;
}
- mk_att(cat, Fi, Driver, ncol, doatt, flags.nocat->answer, Ogr_feature, &noatt, &fout);
+ mk_att(cat, Fi, Driver, ncol, doatt, flags.nocat->answer,
+ Ogr_feature, &noatt, &fout);
OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
}
OGR_G_DestroyGeometry(Ogr_geometry);
@@ -697,8 +726,7 @@
/* Faces (run always to count features of different type) - Faces are similar to lines */
if (Vect_get_num_primitives(&In, GV_FACE) > 0 && otype & GV_FACE) {
- G_message(_("Exporting %i faces..."),
- Vect_get_num_faces(&In));
+ G_message(_("Exporting %i faces..."), Vect_get_num_faces(&In));
for (i = 1; i <= Vect_get_num_faces(&In); i++) {
OGRGeometryH ring;
@@ -718,7 +746,7 @@
if (type & GV_FACE) {
- Ogr_feature = OGR_F_Create(Ogr_featuredefn);
+ Ogr_feature = OGR_F_Create(Ogr_featuredefn);
/* Geometry */
Ogr_geometry = OGR_G_CreateGeometry(wkbPolygon25D);
@@ -747,14 +775,14 @@
continue;
}
- mk_att(cat, Fi, Driver, ncol, doatt, flags.nocat->answer, Ogr_feature, &noatt, &fout);
+ mk_att(cat, Fi, Driver, ncol, doatt, flags.nocat->answer,
+ Ogr_feature, &noatt, &fout);
OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
}
OGR_G_DestroyGeometry(Ogr_geometry);
OGR_F_Destroy(Ogr_feature);
} /* if type & GV_FACE */
-
} /* for */
}
@@ -779,48 +807,48 @@
continue;
}
-
/* Geometry */
if (type == GV_KERNEL) {
- Ogr_geometry = OGR_G_CreateGeometry(wkbPoint);
- OGR_G_AddPoint(Ogr_geometry, Points->x[0], Points->y[0],
- Points->z[0]);
+ Ogr_geometry = OGR_G_CreateGeometry(wkbPoint);
+ OGR_G_AddPoint(Ogr_geometry, Points->x[0], Points->y[0],
+ Points->z[0]);
- Ogr_feature = OGR_F_Create(Ogr_featuredefn);
+ Ogr_feature = OGR_F_Create(Ogr_featuredefn);
- OGR_F_SetGeometry(Ogr_feature, Ogr_geometry);
+ OGR_F_SetGeometry(Ogr_feature, Ogr_geometry);
- /* Output one feature for each category */
- for (j = -1; j < Cats->n_cats; j++) {
- if (j == -1) {
- if (cat >= 0)
- continue; /* cat(s) exists */
- }
- else {
- if (Cats->field[j] == field)
- cat = Cats->cat[j];
- else
- continue;
- }
+ /* Output one feature for each category */
+ for (j = -1; j < Cats->n_cats; j++) {
+ if (j == -1) {
+ if (cat >= 0)
+ continue; /* cat(s) exists */
+ }
+ else {
+ if (Cats->field[j] == field)
+ cat = Cats->cat[j];
+ else
+ continue;
+ }
- mk_att(cat, Fi, Driver, ncol, doatt, flags.nocat->answer, Ogr_feature, &noatt, &fout);
- OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
- }
- OGR_G_DestroyGeometry(Ogr_geometry);
- OGR_F_Destroy(Ogr_feature);
+ mk_att(cat, Fi, Driver, ncol, doatt, flags.nocat->answer,
+ Ogr_feature, &noatt, &fout);
+ OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
+ }
+ OGR_G_DestroyGeometry(Ogr_geometry);
+ OGR_F_Destroy(Ogr_feature);
}
}
}
/*
- TODO: Volumes. Do not export kernels here, that's already done.
- We do need to worry about holes, though.
- NOTE: We can probably just merge this with faces export function.
- Except for GRASS, which output format would know the difference?
- */
+ TODO: Volumes. Do not export kernels here, that's already done.
+ We do need to worry about holes, though.
+ NOTE: We can probably just merge this with faces export function.
+ Except for GRASS, which output format would know the difference?
+ */
if ((otype & GV_VOLUME)) {
- G_message(_("Exporting %i volumes..."), Vect_get_num_volumes(&In));
- G_warning(_("Export of volumes not implemented yet. Skipping."));
+ G_message(_("Exporting %i volumes..."), Vect_get_num_volumes(&In));
+ G_warning(_("Export of volumes not implemented yet. Skipping."));
}
OGR_DS_Destroy(Ogr_ds);
@@ -839,7 +867,7 @@
G_warning(_("%d features without attributes were written"), noatt);
if (nocatskip > 0)
G_message(_("%d features found without category were skipped"),
- nocatskip);
+ nocatskip);
/* Enable this? May be confusing that for area type are not reported
* all boundaries/centroids.
@@ -851,6 +879,6 @@
G_done_msg(_("%d features written to <%s> (%s)."), fout,
options.layer->answer, options.format->answer);
-
+
exit(EXIT_SUCCESS);
}
More information about the grass-commit
mailing list