[GRASS-SVN] r56469 - in grass/trunk: include/defs lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 29 05:08:34 PDT 2013
Author: martinl
Date: 2013-05-29 05:08:34 -0700 (Wed, 29 May 2013)
New Revision: 56469
Modified:
grass/trunk/include/defs/vector.h
grass/trunk/lib/vector/Vlib/simple_features.c
Log:
vlib: add Vect_sfa_get_num_features()
Modified: grass/trunk/include/defs/vector.h
===================================================================
--- grass/trunk/include/defs/vector.h 2013-05-29 12:05:57 UTC (rev 56468)
+++ grass/trunk/include/defs/vector.h 2013-05-29 12:08:34 UTC (rev 56469)
@@ -461,6 +461,7 @@
int Vect_sfa_line_astext(const struct line_pnts *, int, int, int, FILE *);
int Vect_sfa_is_line_simple(const struct line_pnts *, int, int);
int Vect_sfa_is_line_closed(const struct line_pnts *, int, int);
+int Vect_sfa_get_num_features(const struct Map_info *);
/*
* Internal functions, MUST NOT be used in modules
Modified: grass/trunk/lib/vector/Vlib/simple_features.c
===================================================================
--- grass/trunk/lib/vector/Vlib/simple_features.c 2013-05-29 12:05:57 UTC (rev 56468)
+++ grass/trunk/lib/vector/Vlib/simple_features.c 2013-05-29 12:08:34 UTC (rev 56469)
@@ -20,7 +20,7 @@
Reference: http://www.opengeospatial.org/standards/sfa
- (C) 2009, 2011-2012 by the GRASS Development Team
+ (C) 2009, 2011-2013 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.
@@ -33,6 +33,14 @@
#include <grass/vector.h>
#include <grass/glocale.h>
+#ifdef HAVE_POSTGRES
+#include "pg_local_proto.h"
+#endif
+
+#ifdef HAVE_OGR
+#include <ogr_api.h>
+#endif
+
static int check_sftype(const struct line_pnts *, int, SF_FeatureType, int);
static int get_sftype(const struct line_pnts *, int, int);
static void print_point(const struct line_pnts *, int, int, int, FILE *);
@@ -272,6 +280,72 @@
return -1;
}
+/*!
+ \brief Get number of simple features
+
+ For native format or PostGIS Topology returns -1
+
+ \param Map vector map
+
+ \return number of features
+ \return -1 on error
+*/
+int Vect_sfa_get_num_features(const struct Map_info *Map)
+{
+ int nfeat;
+
+ nfeat = 0;
+ if (Map->format == GV_FORMAT_OGR || Map->format == GV_FORMAT_OGR_DIRECT) {
+ /* OGR */
+#ifdef HAVE_OGR
+ const struct Format_info_ogr *ogr_info;
+
+ ogr_info = &(Map->fInfo.ogr);
+
+ if (!ogr_info->layer)
+ return -1;
+
+ return OGR_L_GetFeatureCount(ogr_info->layer, TRUE);
+#else
+ G_fatal_error(_("GRASS is not compiled with OGR support"));
+ return -1;
+#endif
+ }
+ else if (Map->format == GV_FORMAT_POSTGIS && !Map->fInfo.pg.toposchema_name) {
+#ifdef HAVE_POSTGRES
+ /* PostGIS */
+ char stmt[DB_SQL_MAX];
+
+ const struct Format_info_pg *pg_info;
+
+ pg_info = &(Map->fInfo.pg);
+
+ if (!pg_info->conn || !pg_info->table_name) {
+ G_warning(_("No connection defined"));
+ return -1;
+ }
+
+ sprintf(stmt, "SELECT count(*) FROM \"%s\".%s", pg_info->schema_name,
+ pg_info->table_name);
+ nfeat = Vect__execute_get_value_pg(pg_info->conn, stmt);
+ if (nfeat < 0) {
+ G_warning(_("Unable to get number of simple features"));
+ return -1;
+ }
+#else
+ G_fatal_error(_("GRASS is not compiled with PostgreSQL support"));
+ return -1;
+#endif
+ }
+ else {
+ G_warning(_("Unable to report simple features for vector map <%s>"),
+ Vect_get_full_name(Map));
+ return -1;
+ }
+
+ return nfeat;
+}
+
int check_sftype(const struct line_pnts *points, int type,
SF_FeatureType sftype, int with_z)
{
More information about the grass-commit
mailing list