📄 dtedtranform.cpp
字号:
/******************************************************************************* $Id: dted_test.c 9482 2006-04-04 01:00:27Z fwarmerdam $** Project: DTED Translator* Purpose: Test mainline for DTED writer.* Author: Frank Warmerdam, warmerdam@pobox.com******************************************************************************** Copyright (c) 2001, Frank Warmerdam** Permission is hereby granted, free of charge, to any person obtaining a* copy of this software and associated documentation files (the "Software"),* to deal in the Software without restriction, including without limitation* the rights to use, copy, modify, merge, publish, distribute, sublicense,* and/or sell copies of the Software, and to permit persons to whom the* Software is furnished to do so, subject to the following conditions:** The above copyright notice and this permission notice shall be included* in all copies or substantial portions of the Software.** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER* DEALINGS IN THE SOFTWARE.*****************************************************************************/#include "gdal.h"#include "dted_api.h"#include <conio.h>
#include <ctype.h>
/************************************************************************//* Usage() *//************************************************************************/static void Usage(){ printf( "\n命令格式: MakeDTED [-trim] [-fill n] [-level n] --op oPath src_file\n\n" ); printf( "参数说明: \n" "-trim : 边界有效 [可缺省] \n" "-fill n : 填充 [可缺省] \n" "-level n : DTED Level [可缺省 默认为0] \n" "--op oPath : 输出绝对路径 [不可缺省] \n" "Src_File : 需要转换的源文件 [不可缺省] \n\n"); printf("按任意键退出...\n"); getch(); exit(0);}/************************************************************************//* main() *//************************************************************************/int main( int argc, char ** argv ){ GDALDatasetH hSrcDS; int iY, iX, nOutLevel=0, nXSize, nYSize, iArg, nFillDist=0; void *pStream; GInt16 *panData; const char *pszFilename = NULL; GDALRasterBandH hSrcBand; double adfGeoTransform[6]; int bEnableTrim = FALSE; const char *pszOutputPath = NULL; /* -------------------------------------------------------------------- */ /* Identify arguments. */ /* -------------------------------------------------------------------- */ for( iArg = 1; iArg < argc; iArg++ ) { if( EQUAL(argv[iArg],"-trim") ) bEnableTrim = TRUE; else if( EQUAL(argv[iArg],"-fill") ) nFillDist = atoi(argv[++iArg]); else if( EQUAL(argv[iArg],"-level") ) nOutLevel = atoi(argv[++iArg]); else if( EQUAL(argv[iArg],"--op") ) { pszOutputPath = argv[++iArg]; if( pszOutputPath == NULL ) { printf("输出路径无效...\n"); Usage(); } } else { if( pszFilename != NULL ) { printf("源文件名无效...\n"); Usage(); } pszFilename = argv[iArg]; } } if( pszFilename == NULL || pszOutputPath == NULL) Usage(); /* -------------------------------------------------------------------- */ /* Open input file. */ /* -------------------------------------------------------------------- */ GDALAllRegister(); hSrcDS = GDALOpen( pszFilename, GA_ReadOnly ); if( hSrcDS == NULL ) exit(1); printf("\n输入文件 [ %s ]\n\n",pszFilename); hSrcBand = GDALGetRasterBand( hSrcDS, 1 ); nXSize = GDALGetRasterXSize( hSrcDS ); nYSize = GDALGetRasterYSize( hSrcDS ); GDALGetGeoTransform( hSrcDS, adfGeoTransform ); /* -------------------------------------------------------------------- */ /* Create output stream. */ /* -------------------------------------------------------------------- */ pStream = DTEDCreatePtStream(pszOutputPath, nOutLevel ); printf("输出文件目录 [ %s ]\n\n",pszOutputPath); printf("输出DTED文件 Level [ %d ]\n\n",nOutLevel); if( pStream == NULL ) exit( 1 ); /* -------------------------------------------------------------------- */ /* Process all the profiles. */ /* -------------------------------------------------------------------- */ panData = (GInt16 *) malloc(sizeof(GInt16) * nXSize); for( iY = 0; iY < nYSize; iY++ ) { GDALRasterIO( hSrcBand, GF_Read, 0, iY, nXSize, 1, panData, nXSize, 1, GDT_Int16, 0, 0 ); for( iX = 0; iX < nXSize; iX++ ) { DTEDWritePt( pStream, adfGeoTransform[0] + adfGeoTransform[1] * (iX + 0.5) + adfGeoTransform[2] * (iY + 0.5), adfGeoTransform[3] + adfGeoTransform[4] * (iX + 0.5) + adfGeoTransform[5] * (iY + 0.5), panData[iX] ); } } free( panData ); /* -------------------------------------------------------------------- */ /* Cleanup. */ /* -------------------------------------------------------------------- */ if( bEnableTrim ) DTEDPtStreamTrimEdgeOnlyTiles( pStream ); if( nFillDist > 0 ) DTEDFillPtStream( pStream, nFillDist ); DTEDClosePtStream( pStream ); GDALClose( hSrcDS ); printf("\n完成对 [ %s ] 的转换\n 文件位于 [ %s ]\n",pszFilename, pszOutputPath); //getch(); exit( 0 );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -