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 ************************/
PostGISRasterTileDataset(PostGISRasterDataset * poRDS,int nXSize,int nYSize)39 PostGISRasterTileDataset::PostGISRasterTileDataset(PostGISRasterDataset* poRDS,
40 int nXSize,
41 int nYSize)
42 {
43 this->poRDS = poRDS;
44 this->pszPKID = NULL;
45 this->nRasterXSize = nXSize;
46 this->nRasterYSize = nYSize;
47
48 adfGeoTransform[GEOTRSFRM_TOPLEFT_X] = 0;
49 adfGeoTransform[GEOTRSFRM_WE_RES] = 1;
50 adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1] = 0;
51 adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] = 0;
52 adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] = 0;
53 adfGeoTransform[GEOTRSFRM_NS_RES] = 1;
54 }
55
56
57 /************************
58 * \brief Destructor
59 ************************/
~PostGISRasterTileDataset()60 PostGISRasterTileDataset::~PostGISRasterTileDataset()
61 {
62 if (pszPKID) {
63 CPLFree(pszPKID);
64 pszPKID = NULL;
65 }
66 }
67
68 /********************************************************
69 * \brief Get the affine transformation coefficients
70 ********************************************************/
GetGeoTransform(double * padfTransform)71 CPLErr PostGISRasterTileDataset::GetGeoTransform(double * padfTransform) {
72 // copy necessary values in supplied buffer
73 padfTransform[0] = adfGeoTransform[0];
74 padfTransform[1] = adfGeoTransform[1];
75 padfTransform[2] = adfGeoTransform[2];
76 padfTransform[3] = adfGeoTransform[3];
77 padfTransform[4] = adfGeoTransform[4];
78 padfTransform[5] = adfGeoTransform[5];
79
80 return CE_None;
81 }
82
83 /********************************************************
84 * \brief Return spatial extent of tile
85 ********************************************************/
GetExtent(double * pdfMinX,double * pdfMinY,double * pdfMaxX,double * pdfMaxY)86 void PostGISRasterTileDataset::GetExtent(double* pdfMinX, double* pdfMinY,
87 double* pdfMaxX, double* pdfMaxY)
88 {
89 // FIXME; incorrect in case of non 0 rotation terms
90
91 double dfMinX = adfGeoTransform[GEOTRSFRM_TOPLEFT_X];
92 double dfMaxY = adfGeoTransform[GEOTRSFRM_TOPLEFT_Y];
93
94 double dfMaxX = adfGeoTransform[GEOTRSFRM_TOPLEFT_X] +
95 nRasterXSize * adfGeoTransform[GEOTRSFRM_WE_RES] +
96 nRasterYSize * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM1];
97
98 double dfMinY = adfGeoTransform[GEOTRSFRM_TOPLEFT_Y] +
99 nRasterXSize * adfGeoTransform[GEOTRSFRM_ROTATION_PARAM2] +
100 nRasterYSize * adfGeoTransform[GEOTRSFRM_NS_RES];
101
102 // In case yres > 0
103 if( dfMinY > dfMaxY )
104 {
105 double dfTemp = dfMinY;
106 dfMinY = dfMaxY;
107 dfMaxY = dfTemp;
108 }
109
110 *pdfMinX = dfMinX;
111 *pdfMinY = dfMinY;
112 *pdfMaxX = dfMaxX;
113 *pdfMaxY = dfMaxY;
114 }
115