From: Bborie Park Date: Sat, 2 Nov 2013 21:03:12 +0000 (+0000) Subject: code cleanup X-Git-Tag: 2.2.0rc1~1310 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dabe55a5f1da84248a8d5c7bc7968f8faf53a4fc;p=postgis code cleanup git-svn-id: http://svn.osgeo.org/postgis/trunk@12077 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_raster.c b/raster/rt_core/rt_raster.c index e583bbe3c..d5f7f3107 100644 --- a/raster/rt_core/rt_raster.c +++ b/raster/rt_core/rt_raster.c @@ -4,6 +4,7 @@ * WKTRaster - Raster Types for PostGIS * http://trac.osgeo.org/postgis/wiki/WKTRaster * + * Copyright (C) 2013 Bborie Park * Copyright (C) 2011-2013 Regents of the University of California * * Copyright (C) 2010-2011 Jorge Arevalo @@ -2401,6 +2402,8 @@ struct _rti_rasterize_arg_t { uint32_t numbands; + OGRSpatialReferenceH src_sr; + rt_pixtype *pixtype; double *init; double *nodata; @@ -2422,6 +2425,9 @@ _rti_rasterize_arg_init() { arg->noband = 0; arg->numbands = 0; + + arg->src_sr = NULL; + arg->pixtype = NULL; arg->init = NULL; arg->nodata = NULL; @@ -2450,6 +2456,9 @@ _rti_rasterize_arg_destroy(_rti_rasterize_arg arg) { if (arg->bandlist != NULL) rtdealloc(arg->bandlist); + if (arg->src_sr != NULL) + OSRDestroySpatialReference(arg->src_sr); + rtdealloc(arg); } @@ -2504,7 +2513,6 @@ rt_raster_gdal_rasterize( double _skew[2] = {0}; OGRErr ogrerr; - OGRSpatialReferenceH src_sr = NULL; OGRGeometryH src_geom; OGREnvelope src_env; rt_envelope extent; @@ -2566,8 +2574,8 @@ rt_raster_gdal_rasterize( /* OGR spatial reference */ if (NULL != srs && strlen(srs)) { - src_sr = OSRNewSpatialReference(NULL); - if (OSRSetFromUserInput(src_sr, srs) != OGRERR_NONE) { + arg->src_sr = OSRNewSpatialReference(NULL); + if (OSRSetFromUserInput(arg->src_sr, srs) != OGRERR_NONE) { rterror("rt_raster_gdal_rasterize: Could not create OSR spatial reference using the provided srs: %s", srs); _rti_rasterize_arg_destroy(arg); return NULL; @@ -2575,13 +2583,11 @@ rt_raster_gdal_rasterize( } /* convert WKB to OGR Geometry */ - ogrerr = OGR_G_CreateFromWkb((unsigned char *) wkb, src_sr, &src_geom, wkb_len); + ogrerr = OGR_G_CreateFromWkb((unsigned char *) wkb, arg->src_sr, &src_geom, wkb_len); if (ogrerr != OGRERR_NONE) { rterror("rt_raster_gdal_rasterize: Could not create OGR Geometry from WKB"); _rti_rasterize_arg_destroy(arg); - - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); /* OGRCleanupAll(); */ return NULL; @@ -2591,10 +2597,8 @@ rt_raster_gdal_rasterize( if (OGR_G_IsEmpty(src_geom)) { rtinfo("Geometry provided is empty. Returning empty raster"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return rt_raster_new(0, 0); @@ -2641,10 +2645,8 @@ rt_raster_gdal_rasterize( else { rterror("rt_raster_gdal_rasterize: Values must be provided for width and height or X and Y of scale"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -2721,10 +2723,8 @@ rt_raster_gdal_rasterize( if (epoly == NULL) { rterror("rt_raster_gdal_rasterize: Could not create envelope's geometry to test if geometry is properly contained by extent"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -2746,10 +2746,8 @@ rt_raster_gdal_rasterize( if (result == 2) { rterror("rt_raster_gdal_rasterize: Could not test if geometry is properly contained by extent for geometry within extent"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -2852,10 +2850,8 @@ rt_raster_gdal_rasterize( if (skewedrast == NULL) { rterror("rt_raster_gdal_rasterize: Could not compute skewed raster"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -2881,10 +2877,8 @@ rt_raster_gdal_rasterize( if (rast == NULL) { rterror("rt_raster_gdal_rasterize: Out of memory allocating temporary raster"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -2922,10 +2916,8 @@ rt_raster_gdal_rasterize( rterror("rt_raster_gdal_rasterize: Both X and Y upper-left corner values must be provided"); rt_raster_destroy(rast); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -2945,10 +2937,8 @@ rt_raster_gdal_rasterize( rterror("rt_raster_gdal_rasterize: Both X and Y alignment values must be provided"); rt_raster_destroy(rast); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -2980,10 +2970,8 @@ rt_raster_gdal_rasterize( rterror("rt_raster_gdal_rasterize: Could not compute raster pixel for spatial coordinates"); rt_raster_destroy(rast); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -2998,10 +2986,8 @@ rt_raster_gdal_rasterize( rterror("rt_raster_gdal_rasterize: Could not compute spatial coordinates for raster pixel"); rt_raster_destroy(rast); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -3026,10 +3012,8 @@ rt_raster_gdal_rasterize( rterror("rt_raster_gdal_rasterize: Could not compute spatial coordinates for raster pixel"); rt_raster_destroy(rast); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -3056,10 +3040,8 @@ rt_raster_gdal_rasterize( rterror("rt_raster_gdal_rasterize: Could not compute spatial coordinates for raster pixel"); rt_raster_destroy(rast); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -3107,10 +3089,8 @@ rt_raster_gdal_rasterize( rterror("rt_raster_gdal_rasterize: Could not compute spatial coordinates for raster pixel"); rt_raster_destroy(rast); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -3139,10 +3119,8 @@ rt_raster_gdal_rasterize( rterror("rt_raster_gdal_rasterize: Could not compute spatial coordinates for raster pixel"); rt_raster_destroy(rast); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -3172,10 +3150,8 @@ rt_raster_gdal_rasterize( if (NULL == _drv) { rterror("rt_raster_gdal_rasterize: Could not load the MEM GDAL driver"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -3185,10 +3161,8 @@ rt_raster_gdal_rasterize( if (NULL == _ds) { rterror("rt_raster_gdal_rasterize: Could not create a GDALDataset to rasterize the geometry into"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ return NULL; @@ -3199,10 +3173,8 @@ rt_raster_gdal_rasterize( if (cplerr != CE_None) { rterror("rt_raster_gdal_rasterize: Could not set geotransform on GDALDataset"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ GDALClose(_ds); @@ -3211,19 +3183,17 @@ rt_raster_gdal_rasterize( } /* set SRS */ - if (NULL != src_sr) { + if (NULL != arg->src_sr) { char *_srs = NULL; - OSRExportToWkt(src_sr, &_srs); + OSRExportToWkt(arg->src_sr, &_srs); cplerr = GDALSetProjection(_ds, _srs); CPLFree(_srs); if (cplerr != CE_None) { rterror("rt_raster_gdal_rasterize: Could not set projection on GDALDataset"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ GDALClose(_ds); @@ -3275,10 +3245,10 @@ rt_raster_gdal_rasterize( while (0); if (err) { - _rti_rasterize_arg_destroy(arg); OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); + /* OGRCleanupAll(); */ GDALClose(_ds); @@ -3290,7 +3260,6 @@ rt_raster_gdal_rasterize( arg->bandlist = (int *) rtalloc(sizeof(int) * arg->numbands); for (i = 0; i < arg->numbands; i++) arg->bandlist[i] = i + 1; - /* burn geometry */ cplerr = GDALRasterizeGeometries( _ds, @@ -3304,10 +3273,8 @@ rt_raster_gdal_rasterize( if (cplerr != CE_None) { rterror("rt_raster_gdal_rasterize: Could not rasterize geometry"); - _rti_rasterize_arg_destroy(arg); - OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); + _rti_rasterize_arg_destroy(arg); /* OGRCleanupAll(); */ GDALClose(_ds); @@ -3321,7 +3288,6 @@ rt_raster_gdal_rasterize( rast = rt_raster_from_gdal_dataset(_ds); OGR_G_DestroyGeometry(src_geom); - if (src_sr != NULL) OSRDestroySpatialReference(src_sr); /* OGRCleanupAll(); */ GDALClose(_ds); diff --git a/raster/rt_core/rt_warp.c b/raster/rt_core/rt_warp.c index 854d179b5..8e97fe679 100644 --- a/raster/rt_core/rt_warp.c +++ b/raster/rt_core/rt_warp.c @@ -272,12 +272,9 @@ rt_raster rt_raster_gdal_warp( /* substitute spatial info (lack of) with a real one EPSG:32731 (WGS84/UTM zone 31s) */ if ( - FLT_EQ(gt[0], 0) && - FLT_EQ(gt[1], 1) && - FLT_EQ(gt[2], 0) && - FLT_EQ(gt[3], 0) && - FLT_EQ(gt[4], 0) && - FLT_EQ(gt[5], -1) + FLT_EQ(gt[0], 0) && FLT_EQ(gt[3], 0) && + FLT_EQ(gt[1], 1) && FLT_EQ(gt[5], -1) && + FLT_EQ(gt[2], 0) && FLT_EQ(gt[4], 0) ) { double ngt[6] = {166021.4431, 0.1, 0, 10000000.0000, 0, -0.1};