Line data Source code
1 : /*********************************************************************** 2 : * File : postgisrastertiledataset.cpp 3 : * Project: PostGIS Raster driver 4 : * Purpose: GDAL Dataset implementation for PostGIS Raster tile 5 : * Author: Jorge Arevalo, jorge.arevalo@deimos-space.com 6 : * jorgearevalo@libregis.org 7 : * 8 : * Last changes: $Id$ 9 : * 10 : *********************************************************************** 11 : * Copyright (c) 2013, Jorge Arevalo 12 : * Copyright (c) 2013, Even Rouault 13 : * 14 : * Permission is hereby granted, free of charge, to any person obtaining 15 : * a copy of this software and associated documentation files (the 16 : * "Software"), to deal in the Software without restriction, including 17 : * without limitation the rights to use, copy, modify, merge, publish, 18 : * distribute, sublicense, and/or sell copies of the Software, and to 19 : * permit persons to whom the Software is furnished to do so, subject to 20 : * the following conditions: 21 : * 22 : * The above copyright notice and this permission notice shall be 23 : * included in all copies or substantial portions of the Software. 24 : * 25 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26 : * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 : * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 : * NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 : * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30 : * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31 : * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 : * SOFTWARE. 33 : ************************************************************************/ 34 : #include "postgisraster.h" 35 : 36 : /************************ 37 : * \brief Constructor 38 : ************************/ 39 0 : PostGISRasterTileDataset::PostGISRasterTileDataset( 40 0 : PostGISRasterDataset *poRDSIn, int nXSize, int nYSize) 41 0 : : poRDS(poRDSIn), pszPKID(nullptr) 42 : { 43 0 : nRasterXSize = nXSize; 44 0 : nRasterYSize = nYSize; 45 : 46 0 : adfGeoTransform[GEOTRSFRM_TOPLEFT_X] = 0; 47 0 : adfGeoTransform[GEOTRSFRM_WE_RES] = 1; 48 0 : adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1] = 0; 49 0 : adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] = 0; 50 0 : adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] = 0; 51 0 : adfGeoTransform[GEOTRSFRM_NS_RES] = 1; 52 0 : } 53 : 54 : /************************ 55 : * \brief Destructor 56 : ************************/ 57 0 : PostGISRasterTileDataset::~PostGISRasterTileDataset() 58 : { 59 0 : if (pszPKID) 60 : { 61 0 : CPLFree(pszPKID); 62 0 : pszPKID = nullptr; 63 : } 64 0 : } 65 : 66 : /******************************************************** 67 : * \brief Get the affine transformation coefficients 68 : ********************************************************/ 69 0 : CPLErr PostGISRasterTileDataset::GetGeoTransform(double *padfTransform) 70 : { 71 : // copy necessary values in supplied buffer 72 0 : padfTransform[0] = adfGeoTransform[0]; 73 0 : padfTransform[1] = adfGeoTransform[1]; 74 0 : padfTransform[2] = adfGeoTransform[2]; 75 0 : padfTransform[3] = adfGeoTransform[3]; 76 0 : padfTransform[4] = adfGeoTransform[4]; 77 0 : padfTransform[5] = adfGeoTransform[5]; 78 : 79 0 : return CE_None; 80 : } 81 : 82 : /******************************************************** 83 : * \brief Return spatial extent of tile 84 : ********************************************************/ 85 0 : void PostGISRasterTileDataset::GetExtent(double *pdfMinX, double *pdfMinY, 86 : double *pdfMaxX, double *pdfMaxY) const 87 : { 88 : // FIXME; incorrect in case of non 0 rotation terms 89 : 90 0 : double dfMinX = adfGeoTransform[GEOTRSFRM_TOPLEFT_X]; 91 0 : double dfMaxY = adfGeoTransform[GEOTRSFRM_TOPLEFT_Y]; 92 : 93 0 : double dfMaxX = adfGeoTransform[GEOTRSFRM_TOPLEFT_X] + 94 0 : nRasterXSize * adfGeoTransform[GEOTRSFRM_WE_RES] + 95 0 : nRasterYSize * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1]; 96 : 97 0 : double dfMinY = adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] + 98 0 : nRasterXSize * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] + 99 0 : nRasterYSize * adfGeoTransform[GEOTRSFRM_NS_RES]; 100 : 101 : // In case yres > 0 102 0 : if (dfMinY > dfMaxY) 103 : { 104 0 : double dfTemp = dfMinY; 105 0 : dfMinY = dfMaxY; 106 0 : dfMaxY = dfTemp; 107 : } 108 : 109 0 : *pdfMinX = dfMinX; 110 0 : *pdfMinY = dfMinY; 111 0 : *pdfMaxX = dfMaxX; 112 0 : *pdfMaxY = dfMaxY; 113 0 : }