[GRASS-SVN] r72114 - in grass/trunk: raster/r.external raster/r.in.gdal vector/v.external vector/v.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 22 12:33:02 PST 2018


Author: mmetz
Date: 2018-01-22 12:33:02 -0800 (Mon, 22 Jan 2018)
New Revision: 72114

Modified:
   grass/trunk/raster/r.external/proj.c
   grass/trunk/raster/r.in.gdal/proj.c
   grass/trunk/vector/v.external/proj.c
   grass/trunk/vector/v.in.ogr/main.c
   grass/trunk/vector/v.in.ogr/proj.c
Log:
retrieve and use EPSG code from GDAL/OGR input whenever possible

Modified: grass/trunk/raster/r.external/proj.c
===================================================================
--- grass/trunk/raster/r.external/proj.c	2018-01-22 20:28:29 UTC (rev 72113)
+++ grass/trunk/raster/r.external/proj.c	2018-01-22 20:33:02 UTC (rev 72114)
@@ -11,8 +11,8 @@
 		      int check_only)
 {
     struct Cell_head loc_wind;
-    struct Key_Value *proj_info = NULL, *proj_units = NULL;
-    struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;
+    struct Key_Value *proj_info, *proj_units, *proj_epsg;
+    struct Key_Value *loc_proj_info, *loc_proj_units;
     const char *wkt;
     char error_msg[8096];
     int proj_trouble;
@@ -22,6 +22,10 @@
     /* -------------------------------------------------------------------- */
     proj_info = NULL;
     proj_units = NULL;
+    proj_epsg = NULL;
+    loc_proj_info = NULL;
+    loc_proj_units = NULL;
+
     wkt = GDALGetProjectionRef(hDS);
     /* proj_trouble:
      * 0: valid srs
@@ -43,6 +47,24 @@
 
 	    proj_trouble = 2;
 	}
+	else{
+	    const char *authkey, *authname, *authcode;
+
+	    if (OSRIsProjected(hSRS))
+		authkey = "PROJCS";
+	    else /* is geographic */
+		authkey = "GEOGCS";
+
+	    authname = OSRGetAuthorityName(hSRS, authkey);
+	    if (authname && *authname && strcmp(authname, "EPSG") == 0) {
+		authcode = OSRGetAuthorityCode(hSRS, authkey);
+		if (authcode && *authcode) {
+		    G_debug(0, "found EPSG:%s", authcode);
+		    proj_epsg = G_create_key_value();
+		    G_set_key_value("epsg", authcode, proj_epsg);
+		}
+	    }
+	}
 	if (hSRS)
 	    OSRDestroySpatialReference(hSRS);
     }
@@ -63,8 +85,8 @@
 			    "format; cannot create new location."));
 	}
 	else {
-            if (0 != G_make_location(outloc, cellhd,
-                                     proj_info, proj_units)) {
+            if (0 != G_make_location_epsg(outloc, cellhd, proj_info,
+	                                  proj_units, proj_epsg)) {
                 G_fatal_error(_("Unable to create new location <%s>"),
                               outloc);
             }

Modified: grass/trunk/raster/r.in.gdal/proj.c
===================================================================
--- grass/trunk/raster/r.in.gdal/proj.c	2018-01-22 20:28:29 UTC (rev 72113)
+++ grass/trunk/raster/r.in.gdal/proj.c	2018-01-22 20:33:02 UTC (rev 72114)
@@ -11,8 +11,8 @@
 		      int check_only)
 {
     struct Cell_head loc_wind;
-    struct Key_Value *proj_info = NULL, *proj_units = NULL;
-    struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;
+    struct Key_Value *proj_info, *proj_units, *proj_epsg;
+    struct Key_Value *loc_proj_info, *loc_proj_units;
     const char *wkt;
     char error_msg[8096];
     int proj_trouble;
@@ -22,6 +22,10 @@
     /* -------------------------------------------------------------------- */
     proj_info = NULL;
     proj_units = NULL;
+    proj_epsg = NULL;
+    loc_proj_info = NULL;
+    loc_proj_units = NULL;
+
     wkt = GDALGetProjectionRef(hDS);
     /* proj_trouble:
      * 0: valid srs
@@ -43,6 +47,24 @@
 
 	    proj_trouble = 2;
 	}
+	else{
+	    const char *authkey, *authname, *authcode;
+
+	    if (OSRIsProjected(hSRS))
+		authkey = "PROJCS";
+	    else /* is geographic */
+		authkey = "GEOGCS";
+
+	    authname = OSRGetAuthorityName(hSRS, authkey);
+	    if (authname && *authname && strcmp(authname, "EPSG") == 0) {
+		authcode = OSRGetAuthorityCode(hSRS, authkey);
+		if (authcode && *authcode) {
+		    G_debug(0, "found EPSG:%s", authcode);
+		    proj_epsg = G_create_key_value();
+		    G_set_key_value("epsg", authcode, proj_epsg);
+		}
+	    }
+	}
 	if (hSRS)
 	    OSRDestroySpatialReference(hSRS);
     }
