[GRASS-SVN] r44811 - in grass/trunk: lib/vector/Vlib raster/r.external vector/v.external

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 30 11:52:24 EST 2010


Author: martinl
Date: 2010-12-30 08:52:24 -0800 (Thu, 30 Dec 2010)
New Revision: 44811

Modified:
   grass/trunk/lib/vector/Vlib/header.c
   grass/trunk/lib/vector/Vlib/open.c
   grass/trunk/lib/vector/Vlib/open_ogr.c
   grass/trunk/raster/r.external/main.c
   grass/trunk/vector/v.external/list.c
   grass/trunk/vector/v.external/local_proto.h
   grass/trunk/vector/v.external/main.c
Log:
vlib: initial suppor for 3D vector data linked via OGR


Modified: grass/trunk/lib/vector/Vlib/header.c
===================================================================
--- grass/trunk/lib/vector/Vlib/header.c	2010-12-30 13:08:24 UTC (rev 44810)
+++ grass/trunk/lib/vector/Vlib/header.c	2010-12-30 16:52:24 UTC (rev 44811)
@@ -314,13 +314,39 @@
     Ogr_geom_type = OGR_FD_GetGeomType(Ogr_feature_defn);
     switch(Ogr_geom_type) {
     case wkbPoint:
-	return G_store(_("point"));
+	return G_store(_("Point"));
+    case wkbMultiPoint:
+	return G_store(_("MultiPoint"));
     case wkbLineString:
-	return G_store(_("linestring"));
+	return G_store(_("LineString"));
+    case wkbMultiLineString:
+	return G_store(_("MultiLineString"));
     case wkbPolygon:
-	return G_store(_("polygon"));
+	return G_store(_("Polygon"));
+    case wkbMultiPolygon:
+	return G_store(_("MultiPolygon"));
+    case wkbGeometryCollection:
+	return G_store(_("GeometryCollection"));
+    case wkbNone:
+	return G_store(_("None"));
+    case wkbLinearRing:
+	return G_store(_("LinearRing"));
+    case wkbPoint25D:
+	return G_store(_("3D Point"));
+    case wkbMultiPoint25D:
+	return G_store(_("3D MultiPoint"));
+    case wkbLineString25D:
+	return G_store(_("3D LineString"));
+    case wkbMultiLineString25D:
+	return G_store(_("3D MultiLineString"));
+    case wkbPolygon25D:
+	return G_store(_("3D Polygon"));
+    case wkbMultiPolygon25D:
+	return G_store(_("3D MultiPolygon"));
+    case wkbGeometryCollection25D:
+	return G_store(_("3D GeometryCollection"));
     default:
-	return G_store(_("unknown"));
+	return G_store(_("Unknown"));
     }
 #endif
     return NULL;
@@ -329,6 +355,8 @@
 /*!
    \brief Check if vector map is 3D
 
+   Check vector map header.
+
    \param Map pointer to Map_info structure
 
    \return TRUE  vector map is 3D

Modified: grass/trunk/lib/vector/Vlib/open.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open.c	2010-12-30 13:08:24 UTC (rev 44810)
+++ grass/trunk/lib/vector/Vlib/open.c	2010-12-30 16:52:24 UTC (rev 44811)
@@ -177,17 +177,17 @@
     /* initialize Map->head */
     Vect__init_head(Map);
     /* initialize support structures for 2D, update to 3D when reading support files */
-    Map->plus.spidx_with_z = Map->plus.with_z = Map->head.with_z = 0;
+    Map->plus.spidx_with_z = Map->plus.with_z = Map->head.with_z = WITHOUT_Z;
     /* initialize Map->plus */
     dig_init_plus(&(Map->plus));
 
     /* check OGR mapset */
