[GRASS-SVN] r51956 - in grass/trunk: include/defs lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jun 3 09:36:19 PDT 2012
Author: martinl
Date: 2012-06-03 09:36:19 -0700 (Sun, 03 Jun 2012)
New Revision: 51956
Added:
grass/trunk/lib/vector/Vlib/header_finfo.c
Modified:
grass/trunk/include/defs/vector.h
grass/trunk/lib/vector/Vlib/header.c
Log:
vlib: separate fInfo-related subroutines into header_finfo.c
introduced Vect_get_finfo_geometry_column()
Modified: grass/trunk/include/defs/vector.h
===================================================================
--- grass/trunk/include/defs/vector.h 2012-06-03 13:40:45 UTC (rev 51955)
+++ grass/trunk/include/defs/vector.h 2012-06-03 16:36:19 UTC (rev 51956)
@@ -164,6 +164,7 @@
char *Vect_get_finfo_layer_name(const struct Map_info *);
const char *Vect_get_finfo_format_info(const struct Map_info *);
const char *Vect_get_finfo_geometry_type(const struct Map_info *);
+const char *Vect_get_finfo_geometry_column(const struct Map_info *);
int Vect_is_3d(const struct Map_info *);
int Vect_set_organization(struct Map_info *, const char *);
const char *Vect_get_organization(const struct Map_info *);
Modified: grass/trunk/lib/vector/Vlib/header.c
===================================================================
--- grass/trunk/lib/vector/Vlib/header.c 2012-06-03 13:40:45 UTC (rev 51955)
+++ grass/trunk/lib/vector/Vlib/header.c 2012-06-03 16:36:19 UTC (rev 51956)
@@ -251,188 +251,6 @@
}
/*!
- \brief Get datasource name (relevant only for non-native formats)
-
- Returns:
- - datasource name for OGR format (GV_FORMAT_OGR and GV_FORMAT_OGR_DIRECT)
- - database name for PostGIS format (GV_FORMAT_POSTGIS)
-
- \param Map pointer to Map_info structure
-
- \return string containing OGR/PostGIS datasource name
- \return NULL on error (map format is native)
- */
-const char *Vect_get_finfo_dsn_name(const struct Map_info *Map)
-{
- if (Map->format == GV_FORMAT_OGR ||
- Map->format == GV_FORMAT_OGR_DIRECT) {
-#ifndef HAVE_OGR
- G_warning(_("GRASS is not compiled with OGR support"));
-#endif
- return Map->fInfo.ogr.dsn;
- }
- else if (Map->format == GV_FORMAT_POSTGIS) {
-#ifndef HAVE_POSTGRES
- G_warning(_("GRASS is not compiled with PostgreSQL support"));
-#endif
- return Map->fInfo.pg.db_name;
- }
-
- G_warning(_("Native vector format detected for <%s>"),
- Vect_get_full_name(Map));
-
- return NULL;
-}
-
-/*!
- \brief Get layer name (relevant only for non-native formats)
-
- Returns:
- - layer name for OGR format (GV_FORMAT_OGR and GV_FORMAT_OGR_DIRECT)
- - table name for PostGIS format (GV_FORMAT_POSTGIS)
-
- Note: allocated string should be freed by G_free()
-
- \param Map pointer to Map_info structure
-
- \return string containing layer name
- \return NULL on error (map format is native)
- */
-char *Vect_get_finfo_layer_name(const struct Map_info *Map)
-{
- char *name;
-
- name = NULL;
- if (Map->format == GV_FORMAT_OGR ||
- Map->format == GV_FORMAT_OGR_DIRECT) {
-#ifndef HAVE_OGR
- G_warning(_("GRASS is not compiled with OGR support"));
-#endif
- name = G_store(Map->fInfo.ogr.layer_name);
- }
- else if (Map->format == GV_FORMAT_POSTGIS) {
-#ifndef HAVE_POSTGRES
- G_warning(_("GRASS is not compiled with PostgreSQL support"));
-#endif
- G_asprintf(&name, "%s.%s", Map->fInfo.pg.schema_name,
- Map->fInfo.pg.table_name);
- }
- else {
- G_warning(_("Native vector format detected for <%s>"),
- Vect_get_full_name(Map));
- }
-
- return name;
-}
-
-/*!
- \brief Get format info (relevant only for non-native formats)
-
- Returns:
- - layer name for OGR format (GV_FORMAT_OGR and GV_FORMAT_OGR_DIRECT)
-
- \param Map pointer to Map_info structure
-
- \return string containing name of OGR format (allocated by G_store())
- \return NULL on error (or on missing OGR/PostgreSQL support)
-*/
-const char *Vect_get_finfo_format_info(const struct Map_info *Map)
-{
- if (Map->format == GV_FORMAT_OGR ||
- Map->format == GV_FORMAT_OGR_DIRECT) {
-#ifndef HAVE_OGR
- G_warning(_("GRASS is not compiled with OGR support"));
-#else
- if (!Map->fInfo.ogr.ds)
- return NULL;
-
- return OGR_Dr_GetName(OGR_DS_GetDriver(Map->fInfo.ogr.ds));
-#endif
- }
- else if (Map->format == GV_FORMAT_POSTGIS) {
-#ifndef HAVE_OGR
- G_warning(_("GRASS is not compiled with PostgreSQL support"));
-#else
- return "PostgreSQL";
-#endif
- }
-
- return NULL;
-}
-
-/*!
- \brief Get geometry type (relevant only for non-native formats)
-
- Note: All inner spaces are removed, function returns feature type in
- lowercase.
-
- \param Map pointer to Map_info structure
-
- \return allocated string containing geometry type info
- (point, linestring, polygon, ...)
- \return NULL on error (map format is native)
-*/
-const char *Vect_get_finfo_geometry_type(const struct Map_info *Map)
-{
- char *ftype, *ftype_tmp;
-
- ftype_tmp = ftype = NULL;
- if (Map->format == GV_FORMAT_OGR ||
- Map->format == GV_FORMAT_OGR_DIRECT) {
-#ifndef HAVE_OGR
- G_warning(_("GRASS is not compiled with OGR support"));
-#else
- OGRwkbGeometryType Ogr_geom_type;
- OGRFeatureDefnH Ogr_feature_defn;
-
- if (!Map->fInfo.ogr.layer)
- return NULL;
-
- Ogr_feature_defn = OGR_L_GetLayerDefn(Map->fInfo.ogr.layer);
- Ogr_geom_type = wkbFlatten(OGR_FD_GetGeomType(Ogr_feature_defn));
-
- ftype_tmp = G_store(OGRGeometryTypeToName(Ogr_geom_type));
-#endif
- }
- else if (Map->format == GV_FORMAT_POSTGIS) {
-#ifndef HAVE_POSTGRES
- G_warning(_("GRASS is not compiled with PostgreSQL support"));
-#else
- char stmt[DB_SQL_MAX];
-
- const struct Format_info_pg *pg_info;
-
- PGresult *res;
-
- pg_info = &(Map->fInfo.pg);
- sprintf(stmt, "SELECT type FROM geometry_columns "
- "WHERE f_table_schema = '%s' AND f_table_name = '%s'",
- pg_info->schema_name, pg_info->table_name);
- G_debug(2, "SQL: %s", stmt);
-
- res = PQexec(pg_info->conn, stmt);
- if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
- PQntuples(res) != 1) {
- G_warning("%s\n%s", _("Unable to get feature type"),
- PQresultErrorMessage(res));
- return NULL;
- }
- ftype_tmp = G_store(PQgetvalue(res, 0, 0));
- PQclear(res);
-#endif
- }
-
- if (!ftype_tmp)
- return NULL;
-
- ftype = G_str_replace(ftype_tmp, " ", "");
- G_free(ftype_tmp);
- G_str_to_lower(ftype);
-
- return ftype;
-}
-
-/*!
\brief Check if vector map is 3D
Check vector map header.
@@ -773,13 +591,3 @@
G_debug(1, "Vect_get_thresh(): thresh = %f", Map->head.digit_thresh);
return Map->head.digit_thresh;
}
-
-
-/* from lib/gis/proj3.c */
-static int lookup(const char *file, const char *key, char *value, size_t len)
-{
- char path[GPATH_MAX];
-
- G_file_name(path, "", file, "PERMANENT");
- return G_lookup_key_value_from_file(path, key, value, (int) len) == 1;
-}
Added: grass/trunk/lib/vector/Vlib/header_finfo.c
===================================================================
--- grass/trunk/lib/vector/Vlib/header_finfo.c (rev 0)
+++ grass/trunk/lib/vector/Vlib/header_finfo.c 2012-06-03 16:36:19 UTC (rev 51956)
@@ -0,0 +1,222 @@
+/*!
+ \file lib/vector/Vlib/header_finfo.c
+
+ \brief Vector library - header manipulation (external formats)
+
+ Higher level functions for reading/writing/manipulating vectors.
+
+ (C) 2001-2010, 2012 by the GRASS Development Team
+
+ This program is free software under the GNU General Public License
+ (>=v2). Read the file COPYING that comes with GRASS for details.
+
+ \author Original author CERL, probably Dave Gerdes or Mike Higgins.
+ \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
+ \author Update to GRASS 7 (OGR support) by Martin Landa <landa.martin gmail.com>
+*/
+
+#include <grass/vector.h>
+#include <grass/glocale.h>
+
+/*!
+ \brief Get datasource name (relevant only for non-native formats)
+
+ Returns:
+ - datasource name for OGR format (GV_FORMAT_OGR and GV_FORMAT_OGR_DIRECT)
+ - database name for PostGIS format (GV_FORMAT_POSTGIS)
+
+ \param Map pointer to Map_info structure
+
+ \return string containing OGR/PostGIS datasource name
+ \return NULL on error (map format is native)
+ */
+const char *Vect_get_finfo_dsn_name(const struct Map_info *Map)
+{
+ if (Map->format == GV_FORMAT_OGR ||
+ Map->format == GV_FORMAT_OGR_DIRECT) {
+#ifndef HAVE_OGR
+ G_warning(_("GRASS is not compiled with OGR support"));
+#endif
+ return Map->fInfo.ogr.dsn;
+ }
+ else if (Map->format == GV_FORMAT_POSTGIS) {
+#ifndef HAVE_POSTGRES
+ G_warning(_("GRASS is not compiled with PostgreSQL support"));
+#endif
+ return Map->fInfo.pg.db_name;
+ }
+
+ G_warning(_("Native vector format detected for <%s>"),
+ Vect_get_full_name(Map));
+
+ return NULL;
+}
+
+/*!
+ \brief Get layer name (relevant only for non-native formats)
+
+ Returns:
+ - layer name for OGR format (GV_FORMAT_OGR and GV_FORMAT_OGR_DIRECT)
+ - table name for PostGIS format (GV_FORMAT_POSTGIS)
+
+ Note: allocated string should be freed by G_free()
+
+ \param Map pointer to Map_info structure
+
+ \return string containing layer name
+ \return NULL on error (map format is native)
+ */
+char *Vect_get_finfo_layer_name(const struct Map_info *Map)
+{
+ char *name;
+
+ name = NULL;
+ if (Map->format == GV_FORMAT_OGR ||
+ Map->format == GV_FORMAT_OGR_DIRECT) {
+#ifndef HAVE_OGR
+ G_warning(_("GRASS is not compiled with OGR support"));
+#endif
+ name = G_store(Map->fInfo.ogr.layer_name);
+ }
+ else if (Map->format == GV_FORMAT_POSTGIS) {
+#ifndef HAVE_POSTGRES
+ G_warning(_("GRASS is not compiled with PostgreSQL support"));
+#endif
+ G_asprintf(&name, "%s.%s", Map->fInfo.pg.schema_name,
+ Map->fInfo.pg.table_name);
+ }
+ else {
+ G_warning(_("Native vector format detected for <%s>"),
+ Vect_get_full_name(Map));
+ }
+
+ return name;
+}
+
+/*!
+ \brief Get format info (relevant only for non-native formats)
+
+ Returns:
+ - layer name for OGR format (GV_FORMAT_OGR and GV_FORMAT_OGR_DIRECT)
+
+ \param Map pointer to Map_info structure
+
+ \return string containing name of OGR format (allocated by G_store())
+ \return NULL on error (or on missing OGR/PostgreSQL support)
+*/
+const char *Vect_get_finfo_format_info(const struct Map_info *Map)
+{
+ if (Map->format == GV_FORMAT_OGR ||
+ Map->format == GV_FORMAT_OGR_DIRECT) {
+#ifndef HAVE_OGR
+ G_warning(_("GRASS is not compiled with OGR support"));
+#else
+ if (!Map->fInfo.ogr.ds)
+ return NULL;
+
+ return OGR_Dr_GetName(OGR_DS_GetDriver(Map->fInfo.ogr.ds));
+#endif
+ }
+ else if (Map->format == GV_FORMAT_POSTGIS) {
+#ifndef HAVE_OGR
+ G_warning(_("GRASS is not compiled with PostgreSQL support"));
+#else
+ return "PostgreSQL";
+#endif
+ }
+
+ return NULL;
+}
+
+/*!
+ \brief Get geometry type (relevant only for non-native formats)
+
+ Note: All inner spaces are removed, function returns feature type in
+ lowercase.
+
+ \param Map pointer to Map_info structure
+
+ \return allocated string containing geometry type info
+ (point, linestring, polygon, ...)
+ \return NULL on error (map format is native)
+*/
+const char *Vect_get_finfo_geometry_type(const struct Map_info *Map)
+{
+ char *ftype, *ftype_tmp;
+
+ ftype_tmp = ftype = NULL;
+ if (Map->format == GV_FORMAT_OGR ||
+ Map->format == GV_FORMAT_OGR_DIRECT) {
+#ifndef HAVE_OGR
+ G_warning(_("GRASS is not compiled with OGR support"));
+#else
+ OGRwkbGeometryType Ogr_geom_type;
+ OGRFeatureDefnH Ogr_feature_defn;
+
+ if (!Map->fInfo.ogr.layer)
+ return NULL;
+
+ Ogr_feature_defn = OGR_L_GetLayerDefn(Map->fInfo.ogr.layer);
+ Ogr_geom_type = wkbFlatten(OGR_FD_GetGeomType(Ogr_feature_defn));
+
+ ftype_tmp = G_store(OGRGeometryTypeToName(Ogr_geom_type));
+#endif
+ }
+ else if (Map->format == GV_FORMAT_POSTGIS) {
+#ifndef HAVE_POSTGRES
+ G_warning(_("GRASS is not compiled with PostgreSQL support"));
+#else
+ char stmt[DB_SQL_MAX];
+
+ const struct Format_info_pg *pg_info;
+
+ PGresult *res;
+
+ pg_info = &(Map->fInfo.pg);
+ sprintf(stmt, "SELECT type FROM geometry_columns "
+ "WHERE f_table_schema = '%s' AND f_table_name = '%s'",
+ pg_info->schema_name, pg_info->table_name);
+ G_debug(2, "SQL: %s", stmt);
+
+ res = PQexec(pg_info->conn, stmt);
+ if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
+ PQntuples(res) != 1) {
+ G_warning("%s\n%s", _("Unable to get feature type"),
+ PQresultErrorMessage(res));
+ return NULL;
+ }
+ ftype_tmp = G_store(PQgetvalue(res, 0, 0));
+ PQclear(res);
+#endif
+ }
+
+ if (!ftype_tmp)
+ return NULL;
+
+ ftype = G_str_replace(ftype_tmp, " ", "");
+ G_free(ftype_tmp);
+ G_str_to_lower(ftype);
+
+ return ftype;
+}
+
+/*!
+ \brief Get geometry column (relevant only for non-native DB formats)
+
+ \param Map pointer to Map_info structure
+
+ \return allocated string with geometry column name
+ \return NULL on error (map format is native)
+*/
+const char *Vect_get_finfo_geometry_column(const struct Map_info *Map)
+{
+ if (Map->format == GV_FORMAT_POSTGIS) {
+#ifndef HAVE_POSTGRES
+ G_warning(_("GRASS is not compiled with PostgreSQL support"));
+#else
+ return Map->fInfo.pg.geom_column;
+#endif
+ }
+
+ return NULL;
+}
Property changes on: grass/trunk/lib/vector/Vlib/header_finfo.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list