Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Name: gdalmultidim_c_api_dimension.cpp 4 : * Project: GDAL Core 5 : * Purpose: C API for GDALDimension 6 : * Author: Even Rouault <even.rouault at spatialys.com> 7 : * 8 : ****************************************************************************** 9 : * Copyright (c) 2019, Even Rouault <even.rouault at spatialys.com> 10 : * 11 : * SPDX-License-Identifier: MIT 12 : ****************************************************************************/ 13 : 14 : #include "gdal_multidim.h" 15 : #include "gdalmultidim_priv.h" 16 : #include "gdal_fwd.h" 17 : 18 : /************************************************************************/ 19 : /* GDALDimensionRelease() */ 20 : /************************************************************************/ 21 : 22 : /** Release the GDAL in-memory object associated with a GDALDimension. 23 : * 24 : * Note: when applied on a object coming from a driver, this does not 25 : * destroy the object in the file, database, etc... 26 : */ 27 7514 : void GDALDimensionRelease(GDALDimensionH hDim) 28 : { 29 7514 : delete hDim; 30 7514 : } 31 : 32 : /************************************************************************/ 33 : /* GDALReleaseDimensions() */ 34 : /************************************************************************/ 35 : 36 : /** Free the return of GDALGroupGetDimensions() or GDALMDArrayGetDimensions() 37 : * 38 : * @param dims return pointer of above methods 39 : * @param nCount *pnCount value returned by above methods 40 : */ 41 3603 : void GDALReleaseDimensions(GDALDimensionH *dims, size_t nCount) 42 : { 43 10356 : for (size_t i = 0; i < nCount; i++) 44 : { 45 6753 : delete dims[i]; 46 : } 47 3603 : CPLFree(dims); 48 3603 : } 49 : 50 : /************************************************************************/ 51 : /* GDALDimensionGetName() */ 52 : /************************************************************************/ 53 : 54 : /** Return dimension name. 55 : * 56 : * This is the same as the C++ method GDALDimension::GetName() 57 : */ 58 306 : const char *GDALDimensionGetName(GDALDimensionH hDim) 59 : { 60 306 : VALIDATE_POINTER1(hDim, __func__, nullptr); 61 306 : return hDim->m_poImpl->GetName().c_str(); 62 : } 63 : 64 : /************************************************************************/ 65 : /* GDALDimensionGetFullName() */ 66 : /************************************************************************/ 67 : 68 : /** Return dimension full name. 69 : * 70 : * This is the same as the C++ method GDALDimension::GetFullName() 71 : */ 72 82 : const char *GDALDimensionGetFullName(GDALDimensionH hDim) 73 : { 74 82 : VALIDATE_POINTER1(hDim, __func__, nullptr); 75 82 : return hDim->m_poImpl->GetFullName().c_str(); 76 : } 77 : 78 : /************************************************************************/ 79 : /* GDALDimensionGetType() */ 80 : /************************************************************************/ 81 : 82 : /** Return dimension type. 83 : * 84 : * This is the same as the C++ method GDALDimension::GetType() 85 : */ 86 70 : const char *GDALDimensionGetType(GDALDimensionH hDim) 87 : { 88 70 : VALIDATE_POINTER1(hDim, __func__, nullptr); 89 70 : return hDim->m_poImpl->GetType().c_str(); 90 : } 91 : 92 : /************************************************************************/ 93 : /* GDALDimensionGetDirection() */ 94 : /************************************************************************/ 95 : 96 : /** Return dimension direction. 97 : * 98 : * This is the same as the C++ method GDALDimension::GetDirection() 99 : */ 100 38 : const char *GDALDimensionGetDirection(GDALDimensionH hDim) 101 : { 102 38 : VALIDATE_POINTER1(hDim, __func__, nullptr); 103 38 : return hDim->m_poImpl->GetDirection().c_str(); 104 : } 105 : 106 : /************************************************************************/ 107 : /* GDALDimensionGetSize() */ 108 : /************************************************************************/ 109 : 110 : /** Return the size, that is the number of values along the dimension. 111 : * 112 : * This is the same as the C++ method GDALDimension::GetSize() 113 : */ 114 6044 : GUInt64 GDALDimensionGetSize(GDALDimensionH hDim) 115 : { 116 6044 : VALIDATE_POINTER1(hDim, __func__, 0); 117 6044 : return hDim->m_poImpl->GetSize(); 118 : } 119 : 120 : /************************************************************************/ 121 : /* GDALDimensionGetIndexingVariable() */ 122 : /************************************************************************/ 123 : 124 : /** Return the variable that is used to index the dimension (if there is one). 125 : * 126 : * This is the array, typically one-dimensional, describing the values taken 127 : * by the dimension. 128 : * 129 : * The returned value should be freed with GDALMDArrayRelease(). 130 : * 131 : * This is the same as the C++ method GDALDimension::GetIndexingVariable() 132 : */ 133 140 : GDALMDArrayH GDALDimensionGetIndexingVariable(GDALDimensionH hDim) 134 : { 135 140 : VALIDATE_POINTER1(hDim, __func__, nullptr); 136 280 : auto var(hDim->m_poImpl->GetIndexingVariable()); 137 140 : if (!var) 138 11 : return nullptr; 139 129 : return new GDALMDArrayHS(var); 140 : } 141 : 142 : /************************************************************************/ 143 : /* GDALDimensionSetIndexingVariable() */ 144 : /************************************************************************/ 145 : 146 : /** Set the variable that is used to index the dimension. 147 : * 148 : * This is the array, typically one-dimensional, describing the values taken 149 : * by the dimension. 150 : * 151 : * This is the same as the C++ method GDALDimension::SetIndexingVariable() 152 : * 153 : * @return TRUE in case of success. 154 : */ 155 27 : int GDALDimensionSetIndexingVariable(GDALDimensionH hDim, GDALMDArrayH hArray) 156 : { 157 27 : VALIDATE_POINTER1(hDim, __func__, FALSE); 158 81 : return hDim->m_poImpl->SetIndexingVariable(hArray ? hArray->m_poImpl 159 54 : : nullptr); 160 : } 161 : 162 : /************************************************************************/ 163 : /* GDALDimensionRename() */ 164 : /************************************************************************/ 165 : 166 : /** Rename the dimension. 167 : * 168 : * This is not implemented by all drivers. 169 : * 170 : * Drivers known to implement it: MEM, netCDF. 171 : * 172 : * This is the same as the C++ method GDALDimension::Rename() 173 : * 174 : * @return true in case of success 175 : * @since GDAL 3.8 176 : */ 177 31 : bool GDALDimensionRename(GDALDimensionH hDim, const char *pszNewName) 178 : { 179 31 : VALIDATE_POINTER1(hDim, __func__, false); 180 31 : VALIDATE_POINTER1(pszNewName, __func__, false); 181 31 : return hDim->m_poImpl->Rename(pszNewName); 182 : }