瀏覽代碼

vlib: initial suppor for 3D vector data linked via OGR

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@44811 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 14 年之前
父節點
當前提交
cef35690cf

+ 32 - 4
lib/vector/Vlib/header.c

@@ -314,13 +314,39 @@ const char *Vect_get_ogr_geometry_type(const struct Map_info *Map)
     Ogr_geom_type = OGR_FD_GetGeomType(Ogr_feature_defn);
     Ogr_geom_type = OGR_FD_GetGeomType(Ogr_feature_defn);
     switch(Ogr_geom_type) {
     switch(Ogr_geom_type) {
     case wkbPoint:
     case wkbPoint:
-	return G_store(_("point"));
+	return G_store(_("Point"));
+    case wkbMultiPoint:
+	return G_store(_("MultiPoint"));
     case wkbLineString:
     case wkbLineString:
-	return G_store(_("linestring"));
+	return G_store(_("LineString"));
+    case wkbMultiLineString:
+	return G_store(_("MultiLineString"));
     case wkbPolygon:
     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:
     default:
-	return G_store(_("unknown"));
+	return G_store(_("Unknown"));
     }
     }
 #endif
 #endif
     return NULL;
     return NULL;
@@ -329,6 +355,8 @@ const char *Vect_get_ogr_geometry_type(const struct Map_info *Map)
 /*!
 /*!
    \brief Check if vector map is 3D
    \brief Check if vector map is 3D
 
 
+   Check vector map header.
+
    \param Map pointer to Map_info structure
    \param Map pointer to Map_info structure
 
 
    \return TRUE  vector map is 3D
    \return TRUE  vector map is 3D

+ 5 - 5
lib/vector/Vlib/open.c

@@ -177,17 +177,17 @@ int Vect__open_old(struct Map_info *Map, const char *name, const char *mapset, c
     /* initialize Map->head */
     /* initialize Map->head */
     Vect__init_head(Map);
     Vect__init_head(Map);
     /* initialize support structures for 2D, update to 3D when reading support files */
     /* 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 */
     /* initialize Map->plus */
     dig_init_plus(&(Map->plus));
     dig_init_plus(&(Map->plus));
 
 
     /* check OGR mapset */
     /* check OGR mapset */