-    ogr_mapset = 0;
+    ogr_mapset = FALSE;
     if (G_name_is_fully_qualified(name, xname, xmapset)) {
 	if (strcasecmp(xmapset, "ogr") == 0) {
 	    /* unique OGR mapset detected */
 	    G_debug(1, "OGR mapset detected");
-	    ogr_mapset = 1;
+	    ogr_mapset = TRUE;
 	    Map->fInfo.ogr.dsn = G_store(xname);
 	    if (layer) {
 		Map->fInfo.ogr.layer_name = G_store(layer); /* no layer to be open */
@@ -491,7 +491,7 @@
 	    unlink(file_path);
     }
 
-    return (level);
+    return level;
 }
 
 /*!
@@ -920,7 +920,7 @@
  * \brief Open topology file ('topo')
  *
  * \param[in,out] Map pointer to Map_info structure
- * \param head_only open only head
+ * \param head_only TRUE to read only header
  *
  * \return 0 on success
  * \return 1 file does not exist

Modified: grass/trunk/lib/vector/Vlib/open_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open_ogr.c	2010-12-30 13:08:24 UTC (rev 44810)
+++ grass/trunk/lib/vector/Vlib/open_ogr.c	2010-12-30 16:52:24 UTC (rev 44811)
@@ -37,8 +37,7 @@
    Map->fInfo.ogr.layer_name must be set before.
 
    \param[in,out] Map pointer to Map_info structure
-   \param update non-zero for write mode, otherwise read-only
-   (write mode is currently not supported)
+   \param update TRUE for write mode, otherwise read-only
    
    \return 0 success
    \return -1 error
@@ -49,15 +48,10 @@
     OGRDataSourceH Ogr_ds;
     OGRLayerH Ogr_layer;
     OGRFeatureDefnH Ogr_featuredefn;
-
+    OGRwkbGeometryType Ogr_geom_type;
+    
     Ogr_layer = NULL;
-
-    /*
-    if (update) {
-	G_warning(_("Write mode is not supported for OGR format"));
-	return -1;
-    }
-    */
+    Ogr_geom_type = wkbUnknown;
     
     if (!Map->fInfo.ogr.dsn) {
 	G_fatal_error(_("OGR datasource not defined"));
@@ -90,6 +84,7 @@
 	Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
 	Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
 	if (strcmp(OGR_FD_GetName(Ogr_featuredefn), Map->fInfo.ogr.layer_name) == 0) {
+	    Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
 	    layer = i;
 	    break;
 	}
@@ -109,12 +104,21 @@
     Map->fInfo.ogr.lines_num = 0;
     Map->fInfo.ogr.lines_next = 0;
     
-    Map->head.with_z = WITHOUT_Z;	/* TODO: 3D */
+    switch(Ogr_geom_type) {
+    case wkbPoint25D: case wkbLineString25D: case wkbPolygon25D:
+    case wkbMultiPoint25D: case wkbMultiLineString25D: case wkbMultiPolygon25D:
+    case wkbGeometryCollection25D:
+	Map->head.with_z = WITH_Z;
+	break;
+    default:
+	Map->head.with_z = WITHOUT_Z;
+	break;
+    }
     
     Map->fInfo.ogr.feature_cache = NULL;
     Map->fInfo.ogr.feature_cache_id = -1;	/* FID >= 0 */
     
-    return (0);
+    return 0;
 }
 
 /*!
@@ -219,7 +223,7 @@
     OGRDataSourceH  Ogr_ds;
     OGRLayerH       Ogr_layer;
     OGRFeatureDefnH Ogr_featuredefn;
-
+    
     int            i, nlayers;
     char         **Ogr_layer_options;
      

Modified: grass/trunk/raster/r.external/main.c
===================================================================
--- grass/trunk/raster/r.external/main.c	2010-12-30 13:08:24 UTC (rev 44810)
+++ grass/trunk/raster/r.external/main.c	2010-12-30 16:52:24 UTC (rev 44811)
@@ -57,7 +57,7 @@
     /* -------------------------------------------------------------------- */
     int iDr;
 
-    fprintf(stdout, _("Supported Formats:\n"));
+    G_message(_("Supported formats:"));
     for (iDr = 0; iDr < GDALGetDriverCount(); iDr++) {
 	GDALDriverH hDriver = GDALGetDriver(iDr);
 	const char *pszRWFlag;
@@ -69,7 +69,7 @@
 	else
 	    pszRWFlag = "ro";
 
-	fprintf(stdout, "  %s (%s): %s\n",
+	fprintf(stdout, " %s (%s): %s\n",
 		GDALGetDriverShortName(hDriver),
 		pszRWFlag, GDALGetDriverLongName(hDriver));
     }

Modified: grass/trunk/vector/v.external/list.c
===================================================================
--- grass/trunk/vector/v.external/list.c	2010-12-30 13:08:24 UTC (rev 44810)
+++ grass/trunk/vector/v.external/list.c	2010-12-30 16:52:24 UTC (rev 44811)
@@ -1,4 +1,5 @@
 #include <grass/gis.h>
+#include <grass/vector.h>
 #include <grass/glocale.h>
 
 #include "ogr_api.h"
@@ -9,14 +10,14 @@
     
     OGRSFDriverH Ogr_driver;
     
-    G_message(_("Available drivers:\n"));
+    G_message(_("Supported formats:"));
     for (i = 0; i < OGRGetDriverCount(); i++) {
 	Ogr_driver = OGRGetDriver(i);
 	fprintf(fd, " %s\n", OGR_Dr_GetName(Ogr_driver));
     }
 }
 
-int list_layers(FILE *fd, const char *dsn, const char *layer)
+int list_layers(FILE *fd, const char *dsn, const char *layer, int *is3D)
 {
     int i, ret;
     int nlayers;
@@ -25,6 +26,7 @@
     OGRDataSourceH Ogr_ds;
     OGRLayerH Ogr_layer;
     OGRFeatureDefnH Ogr_featuredefn;
+    OGRwkbGeometryType Ogr_geom_type;
     
     ret = -1;
     
@@ -50,6 +52,19 @@
 	
 	if (layer)
 	    if (strcmp(layer_name, layer) == 0) {
+		if (is3D) {
+		    Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
+		    switch(Ogr_geom_type) {
+		    case wkbPoint25D: case wkbLineString25D: case wkbPolygon25D:
+		    case wkbMultiPoint25D: case wkbMultiLineString25D: case wkbMultiPolygon25D:
+		    case wkbGeometryCollection25D:
+			*is3D = WITH_Z;
+			break;
+		    default:
+			*is3D = WITHOUT_Z;
+			break;
+		    }
+		}
 		ret = i;
 	    }
     }

Modified: grass/trunk/vector/v.external/local_proto.h
===================================================================
--- grass/trunk/vector/v.external/local_proto.h	2010-12-30 13:08:24 UTC (rev 44810)
+++ grass/trunk/vector/v.external/local_proto.h	2010-12-30 16:52:24 UTC (rev 44811)
@@ -18,6 +18,6 @@
 
 /* list.c */
 void list_formats(FILE *);
-int list_layers(FILE *, const char *, const char *);
+int list_layers(FILE *, const char *, const char *, int *);
 
 #endif

Modified: grass/trunk/vector/v.external/main.c
===================================================================
--- grass/trunk/vector/v.external/main.c	2010-12-30 13:08:24 UTC (rev 44810)
+++ grass/trunk/vector/v.external/main.c	2010-12-30 16:52:24 UTC (rev 44811)
@@ -8,7 +8,7 @@
  *               
  * PURPOSE:      Create a new vector as a link to OGR layer (read-only)
  *               
- * COPYRIGHT:    (C) 2003-2009 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2003-2010 by the GRASS Development Team
  *
  *               This program is free software under the 
  *               GNU General Public License (>=v2). 
@@ -39,7 +39,7 @@
     
     FILE *fd;
     
-    int ilayer;
+    int ilayer, is3D;
     char buf[GPATH_MAX];
      
     G_gisinit(argv[0]);
@@ -64,7 +64,7 @@
     if (flags.layer->answer) {
 	if (!options.dsn->answer)
 	    G_fatal_error(_("Required parameter <%s> not set"), options.dsn->key);
-	list_layers(stdout, options.dsn->answer, NULL);
+	list_layers(stdout, options.dsn->answer, NULL, NULL);
 	exit(EXIT_SUCCESS);
     }
 
@@ -75,15 +75,14 @@
 	G_fatal_error(_("Required parameter <%s> not set"), options.layer->key);
         
 
-    ilayer = list_layers(NULL, options.dsn->answer, options.layer->answer);
+    ilayer = list_layers(NULL, options.dsn->answer, options.layer->answer, &is3D);
     if (ilayer == -1) {
 	G_fatal_error(_("Layer <%s> not available"), options.layer->answer);
     }
     
     G_debug(2, "layer '%s' was found", options.layer->answer);
 
-    /* TODO: support 3d vector data */
-    Vect_open_new(&Map, options.output->answer, WITHOUT_Z);
+    Vect_open_new(&Map, options.output->answer, is3D);
     Vect_hist_command(&Map);
     Vect_close(&Map);
     
@@ -116,7 +115,7 @@
       Vect_close(&Map);
     }
 
-    G_done_msg(_("<%s> created."), options.output->answer);
+    G_done_msg(_("Link to vector map <%s> created."), options.output->answer);
 
     exit(EXIT_SUCCESS);
 }



More information about the grass-commit mailing list