|
@@ -5,80 +5,68 @@
|
|
|
#include "local_proto.h"
|
|
|
#include "plot.h"
|
|
|
|
|
|
+static int process_line(int, const struct line_pnts *,
|
|
|
+ const struct line_cats *, LATTR *,
|
|
|
+ int, const struct cat_list *);
|
|
|
+
|
|
|
int display_label(struct Map_info *Map, int type,
|
|
|
struct cat_list *Clist, LATTR *lattr, int chcat)
|
|
|
{
|
|
|
- int i, ltype;
|
|
|
+ int ltype;
|
|
|
struct line_pnts *Points;
|
|
|
struct line_cats *Cats;
|
|
|
- int cat;
|
|
|
- char text[100];
|
|
|
+ int ogr_centroids;
|
|
|
|
|
|
Points = Vect_new_line_struct();
|
|
|
Cats = Vect_new_cats_struct();
|
|
|
|
|
|
Vect_rewind(Map);
|
|
|
|
|
|
- while (1) {
|
|
|
+ ogr_centroids = FALSE;
|
|
|
+ if (Vect_maptype(Map) == GV_FORMAT_OGR) {
|
|
|
+ if (Vect_level(Map) < 2)
|
|
|
+ G_warning(_("Topology level required for drawing centroids "
|
|
|
+ "for OGR layers"));
|
|
|
+ else if (Vect_get_num_primitives(Map, GV_CENTROID) > 0 &&
|
|
|
+ type & GV_CENTROID)
|
|
|
+ /* label centroids from topo, don't label boundaries */
|
|
|
+ ogr_centroids = TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ while (TRUE) {
|
|
|
ltype = Vect_read_next_line(Map, Points, Cats);
|
|
|
- switch (ltype) {
|
|
|
- case -1:
|
|
|
- G_fatal_error(_("Unable to read vector map"));
|
|
|
- case -2: /* EOF */
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
+ if (ltype == -1)
|
|
|
+ G_fatal_error(_("Unable to read vector map"));
|
|
|
+ else if (ltype == -2) /* EOF */
|
|
|
+ break;
|
|
|
+
|
|
|
if (!(type & ltype))
|
|
|
continue; /* used for both lines and labels */
|
|
|
+
|
|
|
+ if (ogr_centroids && ltype == GV_BOUNDARY)
|
|
|
+ /* do not label boundaries */
|
|
|
+ continue;
|
|
|
|
|
|
- D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
|
|
|
- D_text_size(lattr->size, lattr->size);
|
|
|
- if (lattr->font)
|
|
|
- D_font(lattr->font);
|
|
|
- if (lattr->enc)
|
|
|
- D_encoding(lattr->enc);
|
|
|
-
|
|
|
- if (chcat) {
|
|
|
- int found = 0;
|
|
|
-
|
|
|
- for (i = 0; i < Cats->n_cats; i++) {
|
|
|
- if (Cats->field[i] == Clist->field &&
|
|
|
- Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
|
|
|
- found = 1;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!found)
|
|
|
- continue;
|
|
|
- }
|
|
|
- else if (Clist->field > 0) {
|
|
|
- int found = 0;
|
|
|
-
|
|
|
- for (i = 0; i < Cats->n_cats; i++) {
|
|
|
- if (Cats->field[i] == Clist->field) {
|
|
|
- found = 1;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- /* lines with no category will be displayed */
|
|
|
- if (Cats->n_cats > 0 && !found)
|
|
|
- continue;
|
|
|
- }
|
|
|
+ process_line(ltype, Points, Cats, lattr, chcat, Clist);
|
|
|
+ }
|
|
|
|
|
|
- if (Vect_cat_get(Cats, lattr->field, &cat)) {
|
|
|
- text[0] = '\0';
|
|
|
- for (i = 0; i < Cats->n_cats; i++) {
|
|
|
- G_debug(3, "cat lab: field = %d, cat = %d", Cats->field[i],
|
|
|
- Cats->cat[i]);
|
|
|
- if (Cats->field[i] == lattr->field) { /* all cats of given lfield */
|
|
|
- if (*text != '\0')
|
|
|
- sprintf(text, "%s/", text);
|
|
|
-
|
|
|
- sprintf(text, "%s%d", text, Cats->cat[i]);
|
|
|
- }
|
|
|
- }
|
|
|
- show_label_line(Points, ltype, lattr, text);
|
|
|
+ if (ogr_centroids) {
|
|
|
+ /* show label for centroids stored in topo (for OGR layers
|
|
|
+ only) */
|
|
|
+ int line, nlines;
|
|
|
+ struct bound_box box;
|
|
|
+ struct boxlist *list;
|
|
|
+
|
|
|
+ list = Vect_new_boxlist(FALSE); /* bboxes not needed */
|
|
|
+ Vect_get_constraint_box(Map, &box);
|
|
|
+ nlines = Vect_select_lines_by_box(Map, &box, GV_CENTROID, list);
|
|
|
+ G_debug(0, "ncentroids (ogr) = %d", nlines);
|
|
|
+
|
|
|
+ for (line = 0; line < nlines; line++) {
|
|
|
+ ltype = Vect_read_line(Map, Points, Cats, list->id[line]);
|
|
|
+ process_line(ltype, Points, Cats, lattr, chcat, Clist);
|
|
|
}
|
|
|
+ Vect_destroy_boxlist(list);
|
|
|
}
|
|
|
|
|
|
Vect_destroy_line_struct(Points);
|
|
@@ -87,6 +75,65 @@ int display_label(struct Map_info *Map, int type,
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+int process_line(int ltype, const struct line_pnts *Points,
|
|
|
+ const struct line_cats *Cats, LATTR *lattr,
|
|
|
+ int chcat, const struct cat_list *Clist)
|
|
|
+{
|
|
|
+ int i, cat;
|
|
|
+ char text[100];
|
|
|
+
|
|
|
+ D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
|
|
|
+ D_text_size(lattr->size, lattr->size);
|
|
|
+ if (lattr->font)
|
|
|
+ D_font(lattr->font);
|
|
|
+ if (lattr->enc)
|
|
|
+ D_encoding(lattr->enc);
|
|
|
+
|
|
|
+ if (chcat) {
|
|
|
+ int found = 0;
|
|
|
+
|
|
|
+ for (i = 0; i < Cats->n_cats; i++) {
|
|
|
+ if (Cats->field[i] == Clist->field &&
|
|
|
+ Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
|
|
|
+ found = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!found)
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ else if (Clist->field > 0) {
|
|
|
+ int found = 0;
|
|
|
+
|
|
|
+ for (i = 0; i < Cats->n_cats; i++) {
|
|
|
+ if (Cats->field[i] == Clist->field) {
|
|
|
+ found = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /* lines with no category will be displayed */
|
|
|
+ if (Cats->n_cats > 0 && !found)
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Vect_cat_get(Cats, lattr->field, &cat)) {
|
|
|
+ text[0] = '\0';
|
|
|
+ for (i = 0; i < Cats->n_cats; i++) {
|
|
|
+ G_debug(3, "cat lab: field = %d, cat = %d", Cats->field[i],
|
|
|
+ Cats->cat[i]);
|
|
|
+ if (Cats->field[i] == lattr->field) { /* all cats of given lfield */
|
|
|
+ if (*text != '\0')
|
|
|
+ sprintf(text, "%s/", text);
|
|
|
+
|
|
|
+ sprintf(text, "%s%d", text, Cats->cat[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ show_label_line(Points, ltype, lattr, text);
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
void show_label(double *px, double *py, LATTR *lattr, const char *text)
|
|
|
{
|
|
|
double X = *px, Y = *py;
|
|
@@ -141,7 +188,8 @@ void show_label(double *px, double *py, LATTR *lattr, const char *text)
|
|
|
D_text(text);
|
|
|
}
|
|
|
|
|
|
-void show_label_line(const struct line_pnts *Points, int ltype, LATTR *lattr, const char *text)
|
|
|
+void show_label_line(const struct line_pnts *Points, int ltype, LATTR *lattr,
|
|
|
+ const char *text)
|
|
|
{
|
|
|
double X, Y;
|
|
|
|