[GRASS-SVN] r54839 - grass/trunk/vector/v.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Feb 2 09:01:59 PST 2013


Author: martinl
Date: 2013-02-02 09:01:59 -0800 (Sat, 02 Feb 2013)
New Revision: 54839

Modified:
   grass/trunk/vector/v.in.ogr/main.c
   grass/trunk/vector/v.in.ogr/v.in.ogr.html
Log:
v.in.ogr: add new parameter to set encoding value (useful for Esri Shapefiles)
          update manual


Modified: grass/trunk/vector/v.in.ogr/main.c
===================================================================
--- grass/trunk/vector/v.in.ogr/main.c	2013-02-02 15:33:25 UTC (rev 54838)
+++ grass/trunk/vector/v.in.ogr/main.c	2013-02-02 17:01:59 UTC (rev 54839)
@@ -51,7 +51,7 @@
     struct _param {
 	struct Option *dsn, *out, *layer, *spat, *where,
 	    *min_area;
-	struct Option *snap, *type, *outloc, *cnames;
+	struct Option *snap, *type, *outloc, *cnames, *encoding;
     } param;
     struct _flag {
 	struct Flag *list, *no_clean, *force2d, *notab,
@@ -122,7 +122,7 @@
     module = G_define_module();
     G_add_keyword(_("vector"));
     G_add_keyword(_("import"));
-    module->description = _("Converts vector data into a GRASS vector map using OGR library.");
+    module->description = _("Imports vector data into a GRASS vector map using OGR library.");
 
     param.dsn = G_define_option();
     param.dsn->key = "dsn";
@@ -213,6 +213,16 @@
 	  "first is used for category column");
     param.cnames->guisection = _("Attributes");
 
+    param.encoding = G_define_option();
+    param.encoding->key = "encoding";
+    param.encoding->type = TYPE_STRING;
+    param.encoding->required = NO;
+    param.encoding->label =
+        _("Encoding value for attribute data");
+    param.encoding->description = 
+        _("Overrides encoding interpretation, useful when importing ESRI Shapefile");
+    param.encoding->guisection = _("Attributes");
+
     flag.formats = G_define_flag();
     flag.formats->key = 'f';
     flag.formats->description = _("List supported OGR formats and exit");
@@ -322,15 +332,33 @@
 	}
     }
 
-    /* Open OGR DSN */
+    /* set up encoding for attribute data */
+    if (param.encoding->answer) {
+        /* -> Esri Shapefile */
+        setenv("SHAPE_ENCODING", param.encoding->answer, 1);
+        /* -> DXF */
+        setenv("DXF_ENCODING", param.encoding->answer, 1);
+        /* todo: others ? */
+    }
+
+    /* open OGR DSN */
     Ogr_ds = NULL;
     if (strlen(param.dsn->answer) > 0)
 	Ogr_ds = OGROpen(param.dsn->answer, FALSE, NULL);
-
     if (Ogr_ds == NULL)
 	G_fatal_error(_("Unable to open data source <%s>"), param.dsn->answer);
 
-    /* Make a list of available layers */
+    /* check encoding for given driver */
+    if (param.encoding->answer) {
+        const char *driver_name;
+
+        driver_name = OGR_Dr_GetName(OGR_DS_GetDriver(Ogr_ds));
+        if (strcmp(driver_name, "ESRI Shapefile") != 0 &&
+            strcmp(driver_name, "DXF") != 0)
+            G_warning(_("Encoding value not supported by OGR driver <%s>"), driver_name);
+    }
+
+    /* make a list of available layers */
     navailable_layers = OGR_DS_GetLayerCount(Ogr_ds);
     available_layer_names =
 	(char **)G_malloc(navailable_layers * sizeof(char *));
@@ -402,7 +430,7 @@
 	    G_fatal_error(_("Vector map <%s> already exists"),
 			  output);
     }
-    
+
     /* Get first imported layer to use for extents and projection check */
     Ogr_layer = OGR_DS_GetLayer(Ogr_ds, layers[0]);
 

Modified: grass/trunk/vector/v.in.ogr/v.in.ogr.html
===================================================================
--- grass/trunk/vector/v.in.ogr/v.in.ogr.html	2013-02-02 15:33:25 UTC (rev 54838)
+++ grass/trunk/vector/v.in.ogr/v.in.ogr.html	2013-02-02 17:01:59 UTC (rev 54839)
@@ -121,6 +121,21 @@
 Alternatively, change the local DB with
 <em><a href="db.connect.html">db.connect</a></em>.
 
+<p>
+When importing Esri Shapefiles the OGR library tries to read the
+LDID/codepage setting from the .dbf file and use it to translate
+string fields to UTF-8. LDID "87 / 0x57" is treated as
+ISO8859_1 which may not be appropriate for many
+languages. Unfortunately it is not clear what other values may be
+appropriate (see example bellow). To change encoding the user can set
+up <tt>SHAPE_ENCODING</tt> environmental variable or simply to define
+encoding value using <b>encoding</b> parameter. Note that recoding
+support is new for GDAL/OGR 1.9.0.
+
+<p>
+Value for <b>encoding</b> also affects text recoding when importing
+DXF files. For other formats has encoding value no effect.
+
 <h2>EXAMPLES</h2>
 
 The command imports various vector formats:
@@ -137,6 +152,16 @@
 v.in.ogr dsn=/home/user/shape_data layer=test_shape output=grass_map 
 </pre></div>
 
+Define encoding value for attribute data (in this example we expect
+attribute data
+in <a href="http://en.wikipedia.org/wiki/Windows-1250">Windows-1250</a>
+encoding; ie. in Central/Eastern European languages that
+use Latin script, Microsoft Windows encoding).
+
+<div class="code"><pre>
+v.in.ogr dsn=/home/user/shape_data/test_shape.shp output=grass_map encoding=cp1250
+</pre></div>
+
 <h3>MapInfo files</h3>
 
 <div class="code"><pre>



More information about the grass-commit mailing list