예제 #1
0
/*!
   \brief Read spatial index from sidx file
   Only needed when old vector is opened in update mode

   \param fp pointer to struct gvfile
   \param[in,out] Plus pointer to Plus_head structure

   \return 0
 */
int dig_Rd_spidx(struct gvfile * fp, struct Plus_head *Plus)
{
    G_debug(1, "dig_read_spindx()");

    /* free old trees, init new trees */
    dig_spidx_free(Plus);
    dig_spidx_init(Plus);

    dig_rewind(fp);
    dig_Rd_spidx_head(fp, Plus);
    dig_set_cur_port(&(Plus->spidx_port));

    /* Nodes */
    rtree_load_from_sidx(fp, Plus->Node_spidx_offset,
			 Plus->Node_spidx, Plus->spidx_port.off_t_size);

    /* Lines */
    rtree_load_from_sidx(fp, Plus->Line_spidx_offset,
			 Plus->Line_spidx, Plus->spidx_port.off_t_size);

    /* Areas */
    rtree_load_from_sidx(fp, Plus->Area_spidx_offset,
			 Plus->Area_spidx, Plus->spidx_port.off_t_size);

    /* Isles */
    rtree_load_from_sidx(fp, Plus->Isle_spidx_offset,
			 Plus->Isle_spidx, Plus->spidx_port.off_t_size);

    /* 3D future : */
    /* Faces */
    /* Volumes */
    /* Holes */

    return 0;
}
예제 #2
0
파일: close.c 프로젝트: imincik/pkg-grass
/*!
   \brief Close vector data file

   \param Map vector map to be closed

   \return 0 on success
   \return non-zero on error
 */
int Vect_close(struct Map_info *Map)
{
    struct Coor_info CInfo;

    G_debug(1,
	    "Vect_close(): name = %s, mapset = %s, format = %d, level = %d",
	    Map->name, Map->mapset, Map->format, Map->level);

    /* Store support files if in write mode on level 2 */
    if (strcmp(Map->mapset, G_mapset()) == 0 && Map->support_updated &&
	Map->plus.built == GV_BUILD_ALL) {
	char buf[GPATH_MAX];
	char file_path[GPATH_MAX];
	struct stat info;

	/* Delete old support files if available */
	sprintf(buf, "%s/%s", GRASS_VECT_DIRECTORY, Map->name);

	G__file_name(file_path, buf, GV_TOPO_ELEMENT, G_mapset());
	if (stat(file_path, &info) == 0)	/* file exists? */
	    unlink(file_path);

	G__file_name(file_path, buf, GV_SIDX_ELEMENT, G_mapset());
	if (stat(file_path, &info) == 0)	/* file exists? */
	    unlink(file_path);

	G__file_name(file_path, buf, GV_CIDX_ELEMENT, G_mapset());
	if (stat(file_path, &info) == 0)	/* file exists? */
	    unlink(file_path);

	Vect_coor_info(Map, &CInfo);
	Map->plus.coor_size = CInfo.size;
	Map->plus.coor_mtime = CInfo.mtime;

	Vect_save_topo(Map);

	/* Spatial index is not saved */
	/* Vect_save_spatial_index ( Map ); */

	Vect_cidx_save(Map);

#ifdef HAVE_OGR
	if (Map->format == GV_FORMAT_OGR)
	    V2_close_ogr(Map);
#endif
    }

    if (Map->level == 2 && Map->plus.release_support) {
	G_debug(1, "free topology");
	dig_free_plus(&(Map->plus));

	if (!Map->head_only) {
	    G_debug(1, "free spatial index");
	    dig_spidx_free(&(Map->plus));
	}

	G_debug(1, "free category index");
	dig_cidx_free(&(Map->plus));

    }

    if (Map->format == GV_FORMAT_NATIVE) {
	G_debug(1, "close history file");
	if (Map->hist_fp != NULL)
	    fclose(Map->hist_fp);
    }

    /* Close level 1 files / data sources if not head_only */
    if (!Map->head_only) {
	if (((*Close_array[Map->format][1]) (Map)) != 0) {
	    G_warning(_("Unable to close vector <%s>"),
		      Vect_get_full_name(Map));
	    return 1;
	}
    }

    G_free((void *)Map->name);
    Map->name = NULL;
    G_free((void *)Map->mapset);
    Map->mapset = NULL;

    Map->open = VECT_CLOSED_CODE;

    return 0;
}