Explorar o código

r.in.gdal/r.external: add test if OGR spatial reference is NULL

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@72251 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz %!s(int64=7) %!d(string=hai) anos
pai
achega
f7f564117b
Modificáronse 3 ficheiros con 13 adicións e 11 borrados
  1. 4 3
      raster/r.external/proj.c
  2. 5 5
      raster/r.in.gdal/main.c
  3. 4 3
      raster/r.in.gdal/proj.c

+ 4 - 3
raster/r.external/proj.c

@@ -39,9 +39,10 @@ void check_projection(struct Cell_head *cellhd, GDALDatasetH hDS,
 	OGRSpatialReferenceH hSRS;
 
 	hSRS = OSRNewSpatialReference(wkt);
-	GPJ_osr_to_grass(cellhd, &proj_info, &proj_units, hSRS, 0);
+	if (hSRS != NULL)
+	    GPJ_osr_to_grass(cellhd, &proj_info, &proj_units, hSRS, 0);
 
-	if (!OSRIsProjected(hSRS) && !OSRIsGeographic(hSRS)) {
+	if (!hSRS || (!OSRIsProjected(hSRS) && !OSRIsGeographic(hSRS))) {
 	    G_important_message(_("Input contains an invalid SRS. " 
 	                          "WKT definition:\n%s"), wkt);
 
@@ -59,7 +60,7 @@ void check_projection(struct Cell_head *cellhd, GDALDatasetH hDS,
 	    if (authname && *authname && strcmp(authname, "EPSG") == 0) {
 		authcode = OSRGetAuthorityCode(hSRS, authkey);
 		if (authcode && *authcode) {
-		    G_debug(0, "found EPSG:%s", authcode);
+		    G_debug(1, "found EPSG:%s", authcode);
 		    proj_epsg = G_create_key_value();
 		    G_set_key_value("epsg", authcode, proj_epsg);
 		}

+ 5 - 5
raster/r.in.gdal/main.c

@@ -472,11 +472,6 @@ int main(int argc, char *argv[])
     check_projection(&cellhd, hDS, parm.outloc->answer, flag_c->answer,
                      flag_o->answer, flag_j->answer);
 
-    if (GDALGetRasterCount(hDS) > 1) {
-	G_message(_("Importing %d raster bands..."),
-		  GDALGetRasterCount(hDS));
-    }
-
     /* -------------------------------------------------------------------- */
     /*      Set the active window to match the available data.              */
     /* -------------------------------------------------------------------- */
@@ -576,6 +571,11 @@ int main(int argc, char *argv[])
 	    n_bands++;
     }
 
+    if (GDALGetRasterCount(hDS) > 1 && n_bands != 1) {
+	G_message(_("Importing %d raster bands..."),
+		  (n_bands > 1 ? n_bands : GDALGetRasterCount(hDS)));
+    }
+
     if ((GDALGetRasterCount(hDS) > 1 && n_bands != 1)
 	|| GDALGetGCPCount(hDS) > 0)
 	force_imagery = TRUE;

+ 4 - 3
raster/r.in.gdal/proj.c

@@ -39,9 +39,10 @@ void check_projection(struct Cell_head *cellhd, GDALDatasetH hDS,
 	OGRSpatialReferenceH hSRS;
 
 	hSRS = OSRNewSpatialReference(wkt);
-	GPJ_osr_to_grass(cellhd, &proj_info, &proj_units, hSRS, 0);
+	if (hSRS != NULL)
+	    GPJ_osr_to_grass(cellhd, &proj_info, &proj_units, hSRS, 0);
 
-	if (!OSRIsProjected(hSRS) && !OSRIsGeographic(hSRS)) {
+	if (!hSRS || (!OSRIsProjected(hSRS) && !OSRIsGeographic(hSRS))) {
 	    G_important_message(_("Input contains an invalid SRS. " 
 	                          "WKT definition:\n%s"), wkt);
 
@@ -59,7 +60,7 @@ void check_projection(struct Cell_head *cellhd, GDALDatasetH hDS,
 	    if (authname && *authname && strcmp(authname, "EPSG") == 0) {
 		authcode = OSRGetAuthorityCode(hSRS, authkey);
 		if (authcode && *authcode) {
-		    G_debug(0, "found EPSG:%s", authcode);
+		    G_debug(1, "found EPSG:%s", authcode);
 		    proj_epsg = G_create_key_value();
 		    G_set_key_value("epsg", authcode, proj_epsg);
 		}