-    ogr_mapset = 0;
+    ogr_mapset = FALSE;
     if (G_name_is_fully_qualified(name, xname, xmapset)) {
     if (G_name_is_fully_qualified(name, xname, xmapset)) {
 	if (strcasecmp(xmapset, "ogr") == 0) {
 	if (strcasecmp(xmapset, "ogr") == 0) {
 	    /* unique OGR mapset detected */
 	    /* unique OGR mapset detected */
 	    G_debug(1, "OGR mapset detected");
 	    G_debug(1, "OGR mapset detected");
-	    ogr_mapset = 1;
+	    ogr_mapset = TRUE;
 	    Map->fInfo.ogr.dsn = G_store(xname);
 	    Map->fInfo.ogr.dsn = G_store(xname);
 	    if (layer) {
 	    if (layer) {
 		Map->fInfo.ogr.layer_name = G_store(layer); /* no layer to be open */
 		Map->fInfo.ogr.layer_name = G_store(layer); /* no layer to be open */
@@ -491,7 +491,7 @@ int Vect__open_old(struct Map_info *Map, const char *name, const char *mapset, c
 	    unlink(file_path);
 	    unlink(file_path);
     }
     }
 
 
-    return (level);
+    return level;
 }
 }
 
 
 /*!
 /*!
@@ -920,7 +920,7 @@ int Vect_maptype(const struct Map_info *Map)
  * \brief Open topology file ('topo')
  * \brief Open topology file ('topo')
  *
  *
  * \param[in,out] Map pointer to Map_info structure
  * \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 0 on success
  * \return 1 file does not exist
  * \return 1 file does not exist

+ 17 - 13
lib/vector/Vlib/open_ogr.c

@@ -37,8 +37,7 @@
    Map->fInfo.ogr.layer_name must be set before.
    Map->fInfo.ogr.layer_name must be set before.
 
 
    \param[in,out] Map pointer to Map_info structure
    \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 0 success
    \return -1 error
    \return -1 error
@@ -49,15 +48,10 @@ int V1_open_old_ogr(struct Map_info *Map, int update)
     OGRDataSourceH Ogr_ds;
     OGRDataSourceH Ogr_ds;
     OGRLayerH Ogr_layer;
     OGRLayerH Ogr_layer;
     OGRFeatureDefnH Ogr_featuredefn;
     OGRFeatureDefnH Ogr_featuredefn;
-
+    OGRwkbGeometryType Ogr_geom_type;
+    
     Ogr_layer = NULL;
     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) {
     if (!Map->fInfo.ogr.dsn) {
 	G_fatal_error(_("OGR datasource not defined"));
 	G_fatal_error(_("OGR datasource not defined"));
@@ -90,6 +84,7 @@ int V1_open_old_ogr(struct Map_info *Map, int update)
 	Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
 	Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
 	Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
 	Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
 	if (strcmp(OGR_FD_GetName(Ogr_featuredefn), Map->fInfo.ogr.layer_name) == 0) {
 	if (strcmp(OGR_FD_GetName(Ogr_featuredefn), Map->fInfo.ogr.layer_name) == 0) {
+	    Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
 	    layer = i;
 	    layer = i;
 	    break;
 	    break;
 	}
 	}
@@ -109,12 +104,21 @@ int V1_open_old_ogr(struct Map_info *Map, int update)
     Map->fInfo.ogr.lines_num = 0;
     Map->fInfo.ogr.lines_num = 0;
     Map->fInfo.ogr.lines_next = 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 = NULL;
     Map->fInfo.ogr.feature_cache_id = -1;	/* FID >= 0 */
     Map->fInfo.ogr.feature_cache_id = -1;	/* FID >= 0 */
     
     
-    return (0);
+    return 0;
 }
 }
 
 
 /*!
 /*!
@@ -219,7 +223,7 @@ int V1_open_new_ogr(struct Map_info *Map, const char *name, int with_z)
     OGRDataSourceH  Ogr_ds;
     OGRDataSourceH  Ogr_ds;
     OGRLayerH       Ogr_layer;
     OGRLayerH       Ogr_layer;
     OGRFeatureDefnH Ogr_featuredefn;
     OGRFeatureDefnH Ogr_featuredefn;
-
+    
     int            i, nlayers;
     int            i, nlayers;
     char         **Ogr_layer_options;
     char         **Ogr_layer_options;
      
      

+ 2 - 2
raster/r.external/main.c

@@ -57,7 +57,7 @@ static void list_formats(void)
     /* -------------------------------------------------------------------- */
     /* -------------------------------------------------------------------- */
     int iDr;
     int iDr;
 
 
-    fprintf(stdout, _("Supported Formats:\n"));
+    G_message(_("Supported formats:"));
     for (iDr = 0; iDr < GDALGetDriverCount(); iDr++) {
     for (iDr = 0; iDr < GDALGetDriverCount(); iDr++) {
 	GDALDriverH hDriver = GDALGetDriver(iDr);
 	GDALDriverH hDriver = GDALGetDriver(iDr);
 	const char *pszRWFlag;
 	const char *pszRWFlag;
@@ -69,7 +69,7 @@ static void list_formats(void)
 	else
 	else
 	    pszRWFlag = "ro";
 	    pszRWFlag = "ro";
 
 
-	fprintf(stdout, "  %s (%s): %s\n",
+	fprintf(stdout, " %s (%s): %s\n",
 		GDALGetDriverShortName(hDriver),
 		GDALGetDriverShortName(hDriver),
 		pszRWFlag, GDALGetDriverLongName(hDriver));
 		pszRWFlag, GDALGetDriverLongName(hDriver));
     }
     }

+ 17 - 2
vector/v.external/list.c

@@ -1,4 +1,5 @@
 #include <grass/gis.h>
 #include <grass/gis.h>
+#include <grass/vector.h>
 #include <grass/glocale.h>
 #include <grass/glocale.h>
 
 
 #include "ogr_api.h"
 #include "ogr_api.h"
@@ -9,14 +10,14 @@ void list_formats(FILE *fd) {
     
     
     OGRSFDriverH Ogr_driver;
     OGRSFDriverH Ogr_driver;
     
     
-    G_message(_("Available drivers:\n"));
+    G_message(_("Supported formats:"));
     for (i = 0; i < OGRGetDriverCount(); i++) {
     for (i = 0; i < OGRGetDriverCount(); i++) {
 	Ogr_driver = OGRGetDriver(i);
 	Ogr_driver = OGRGetDriver(i);
 	fprintf(fd, " %s\n", OGR_Dr_GetName(Ogr_driver));
 	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 i, ret;
     int nlayers;
     int nlayers;
@@ -25,6 +26,7 @@ int list_layers(FILE *fd, const char *dsn, const char *layer)
     OGRDataSourceH Ogr_ds;
     OGRDataSourceH Ogr_ds;
     OGRLayerH Ogr_layer;
     OGRLayerH Ogr_layer;
     OGRFeatureDefnH Ogr_featuredefn;
     OGRFeatureDefnH Ogr_featuredefn;
+    OGRwkbGeometryType Ogr_geom_type;
     
     
     ret = -1;
     ret = -1;
     
     
@@ -50,6 +52,19 @@ int list_layers(FILE *fd, const char *dsn, const char *layer)
 	
 	
 	if (layer)
 	if (layer)
 	    if (strcmp(layer_name, layer) == 0) {
 	    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;
 		ret = i;
 	    }
 	    }
     }
     }

+ 1 - 1
vector/v.external/local_proto.h

@@ -18,6 +18,6 @@ void get_args(const struct _options *, const struct _flags *,
 
 
 /* list.c */
 /* list.c */
 void list_formats(FILE *);
 void list_formats(FILE *);
-int list_layers(FILE *, const char *, const char *);
+int list_layers(FILE *, const char *, const char *, int *);
 
 
 #endif
 #endif

+ 6 - 7
vector/v.external/main.c

@@ -8,7 +8,7 @@
  *               
  *               
  * PURPOSE:      Create a new vector as a link to OGR layer (read-only)
  * 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 
  *               This program is free software under the 
  *               GNU General Public License (>=v2). 
  *               GNU General Public License (>=v2). 
@@ -39,7 +39,7 @@ int main(int argc, char *argv[])
     
     
     FILE *fd;
     FILE *fd;
     
     
-    int ilayer;
+    int ilayer, is3D;
     char buf[GPATH_MAX];
     char buf[GPATH_MAX];
      
      
     G_gisinit(argv[0]);
     G_gisinit(argv[0]);
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
     if (flags.layer->answer) {
     if (flags.layer->answer) {
 	if (!options.dsn->answer)
 	if (!options.dsn->answer)
 	    G_fatal_error(_("Required parameter <%s> not set"), options.dsn->key);
 	    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);
 	exit(EXIT_SUCCESS);
     }
     }
 
 
@@ -75,15 +75,14 @@ int main(int argc, char *argv[])
 	G_fatal_error(_("Required parameter <%s> not set"), options.layer->key);
 	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) {
     if (ilayer == -1) {
 	G_fatal_error(_("Layer <%s> not available"), options.layer->answer);
 	G_fatal_error(_("Layer <%s> not available"), options.layer->answer);
     }
     }
     
     
     G_debug(2, "layer '%s' was found", 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_hist_command(&Map);
     Vect_close(&Map);
     Vect_close(&Map);
     
     
@@ -116,7 +115,7 @@ int main(int argc, char *argv[])
       Vect_close(&Map);
       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);
     exit(EXIT_SUCCESS);
 }
 }