/*! \brief Reads feature from OGR layer (topology level) This function implements random access on level 2. \param Map pointer to Map_info structure \param[out] line_p container used to store line points within \param[out] line_c container used to store line categories within \param line feature id \return feature type \return -2 no more features \return -1 out of memory */ int V2_read_line_ogr(struct Map_info *Map, struct line_pnts *line_p, struct line_cats *line_c, int line) { struct P_line *Line; G_debug(4, "V2_read_line_ogr() line = %d", line); Line = Map->plus.Line[line]; if (Line == NULL) G_fatal_error(_("Attempt to read dead feature %d"), line); if (Line->type == GV_CENTROID) { G_debug(4, "Centroid"); if (line_p != NULL) { int i, found; struct bound_box box; struct boxlist list; struct P_topo_c *topo = (struct P_topo_c *)Line->topo; /* get area bbox */ Vect_get_area_box(Map, topo->area, &box); /* search in spatial index for centroid with area bbox */ dig_init_boxlist(&list, 1); Vect_select_lines_by_box(Map, &box, Line->type, &list); found = 0; for (i = 0; i < list.n_values; i++) { if (list.id[i] == line) { found = i; break; } } Vect_reset_line(line_p); Vect_append_point(line_p, list.box[found].E, list.box[found].N, 0.0); } if (line_c != NULL) { /* cat = FID and offset = FID for centroid */ Vect_reset_cats(line_c); Vect_cat_set(line_c, 1, (int) Line->offset); } return GV_CENTROID; } return V1_read_line_ogr(Map, line_p, line_c, Line->offset); }
/*! \brief Rewrites feature at the given offset (level 1) \param Map pointer to Map_info structure \param offset feature offset \param type feature type \param points feature geometry \param cats feature categories \return feature offset (rewriten feature) \return -1 on error */ off_t V1_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 != V1_read_line_ogr(Map, NULL, NULL, offset)) { G_warning(_("Unable to rewrite feature (incompatible feature types)")); return -1; } /* delete old */ V1_delete_line_ogr(Map, offset); return V1_write_line_ogr(Map, type, points, cats); }
/*! \brief Rewrites feature at the given offset on level 1 (OGR interface) This function simply calls V1_delete_line_ogr() and V1_write_line_ogr(). \param Map pointer to Map_info structure \param offset feature offset \param type feature type (see V1_write_line_ogr() for supported types) \param points pointer to line_pnts structure (feature geometry) \param cats pointer to line_cats structure (feature categories) \return feature offset (rewriten feature) \return -1 on error */ off_t V1_rewrite_line_ogr(struct Map_info *Map, int line, int type, off_t offset, const struct line_pnts *points, const struct line_cats *cats) { G_debug(3, "V1_rewrite_line_ogr(): line=%d type=%d offset=%"PRI_OFF_T, line, type, offset); #ifdef HAVE_OGR if (type != V1_read_line_ogr(Map, NULL, NULL, offset)) { G_warning(_("Unable to rewrite feature (incompatible feature types)")); return -1; } /* delete old */ V1_delete_line_ogr(Map, offset); return V1_write_line_ogr(Map, type, points, cats); #else G_fatal_error(_("GRASS is not compiled with OGR support")); return -1; #endif }