@@ -63,8 +85,8 @@
 			    "format; cannot create new location."));
 	}
 	else {
-            if (0 != G_make_location(outloc, cellhd,
-                                     proj_info, proj_units)) {
+            if (0 != G_make_location_epsg(outloc, cellhd, proj_info,
+	                                  proj_units, proj_epsg)) {
                 G_fatal_error(_("Unable to create new location <%s>"),
                               outloc);
             }

Modified: grass/trunk/vector/v.external/proj.c
===================================================================
--- grass/trunk/vector/v.external/proj.c	2018-01-22 20:28:29 UTC (rev 72113)
+++ grass/trunk/vector/v.external/proj.c	2018-01-22 20:33:02 UTC (rev 72114)
@@ -10,15 +10,18 @@
  * return 1 if no SRS available
  * return 2 if SRS available but unreadable */
 int get_layer_proj(OGRLayerH Ogr_layer, struct Cell_head *cellhd,
-		   struct Key_Value **proj_info, struct Key_Value **proj_units,
+		   struct Key_Value **proj_info,
+		   struct Key_Value **proj_units,
+		   struct Key_Value **proj_epsg,
 		   char *geom_col, int verbose)
 {
-    OGRSpatialReferenceH Ogr_projection;
+    OGRSpatialReferenceH hSRS;
     char *pszProj4 = NULL;
 
-    Ogr_projection = NULL;
+    hSRS = NULL;
     *proj_info = NULL;
     *proj_units = NULL;
+    *proj_epsg = NULL;
 
     /* Fetch input layer projection in GRASS form. */
 #if GDAL_VERSION_NUM >= 1110000
@@ -33,27 +36,27 @@
             G_fatal_error(_("Geometry column <%s> not found in input layer <%s>"),
                           geom_col, OGR_L_GetName(Ogr_layer));
         Ogr_geomdefn = OGR_FD_GetGeomFieldDefn(Ogr_featuredefn, igeom);
-        Ogr_projection = OGR_GFld_GetSpatialRef(Ogr_geomdefn);
+        hSRS = OGR_GFld_GetSpatialRef(Ogr_geomdefn);
     }
     else {
-        Ogr_projection = OGR_L_GetSpatialRef(Ogr_layer);
+        hSRS = OGR_L_GetSpatialRef(Ogr_layer);
     }
 #else
-    Ogr_projection = OGR_L_GetSpatialRef(Ogr_layer);	/* should not be freed later */
+    hSRS = OGR_L_GetSpatialRef(Ogr_layer);	/* should not be freed later */
 #endif
 
     /* verbose is used only when comparing input SRS to GRASS projection,
      * not when comparing SRS's of several input layers */
     if (GPJ_osr_to_grass(cellhd, proj_info,
-			 proj_units, Ogr_projection, 0) < 0) {
+			 proj_units, hSRS, 0) < 0) {
 	/* TODO: GPJ_osr_to_grass() does not return anything < 0
 	 * check with GRASS 6 and GRASS 5 */
 	G_warning(_("Unable to convert input layer projection information to "
 		   "GRASS format for checking"));
-	if (verbose && Ogr_projection != NULL) {
+	if (verbose && hSRS != NULL) {
 	    char *wkt = NULL;
 
-	    if (OSRExportToPrettyWkt(Ogr_projection, &wkt, FALSE) != OGRERR_NONE) {
+	    if (OSRExportToPrettyWkt(hSRS, &wkt, FALSE) != OGRERR_NONE) {
 		G_warning(_("Can't get WKT parameter string"));
 	    }
 	    else if (wkt) {
@@ -65,23 +68,23 @@
     }
     /* custom checks because if in doubt GPJ_osr_to_grass() returns a 
      * xy CRS */
-    if (Ogr_projection == NULL) {
+    if (hSRS == NULL) {
 	if (verbose) {
-	    G_important_message(_("No OGR projection available for layer <%s>"),
+	    G_important_message(_("No projection information available for layer <%s>"),
 				OGR_L_GetName(Ogr_layer));
 	}
 
 	return 1;
     }
 
-    if (!OSRIsProjected(Ogr_projection) && !OSRIsGeographic(Ogr_projection)) {
-	G_important_message(_("OGR projection for layer <%s> does not contain a valid SRS"),
+    if (!OSRIsProjected(hSRS) && !OSRIsGeographic(hSRS)) {
+	G_important_message(_("Projection for layer <%s> does not contain a valid SRS"),
 			    OGR_L_GetName(Ogr_layer));
 
 	if (verbose) {
 	    char *wkt = NULL;
 
-	    if (OSRExportToPrettyWkt(Ogr_projection, &wkt, FALSE) != OGRERR_NONE) {
+	    if (OSRExportToPrettyWkt(hSRS, &wkt, FALSE) != OGRERR_NONE) {
 		G_important_message(_("Can't get WKT parameter string"));
 	    }
 	    else if (wkt) {
@@ -91,15 +94,32 @@
 
 	return 2;
     }
+    else{
+	const char *authkey, *authname, *authcode;
 
-    if (OSRExportToProj4(Ogr_projection, &pszProj4) != OGRERR_NONE) {
-	G_important_message(_("OGR projection for layer <%s> can not be converted to proj4"),
+	if (OSRIsProjected(hSRS))
+	    authkey = "PROJCS";
+	else /* is geographic */
+	    authkey = "GEOGCS";
+
+	authname = OSRGetAuthorityName(hSRS, authkey);
+	if (authname && *authname && strcmp(authname, "EPSG") == 0) {
+	    authcode = OSRGetAuthorityCode(hSRS, authkey);
+	    if (authcode && *authcode) {
+		*proj_epsg = G_create_key_value();
+		G_set_key_value("epsg", authcode, *proj_epsg);
+	    }
+	}
+    }
+
+    if (OSRExportToProj4(hSRS, &pszProj4) != OGRERR_NONE) {
+	G_important_message(_("Projection for layer <%s> can not be converted to proj4"),
 			    OGR_L_GetName(Ogr_layer));
 
 	if (verbose) {
 	    char *wkt = NULL;
 
-	    if (OSRExportToPrettyWkt(Ogr_projection, &wkt, FALSE) != OGRERR_NONE) {
+	    if (OSRExportToPrettyWkt(hSRS, &wkt, FALSE) != OGRERR_NONE) {
 		G_important_message(_("Can't get WKT-style parameter string"));
 	    }
 	    else if (wkt) {
@@ -119,8 +139,8 @@
 		      int check_only)
 {
     struct Cell_head loc_wind;
-    struct Key_Value *proj_info = NULL, *proj_units = NULL;
-    struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;
+    struct Key_Value *proj_info, *proj_units, *proj_epsg;
+    struct Key_Value *loc_proj_info, *loc_proj_units;
     char error_msg[8096];
     int proj_trouble;
     OGRLayerH Ogr_layer;
@@ -133,6 +153,9 @@
     /* -------------------------------------------------------------------- */
     proj_info = NULL;
     proj_units = NULL;
+    proj_epsg = NULL;
+    loc_proj_info = NULL;
+    loc_proj_units = NULL;
 
     /* proj_trouble:
      * 0: valid srs
@@ -142,7 +165,7 @@
 
     /* Projection only required for checking so convert non-interactively */
     proj_trouble = get_layer_proj(Ogr_layer, cellhd, &proj_info, &proj_units,
-		   geom_col, 1);
+		                  &proj_epsg, geom_col, 1);
 
     /* -------------------------------------------------------------------- */
     /*      Do we need to create a new location?                            */
@@ -155,8 +178,8 @@
 			    "format; cannot create new location."));
 	}
 	else {
-            if (0 != G_make_location(outloc, cellhd,
-                                     proj_info, proj_units)) {
+            if (0 != G_make_location_epsg(outloc, cellhd, proj_info,
+	                                  proj_units, proj_epsg)) {
                 G_fatal_error(_("Unable to create new location <%s>"),
                               outloc);
             }

Modified: grass/trunk/vector/v.in.ogr/main.c
===================================================================
--- grass/trunk/vector/v.in.ogr/main.c	2018-01-22 20:28:29 UTC (rev 72113)
+++ grass/trunk/vector/v.in.ogr/main.c	2018-01-22 20:33:02 UTC (rev 72114)
@@ -1531,13 +1531,6 @@
 	    
 	Vect_spatial_index_destroy(&si);
 
-	if (n_overlaps > 0) {
-	    G_warning(_("%d areas represent more (overlapping) features, because polygons overlap "
-		       "in input layer(s). Such areas are linked to more than 1 row in attribute table. "
-		       "The number of features for those areas is stored as category in layer %d"),
-		      n_overlaps, nlayers + 1);
-	}
-
 	G_message("%s", separator);
 
 	Vect_hist_write(&Map, separator);
@@ -1683,18 +1676,34 @@
 	G_important_message("%s", separator);
 	/* topological errors */
 	if (failed_centr || err_boundaries || err_centr_out || err_centr_dupl) {
-	    G_warning(_("The output contains topological errors:"));
-	    if (failed_centr)
-		G_warning(_("Unable to calculate a centroid for %d areas"), failed_centr);
-	    if (err_boundaries)
-		G_warning(_("Number of incorrect boundaries: %d"),
-			  err_boundaries);
-	    if (err_centr_out)
-		G_warning(_("Number of centroids outside area: %d"),
-			  err_centr_out);
-	    if (err_centr_dupl)
-		G_warning(_("Number of duplicate centroids: %d"),
-			  err_centr_dupl);
+	    char error_msg[8096];
+
+	    strcpy(error_msg, _("The output contains topological errors:"));
+	    if (failed_centr) {
+		strcat(error_msg, "\n");
+		sprintf(error_msg + strlen(error_msg),
+		       _("Unable to calculate a centroid for %d areas"),
+		       failed_centr);
+	    }
+	    if (err_boundaries) {
+		strcat(error_msg, "\n");
+		sprintf(error_msg + strlen(error_msg),
+		        _("Number of incorrect boundaries: %d"),
+			err_boundaries);
+	    }
+	    if (err_centr_out) {
+		strcat(error_msg, "\n");
+		sprintf(error_msg + strlen(error_msg),
+		        _("Number of centroids outside area: %d"),
+			err_centr_out);
+	    }
+	    if (err_centr_dupl) {
+		strcat(error_msg, "\n");
+		sprintf(error_msg + strlen(error_msg),
+		        _("Number of duplicate centroids: %d"),
+			err_centr_dupl);
+	    }
+	    G_warning(error_msg);
 	    
 	    G_important_message(_("The input could be cleaned by snapping vertices to each other."));
 
@@ -1702,10 +1711,20 @@
 		G_important_message(_("Estimated range of snapping threshold: [%g, %g]"), min_snap, max_snap);
 	    }
 
-	    if (snap < min_snap) {
+	    if (snap < 0) {
+		double e1, e2;
+
+		/* human readable */
+		e1 = log10(min_snap);
+		e2 = log10(max_snap);
+		e1 = (int)((e1 + e2) / 2. - 0.5);
+		snap = pow(10, e1);
+		G_important_message(_("Try to import again, snapping with %g: 'snap=%g'"), snap, snap);
+	    }
+	    else if (snap < min_snap) {
 		G_important_message(_("Try to import again, snapping with at least %g: 'snap=%g'"), min_snap, min_snap);
 	    }
-	    else if (snap < max_snap) {
+	    else if (snap * 10 < max_snap) {
 		min_snap = snap * 10;
 		G_important_message(_("Try to import again, snapping with %g: 'snap=%g'"), min_snap, min_snap);
 	    }
@@ -1715,26 +1734,30 @@
 	}
 	/* overlapping polygons */
 	else if (n_overlaps) {
-	    if (n_overlaps) {
-		G_important_message(_("Some input polygons are overlapping each other."));
-		G_important_message(_("If overlapping is not desired, the data need to be cleaned."));
-		G_important_message(_("The input could be cleaned by snapping vertices to each other."));
-	    }
+	    G_important_message(_("%d areas represent multiple (overlapping) features, because polygons overlap "
+		       "in input layer(s). Such areas are linked to more than 1 row in attribute table. "
+		       "The number of features for those areas is stored as category in layer %d"),
+		       n_overlaps, nlayers + 1);
+	    G_important_message("%s", separator);
+	    G_important_message(_("If overlapping is not desired, the input data can be "
+				  "cleaned by snapping vertices to each other."));
 
 	    if (snap < max_snap) {
 		G_important_message(_("Estimated range of snapping threshold: [%g, %g]"), min_snap, max_snap);
 	    }
 
-	    if (snap < min_snap) {
-		G_important_message(_("Try to import again, snapping with at least %g: 'snap=%g'"), min_snap, min_snap);
+	    if (snap > 0) {
+		if (snap < min_snap) {
+		    G_important_message(_("Try to import again, snapping with at least %g: 'snap=%g'"), min_snap, min_snap);
+		}
+		else if (snap * 10 <= max_snap) {
+		    min_snap = snap * 10;
+		    G_important_message(_("Try to import again, snapping with %g: 'snap=%g'"), min_snap, min_snap);
+		}
+		else
+		    /* assume manual cleaning is required */
+		    G_important_message(_("Manual cleaning may be needed."));
 	    }
-	    else if (snap < max_snap) {
-		min_snap = snap * 10;
-		G_important_message(_("Try to import again, snapping with %g: 'snap=%g'"), min_snap, min_snap);
-	    }
-	    else
-		/* assume manual cleaning is required */
-		G_important_message(_("Manual cleaning may be needed."));
 	}
 	/* number of centroids does not match number of input polygons */
 	else if (ncentr != n_polygons) {

Modified: grass/trunk/vector/v.in.ogr/proj.c
===================================================================
--- grass/trunk/vector/v.in.ogr/proj.c	2018-01-22 20:28:29 UTC (rev 72113)
+++ grass/trunk/vector/v.in.ogr/proj.c	2018-01-22 20:33:02 UTC (rev 72114)
@@ -10,15 +10,18 @@
  * return 1 if no SRS available
  * return 2 if SRS available but unreadable */
 int get_layer_proj(OGRLayerH Ogr_layer, struct Cell_head *cellhd,
-		   struct Key_Value **proj_info, struct Key_Value **proj_units,
+		   struct Key_Value **proj_info,
+		   struct Key_Value **proj_units,
+		   struct Key_Value **proj_epsg,
 		   char *geom_col, int verbose)
 {
-    OGRSpatialReferenceH Ogr_projection;
+    OGRSpatialReferenceH hSRS;
     char *pszProj4 = NULL;
 
-    Ogr_projection = NULL;
+    hSRS = NULL;
     *proj_info = NULL;
     *proj_units = NULL;
+    *proj_epsg = NULL;
 
     /* Fetch input layer projection in GRASS form. */
 #if GDAL_VERSION_NUM >= 1110000
@@ -33,27 +36,27 @@
             G_fatal_error(_("Geometry column <%s> not found in input layer <%s>"),
                           geom_col, OGR_L_GetName(Ogr_layer));
         Ogr_geomdefn = OGR_FD_GetGeomFieldDefn(Ogr_featuredefn, igeom);
-        Ogr_projection = OGR_GFld_GetSpatialRef(Ogr_geomdefn);
+        hSRS = OGR_GFld_GetSpatialRef(Ogr_geomdefn);
     }
     else {
-        Ogr_projection = OGR_L_GetSpatialRef(Ogr_layer);
+        hSRS = OGR_L_GetSpatialRef(Ogr_layer);
     }
 #else
-    Ogr_projection = OGR_L_GetSpatialRef(Ogr_layer);	/* should not be freed later */
+    hSRS = OGR_L_GetSpatialRef(Ogr_layer);	/* should not be freed later */
 #endif
 
     /* verbose is used only when comparing input SRS to GRASS projection,
      * not when comparing SRS's of several input layers */
     if (GPJ_osr_to_grass(cellhd, proj_info,
-			 proj_units, Ogr_projection, 0) < 0) {
+			 proj_units, hSRS, 0) < 0) {
 	/* TODO: GPJ_osr_to_grass() does not return anything < 0
 	 * check with GRASS 6 and GRASS 5 */
 	G_warning(_("Unable to convert input layer projection information to "
 		   "GRASS format for checking"));
-	if (verbose && Ogr_projection != NULL) {
+	if (verbose && hSRS != NULL) {
 	    char *wkt = NULL;
 
-	    if (OSRExportToPrettyWkt(Ogr_projection, &wkt, FALSE) != OGRERR_NONE) {
+	    if (OSRExportToPrettyWkt(hSRS, &wkt, FALSE) != OGRERR_NONE) {
 		G_warning(_("Can't get WKT parameter string"));
 	    }
 	    else if (wkt) {
@@ -65,23 +68,23 @@
     }
     /* custom checks because if in doubt GPJ_osr_to_grass() returns a 
      * xy CRS */
-    if (Ogr_projection == NULL) {
+    if (hSRS == NULL) {
 	if (verbose) {
-	    G_important_message(_("No OGR projection available for layer <%s>"),
+	    G_important_message(_("No projection information available for layer <%s>"),
 				OGR_L_GetName(Ogr_layer));
 	}
 
 	return 1;
     }
 
-    if (!OSRIsProjected(Ogr_projection) && !OSRIsGeographic(Ogr_projection)) {
-	G_important_message(_("OGR projection for layer <%s> does not contain a valid SRS"),
+    if (!OSRIsProjected(hSRS) && !OSRIsGeographic(hSRS)) {
+	G_important_message(_("Projection for layer <%s> does not contain a valid SRS"),
 			    OGR_L_GetName(Ogr_layer));
 
 	if (verbose) {
 	    char *wkt = NULL;
 
-	    if (OSRExportToPrettyWkt(Ogr_projection, &wkt, FALSE) != OGRERR_NONE) {
+	    if (OSRExportToPrettyWkt(hSRS, &wkt, FALSE) != OGRERR_NONE) {
 		G_important_message(_("Can't get WKT parameter string"));
 	    }
 	    else if (wkt) {
@@ -91,15 +94,32 @@
 
 	return 2;
     }
+    else{
+	const char *authkey, *authname, *authcode;
 
-    if (OSRExportToProj4(Ogr_projection, &pszProj4) != OGRERR_NONE) {
-	G_important_message(_("OGR projection for layer <%s> can not be converted to proj4"),
+	if (OSRIsProjected(hSRS))
+	    authkey = "PROJCS";
+	else /* is geographic */
+	    authkey = "GEOGCS";
+
+	authname = OSRGetAuthorityName(hSRS, authkey);
+	if (authname && *authname && strcmp(authname, "EPSG") == 0) {
+	    authcode = OSRGetAuthorityCode(hSRS, authkey);
+	    if (authcode && *authcode) {
+		*proj_epsg = G_create_key_value();
+		G_set_key_value("epsg", authcode, *proj_epsg);
+	    }
+	}
+    }
+
+    if (OSRExportToProj4(hSRS, &pszProj4) != OGRERR_NONE) {
+	G_important_message(_("Projection for layer <%s> can not be converted to proj4"),
 			    OGR_L_GetName(Ogr_layer));
 
 	if (verbose) {
 	    char *wkt = NULL;
 
-	    if (OSRExportToPrettyWkt(Ogr_projection, &wkt, FALSE) != OGRERR_NONE) {
+	    if (OSRExportToPrettyWkt(hSRS, &wkt, FALSE) != OGRERR_NONE) {
 		G_important_message(_("Can't get WKT-style parameter string"));
 	    }
 	    else if (wkt) {
@@ -121,16 +141,16 @@
 		  char **layer_names, char *geom_col)
 {
     int layer;
-    struct Key_Value *proj_info1, *proj_units1;
-    struct Key_Value *proj_info2, *proj_units2;
+    struct Key_Value *proj_info1, *proj_units1, *proj_epsg1;
+    struct Key_Value *proj_info2, *proj_units2, *proj_epsg2;
     struct Cell_head cellhd1, cellhd2;
     OGRLayerH Ogr_layer;
 
     if (nlayers == 1)
 	return 0;
 
-    proj_info1 = proj_units1 = NULL;
-    proj_info2 = proj_units2 = NULL;
+    proj_info1 = proj_units1 = proj_epsg1 = NULL;
+    proj_info2 = proj_units2 = proj_epsg2 = NULL;
 
     G_get_window(&cellhd1);
     layer = 0;
@@ -139,7 +159,7 @@
 	Ogr_layer = ds_getlayerbyindex(Ogr_ds, layers[layer]);
 
 	if (get_layer_proj(Ogr_layer, &cellhd1, &proj_info1, &proj_units1,
-			   geom_col, 0) == 0) {
+			   &proj_epsg1, geom_col, 0) == 0) {
 	    break;
 	}
 	layer++;
@@ -153,6 +173,8 @@
 	    G_free_key_value(proj_info1);
 	if (proj_units1)
 	    G_free_key_value(proj_units1);
+	if (proj_epsg1)
+	    G_free_key_value(proj_epsg1);
 
 	return 0;
     }
@@ -165,6 +187,8 @@
 	    G_free_key_value(proj_info1);
 	if (proj_units1)
 	    G_free_key_value(proj_units1);
+	if (proj_epsg1)
+	    G_free_key_value(proj_epsg1);
 
 	return 1;
     }
@@ -174,9 +198,13 @@
 	Ogr_layer = ds_getlayerbyindex(Ogr_ds, layers[layer]);
 	G_get_window(&cellhd2);
 	if (get_layer_proj(Ogr_layer, &cellhd2, &proj_info2, &proj_units2,
-			   geom_col, 0) != 0) {
-	    G_free_key_value(proj_info1);
-	    G_free_key_value(proj_units1);
+			   &proj_epsg2, geom_col, 0) != 0) {
+	    if (proj_info1)
+		G_free_key_value(proj_info1);
+	    if (proj_units1)
+		G_free_key_value(proj_units1);
+	    if (proj_epsg1)
+		G_free_key_value(proj_epsg1);
 
 	    return 1;
 	}
@@ -188,10 +216,14 @@
 		G_free_key_value(proj_info1);
 	    if (proj_units1)
 		G_free_key_value(proj_units1);
+	    if (proj_epsg1)
+		G_free_key_value(proj_epsg1);
 	    if (proj_info2)
 		G_free_key_value(proj_info2);
 	    if (proj_units2)
 		G_free_key_value(proj_units2);
+	    if (proj_epsg2)
+		G_free_key_value(proj_epsg2);
 	    
 	    G_warning(_("Projection of layer <%s> is different from "
 			"projection of layer <%s>"),
@@ -203,11 +235,15 @@
 	    G_free_key_value(proj_info2);
 	if (proj_units2)
 	    G_free_key_value(proj_units2);
+	if (proj_epsg2)
+	    G_free_key_value(proj_epsg2);
     }
     if (proj_info1)
 	G_free_key_value(proj_info1);
     if (proj_units1)
 	G_free_key_value(proj_units1);
+    if (proj_epsg1)
+	G_free_key_value(proj_epsg1);
 
     return 0;
 }
@@ -218,8 +254,8 @@
 		      int check_only)
 {
     struct Cell_head loc_wind;
-    struct Key_Value *proj_info = NULL, *proj_units = NULL;
-    struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;
+    struct Key_Value *proj_info, *proj_units, *proj_epsg;
+    struct Key_Value *loc_proj_info, *loc_proj_units;
     char error_msg[8096];
     int proj_trouble;
     OGRLayerH Ogr_layer;
@@ -232,6 +268,9 @@
     /* -------------------------------------------------------------------- */
     proj_info = NULL;
     proj_units = NULL;
+    proj_epsg = NULL;
+    loc_proj_info = NULL;
+    loc_proj_units = NULL;
 
     /* proj_trouble:
      * 0: valid srs
@@ -241,7 +280,7 @@
 
     /* Projection only required for checking so convert non-interactively */
     proj_trouble = get_layer_proj(Ogr_layer, cellhd, &proj_info, &proj_units,
-		   geom_col, 1);
+		                  &proj_epsg, geom_col, 1);
 
     /* -------------------------------------------------------------------- */
     /*      Do we need to create a new location?                            */
@@ -254,8 +293,8 @@
 			    "format; cannot create new location."));
 	}
 	else {
-            if (0 != G_make_location(outloc, cellhd,
-                                     proj_info, proj_units)) {
+            if (0 != G_make_location_epsg(outloc, cellhd, proj_info,
+	                                  proj_units, proj_epsg)) {
                 G_fatal_error(_("Unable to create new location <%s>"),
                               outloc);
             }



More information about the grass-commit mailing list