[GRASS-SVN] r56119 - grass/branches/releasebranch_6_4/vector/v.out.svg
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat May 4 04:21:29 PDT 2013
Author: martinl
Date: 2013-05-04 04:21:28 -0700 (Sat, 04 May 2013)
New Revision: 56119
Modified:
grass/branches/releasebranch_6_4/vector/v.out.svg/main.c
Log:
v.out.svg: bugfix (exporting points and lines)
(merge r56118 from devbr6)
Modified: grass/branches/releasebranch_6_4/vector/v.out.svg/main.c
===================================================================
--- grass/branches/releasebranch_6_4/vector/v.out.svg/main.c 2013-05-04 11:05:36 UTC (rev 56118)
+++ grass/branches/releasebranch_6_4/vector/v.out.svg/main.c 2013-05-04 11:21:28 UTC (rev 56119)
@@ -32,6 +32,10 @@
#define G_Lines "G_Lines"
#define G_Points "G_Points"
+#define TYPE_POINT 1
+#define TYPE_LINE 2
+#define TYPE_POLY 3
+
FILE *fpsvg;
static int mk_path(struct line_pnts *Points, int precision);
@@ -42,7 +46,7 @@
int main(int argc, char *argv[])
{
- int i, j, precision, field;
+ int i, j, precision, field, type, nlines;
int do_attr = 0, attr_cols[8], attr_size = 0, db_open = 0, cnt = 0;
double width, radius;
@@ -110,6 +114,16 @@
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
+ if (type_opt->answer[0] == 'l') {
+ type = TYPE_LINE;
+ }
+ else {
+ if (type_opt->answer[2] == 'l')
+ type = TYPE_POLY;
+ else
+ type = TYPE_POINT;
+ }
+
/* override coordinate precision if any */
precision = atof(prec_opt->answer);
if (precision < 0) {
@@ -199,23 +213,29 @@
fprintf(fpsvg, "<title>v.out.svg %s %s</title>\n", in_opt->answer,
out_opt->answer);
+ nlines = Vect_get_num_lines(&In);
+
/* extract areas if any or requested */
- if (G_strcasecmp(type_opt->answer, "poly") == 0) {
+ if (type == TYPE_POLY) {
if (Vect_get_num_areas(&In) == 0) {
- G_warning(_("No areas found, skipping type=poly"));
+ G_warning(_("No areas found, skipping %"), "type=poly");
}
else {
+ int nareas;
+
+ nareas = Vect_get_num_areas(&In);
/* extract area as paths */
fprintf(fpsvg,
" <g id=\"%s\" fill=\"#CCC\" stroke=\"#000\" stroke-width=\"%.*f\" >\n",
G_Areas, precision, width);
- for (i = 1; i <= Vect_get_num_areas(&In); i++) {
+ for (i = 1; i <= nareas; i++) {
+ G_percent(i, nareas, 5);
+
/* skip areas without centroid */
if (Vect_get_area_centroid(&In, i) == 0) {
G_warning(_("Skipping area %d without centroid"), i);
continue;
}
- G_percent(i, Vect_get_num_areas(&In), 10);
/* extract attribs, parse area */
Vect_get_area_cats(&In, i, Cats);
@@ -239,21 +259,25 @@
cnt += 1;
}
fprintf(fpsvg, " </g>\n");
- G_message(_("Extracted %d areas"), cnt);
+ G_message(_("%d areas extracted"), cnt);
}
}
+
/* extract points if requested */
- if (G_strcasecmp(type_opt->answer, "point") == 0) {
+ if (type == TYPE_POINT) {
if (Vect_get_num_primitives(&In, GV_POINTS) == 0) {
- G_warning(_("No points found, skipping type=point"));
+ G_warning(_("No points found, skipping %s"), "type=point");
}
else {
/* extract points as circles */
fprintf(fpsvg, " <g id=\"%s\" fill=\"#FC0\" stroke=\"#000\" "
"stroke-width=\"%.*f\" >\n", G_Points, precision, width);
- for (i = 1; i <= Vect_get_num_primitives(&In, GV_POINTS); i++) {
- G_percent(i, Vect_get_num_primitives(&In, GV_POINTS), 10);
- Vect_read_line(&In, Points, Cats, i);
+ for (i = 1; i <= nlines; i++) {
+ G_percent(i, nlines, 5);
+
+ if (!(Vect_read_line(&In, Points, Cats, i) & GV_POINTS))
+ continue;
+
for (j = 0; j < Points->n_points; j++) {
fprintf(fpsvg, " <circle ");
if (Cats->n_cats > 0) {
@@ -268,21 +292,25 @@
}
fprintf(fpsvg, " </g>\n");
- G_message(_("Extracted %d points"), cnt);
+ G_message(_("%d points extracted"), cnt);
}
}
+
/* extract lines if requested */
- if (G_strcasecmp(type_opt->answer, "line") == 0) {
+ if (type == TYPE_LINE) {
if (Vect_get_num_primitives(&In, GV_LINES) == 0) {
- G_warning(_("No lines found, skipping type=line"));
+ G_warning(_("No lines found, skipping %s"), "type=line");
}
else {
/* extract lines as paths */
fprintf(fpsvg, " <g id=\"%s\" fill=\"none\" stroke=\"#000\" "
"stroke-width=\"%.*f\" >\n", G_Lines, precision, width);
- for (i = 1; i <= Vect_get_num_primitives(&In, GV_LINES); i++) {
- G_percent(i, Vect_get_num_primitives(&In, GV_LINES), 10);
- Vect_read_line(&In, Points, Cats, i);
+ for (i = 1; i <= nlines; i++) {
+ G_percent(i, nlines, 5);
+
+ if (!(Vect_read_line(&In, Points, Cats, i) & GV_LINES))
+ continue;
+
fprintf(fpsvg, " <path ");
if (Cats->n_cats > 0) {
mk_attribs(Cats->cat[0], Fi, Driver, Table,
@@ -295,7 +323,7 @@
cnt += 1;
}
fprintf(fpsvg, " </g>\n");
- G_message(_("Extracted %d lines"), cnt);
+ G_message(_("%d lines extracted"), cnt);
}
}
/* finish code */
@@ -309,7 +337,7 @@
/* close SVG-file */
fclose(fpsvg);
-
+
exit(EXIT_SUCCESS);
}
@@ -344,7 +372,6 @@
dbString dbstring;
dbColumn *Column;
dbCursor cursor;
- dbValue *Value;
/* include cat in any case */
fprintf(fpsvg, "gg:cat=\"%d\" ", cat);
@@ -375,7 +402,6 @@
for (i = 0; i < attr_size; i++) {
Column = db_get_table_column(Table, attr_cols[i]);
- Value = db_get_column_value(Column);
db_convert_column_value_to_string(Column, &dbstring);
G_strcpy(buf, db_get_column_name(Column));
fprintf(fpsvg, "gg:%s=\"", G_tolcase(buf));
More information about the grass-commit
mailing list