[GRASS-SVN] r72160 - in grass/trunk: lib/vector/Vlib vector/v.out.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 26 03:22:01 PST 2018


Author: mmetz
Date: 2018-01-26 03:22:01 -0800 (Fri, 26 Jan 2018)
New Revision: 72160

Modified:
   grass/trunk/lib/vector/Vlib/write_ogr.c
   grass/trunk/vector/v.out.ogr/main.c
Log:
v.external.out/v.out.ogr: add CRS EPSG code if available

Modified: grass/trunk/lib/vector/Vlib/write_ogr.c
===================================================================
--- grass/trunk/lib/vector/Vlib/write_ogr.c	2018-01-26 11:20:53 UTC (rev 72159)
+++ grass/trunk/lib/vector/Vlib/write_ogr.c	2018-01-26 11:22:01 UTC (rev 72160)
@@ -269,7 +269,7 @@
     OGRSpatialReferenceH Ogr_spatial_ref;
     
     struct field_info *Fi;
-    struct Key_Value *projinfo, *projunits;
+    struct Key_Value *projinfo, *projunits, *projepsg;
     struct Format_info_ogr *ogr_info;
     
     OGRwkbGeometryType Ogr_geom_type;
@@ -285,7 +285,8 @@
     /* get spatial reference */
     projinfo  = G_get_projinfo();
     projunits = G_get_projunits();
-    Ogr_spatial_ref = GPJ_grass_to_osr(projinfo, projunits);
+    projepsg = G_get_projepsg();
+    Ogr_spatial_ref = GPJ_grass_to_osr2(projinfo, projunits, projepsg);
     G_free_key_value(projinfo);
     G_free_key_value(projunits);
     

Modified: grass/trunk/vector/v.out.ogr/main.c
===================================================================
--- grass/trunk/vector/v.out.ogr/main.c	2018-01-26 11:20:53 UTC (rev 72159)
+++ grass/trunk/vector/v.out.ogr/main.c	2018-01-26 11:22:01 UTC (rev 72160)
@@ -261,22 +261,16 @@
     G_get_default_window(&cellhd);
     Ogr_projection = NULL;
     if (cellhd.proj != PROJECTION_XY) {
-        const char *epsg;
+	struct Key_Value *projinfo, *projunits, *projepsg;
 
-        /* try EPSG code first */
-        epsg = G_database_epsg_code();
-        if (!epsg) {
-            struct Key_Value *projinfo, *projunits;
-            
-            projinfo = G_get_projinfo();
-            projunits = G_get_projunits();
-            Ogr_projection = GPJ_grass_to_osr(projinfo, projunits);
-        }
-        else {
-            Ogr_projection = OSRNewSpatialReference(NULL);
-            if (OSRImportFromEPSG(Ogr_projection, atoi(epsg)) != OGRERR_NONE)
-                G_fatal_error(_("Unknown EPSG code %s"), epsg);
-        }
+	projinfo = G_get_projinfo();
+	projunits = G_get_projunits();
+	projepsg = G_get_projepsg();
+	Ogr_projection = GPJ_grass_to_osr2(projinfo, projunits, projepsg);
+
+	if (Ogr_projection ==  NULL)
+	    G_fatal_error(_("Unable to create OGR spatial reference"));
+
 	if (flags.esristyle->answer &&
 	    (strcmp(options.format->answer, "ESRI_Shapefile") == 0))
 	    OSRMorphToESRI(Ogr_projection);



More information about the grass-commit mailing list