Changeset 971:5a9501d50eb0
- Timestamp:
- 02/19/09 11:02:45 (18 months ago)
- Branch:
- default
- Convert:
- svn:1766ff46-f334-0410-ab20-d63176f87757/trunk@1049
- File:
-
- 1 edited
-
src/lassrs.cpp (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/lassrs.cpp
r969 r971 71 71 // FIXME: this needs to be cleaned up 72 72 73 //if (m_gtiff)74 //{75 //GTIFFree(m_gtiff);76 //m_gtiff = NULL;77 //}78 //if (m_tiff)79 //{80 //ST_Destroy(m_tiff);81 //m_tiff = NULL;82 //}73 if (m_gtiff) 74 { 75 GTIFFree(m_gtiff); 76 m_gtiff = NULL; 77 } 78 if (m_tiff) 79 { 80 ST_Destroy(m_tiff); 81 m_tiff = NULL; 82 } 83 83 84 84 … … 108 108 std::string const uid("LASF_Projection"); 109 109 110 // Wipe out any existing VLRs that might exist on the LASSRS 110 111 m_vlrs.clear(); 112 113 // We only copy VLR records from the list which are related to GeoTIFF keys. 114 // They must have an id of "LASF_Projection" and a record id that's related. 111 115 for (i = vlrs.begin(); i != vlrs.end(); ++i) 112 116 { 117 //GTIFF_GEOKEYDIRECTORY == 34735 113 118 if (uid == (*i).GetUserId(true).c_str() && 34735 == (*i).GetRecordId()) { 114 119 m_vlrs.push_back(*i); 115 120 } 121 122 // GTIFF_DOUBLEPARAMS == 34736 116 123 if (uid == (*i).GetUserId(true).c_str() && 34736 == (*i).GetRecordId()) { 117 124 m_vlrs.push_back(*i); 118 125 } 126 127 // GTIFF_ASCIIPARAMS == 34737 119 128 if (uid == (*i).GetUserId(true).c_str() && 34737 == (*i).GetRecordId()) { 120 129 m_vlrs.push_back(*i); … … 151 160 int atype =0; 152 161 153 if (!m_tiff) throw std::invalid_argument("m_tiff was null ");154 if (!m_gtiff) throw std::invalid_argument("m_gtiff was null ");162 if (!m_tiff) throw std::invalid_argument("m_tiff was null, cannot reset VLRs without m_tiff"); 163 if (!m_gtiff) throw std::invalid_argument("m_gtiff was null, cannot reset VLRs without m_gtiff"); 155 164 156 165 //GTIFF_GEOKEYDIRECTORY == 34735 … … 184 193 } 185 194 195 // GTIFF_DOUBLEPARAMS == 34736 196 ret = ST_GetKey(m_tiff, 34736, &dcount, &dtype, (void**)&ddata); 197 if (ret) 198 { 199 LASVLR record; 200 int i = 0; 201 record.SetRecordId(34736); 202 record.SetUserId("LASF_Projection"); 203 std::vector<uint8_t> data; 204 205 // Doubles are 8 bytes in length 206 uint16_t length = 8*dcount; 207 record.SetRecordLength(length); 208 209 // Copy the data into the data vector 210 for (i=0; i<dcount;i++) 211 { 212 dvalue = ddata[i]; 213 214 uint8_t* v = reinterpret_cast<uint8_t*>(&dvalue); 215 216 data.push_back(v[0]); 217 data.push_back(v[1]); 218 data.push_back(v[2]); 219 data.push_back(v[3]); 220 data.push_back(v[4]); 221 data.push_back(v[5]); 222 data.push_back(v[6]); 223 data.push_back(v[7]); 224 } 225 record.SetData(data); 226 m_vlrs.push_back(record); 227 } 228 186 229 // GTIFF_ASCIIPARAMS == 34737 187 230 ret = ST_GetKey(m_tiff, 34737, &acount, &atype, (void**)&adata); … … 193 236 record.SetUserId("LASF_Projection"); 194 237 std::vector<uint8_t> data; 195 238 239 // whoa. If the returned count was 0, it is because there 240 // was a bug in libgeotiff that existed before r1531 where it 241 // didn't calculate the string length for an ASCII geotiff tag. 242 // We need to throw an exception in this case because we're 243 // screwed, and if we don't we'll end up writing bad GeoTIFF keys. 244 if (!acount) { 245 throw std::runtime_error("GeoTIFF ASCII key with no returned size. " 246 "Upgrade your libgeotiff to a version greater " 247 "than r1531 (libgeotiff 1.2.6)"); 248 } 196 249 uint32_t length = acount; 197 250 record.SetRecordLength(length); … … 217 270 } 218 271 219 220 // GTIFF_DOUBLEPARAMS == 34736221 ret = ST_GetKey(m_tiff, 34736, &dcount, &dtype, (void**)&ddata);222 if (ret)223 {224 LASVLR record;225 int i = 0;226 record.SetRecordId(34736);227 record.SetUserId("LASF_Projection");228 std::vector<uint8_t> data;229 230 // Doubles are 8 bytes in length231 uint16_t length = 8*dcount;232 record.SetRecordLength(length);233 234 // Copy the data into the data vector235 for (i=0; i<dcount;i++)236 {237 dvalue = ddata[i];238 239 uint8_t* v = reinterpret_cast<uint8_t*>(&dvalue);240 241 data.push_back(v[0]);242 data.push_back(v[1]);243 data.push_back(v[2]);244 data.push_back(v[3]);245 data.push_back(v[4]);246 data.push_back(v[5]);247 data.push_back(v[6]);248 data.push_back(v[7]);249 }250 record.SetData(data);251 m_vlrs.push_back(record);252 }253 272 254 273 #endif // ndef HAVE_LIBGEOTIFF … … 259 278 260 279 #ifdef HAVE_LIBGEOTIFF 261 // if we're already set, don't overwrite 262 // FIXME this is a bug. 263 // if (m_gtiff) return m_gtiff; 280 // If we already have m_gtiff and m_tiff, that is because we have 281 // already called GetGTIF once before. VLRs ultimately drive how the 282 // LASSRS is defined, not the GeoTIFF keys. 283 if (m_tiff) {ST_Destroy(m_tiff); m_tiff = NULL;} 284 if (m_gtiff) {GTIFFree(m_gtiff); m_gtiff = NULL; } 264 285 265 286 m_tiff = ST_Create(); 266 287 std::string const uid("LASF_Projection"); 267 288 289 // Nothing is going to happen here if we don't have any VLRs describing 290 // SRS information on the LASSRS. 268 291 for (uint16_t i = 0; i < m_vlrs.size(); ++i) 269 292 { … … 298 321 return NULL; 299 322 } 300 301 323 302 324 /// Fetch the SRS as WKT … … 336 358 } 337 359 #else 338 ; 360 361 throw std::runtime_error("GDAL is not available, LASSRS could not be set from WKT"); 339 362 340 363 #endif … … 362 385 std::string tmp(proj4); 363 386 std::free(proj4); 364 387 388 delete poSRS; 389 365 390 return tmp; 366 391 … … 403 428 404 429 poSRS->exportToWkt(&poWKT); 430 delete poSRS; 431 405 432 std::string tmp(poWKT); 406 433 std::free(poWKT);
Note: See TracChangeset
for help on using the changeset viewer.
