#include "stdafx.h"
#pragma comment(lib, "gdal_i.lib")
#include "include/gdal/gdal.h"
#include "include/gdal/gdal_priv.h"
#include "iostream"
#include "fstream"
#include <io.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include "include/gdal/ogr_spatialref.h"
#include "include/gdal/cpl_minixml.h"
#include "include/gdal/gdal_alg.h"
#include "include/gdal/gdalwarper.h"
#include <afx.h>
#include "math.h"
#define PI 3.1415926535
#define originShift 20037508.342789244
#define initialResolution 156543.03392804097
#define tileSize 256
using namespace std;
typedef unsigned char BYTE;
double cost_time;
clock_t start,end;
class Mercator
{
public:
double mx,my;//墨卡托
double lat,lon;//经纬度
double tx,ty;//瓦片
double px,py;//像素
double zoom;//级数
double px6,py6;
double minx,miny;//最小点
double maxx,maxy;//最大点
double minlat,minlon;//第9个函数
double maxlat,maxlon;
public:
void LatLonToMeters(double lat,double lon);
void MetersToLatLon(double mx,double my );
void PixelsToMeters(double px,double py,double zoom);
void MetersToPixels(double mx,double my,double zoom);
void PixelsToTile(double px,double py);
void PixelsToRaster(double px,double py,double zoom);
void MetersToTile(double mx,double my,double zoom);
void TileBounds(double tx,double ty,double zoom);
void TileLatLonBounds(double tx,double ty,double zoom );
double Resolution(double zoom );
int ZoomForPixelSize(double pixelSize );
protected:
private:
};
void Mercator::LatLonToMeters(double lat,double lon)
{
double mxx= lon *originShift/180.0;
double myy= log(tan((90 +lat) * PI/ 360.0 ))/(PI/180.0);
myy = myy *originShift/180.0;
mx=mxx;
my=myy;
}
void Mercator::MetersToLatLon(double mx,double my)
{
double lonn = (mx / originShift) * 180.0;
double latt = (my / originShift) * 180.0;
latt = 180 /PI * (2 * atan(exp( latt * PI / 180.0)) -PI / 2.0);
lon=lonn;
lat=latt;
}
void Mercator::PixelsToMeters(double px,double py,double zoom)
{
double res=initialResolution /(pow(2,zoom));
double mxx = px * res - originShift;
double myy = py * res - originShift;
mx=mxx;
my=myy;
}
void Mercator::MetersToPixels(double mx,double my,double zoom)
{
double res=initialResolution /(pow(2,zoom));
double pxx = (mx + originShift) / res;
double pyy = (my + originShift) / res;
px=pxx;
py=pyy;
}
void Mercator::PixelsToTile(double px,double py)
{
double txx = int( ceil( px / float(tileSize) ) - 1 );
double tyy = int( ceil( py / float(tileSize) ) - 1 );
tx=txx;
ty=tyy;
}
void Mercator::PixelsToRaster(double px,double py,double zoom)
{
double mapSize = tileSize*(pow(2,zoom));
px6=px;
py6=mapSize - py;
}
void Mercator::MetersToTile(double mx,double my,double zoom)
{
double res=initialResolution /(pow(2,zoom));
double pxx=(mx+originShift) / res;
double pyy=(my+originShift) / res;
px=pxx;
py=pyy;
double txx = int( ceil( px / float(tileSize) ) - 1 );
double tyy = int( ceil( py / float(tileSize) ) - 1 );
tx=txx;
ty=tyy;
}
void Mercator::TileBounds(double tx,double ty,double zoom)
{
//minx, miny = PixelsToMeters( tx*tileSize, ty*tileSize, zoom )
double res=initialResolution /(pow(2,zoom));
double mxx = tx*tileSize * res - originShift;
double myy = ty*tileSize * res - originShift;
minx=mxx;
miny=myy;
//maxx, maxy = PixelsToMeters( (tx+1)*tileSize, (ty+1)*tileSize, zoom )
//double res=initialResolution /(pow(2,zoom));
mxx = (tx+1)*tileSize* res - originShift;
myy = (ty+1)*tileSize* res - originShift;
maxx=mxx;
maxy=myy;
}
void Mercator::TileLatLonBounds(double tx,double ty,double zoom )
{
//bounds = TileBounds( tx, ty, zoom)
double res=initialResolution /(pow(2,zoom));
double mxx = tx*tileSize * res - originShift;
double myy = ty*tileSize * res - originShift;
minx=mxx;
miny=myy;
mxx = (tx+1)*tileSize* res - originShift;
myy = (ty+1)*tileSize* res - originShift;
maxx=mxx;
maxy=myy;
//minLat, minLon = MetersToLatLon(bounds[0], bounds[1])
double lonn = (minx / originShift) * 180.0;
double latt = (miny / originShift) * 180.0;
latt = 180 /PI * (2 * atan(exp( lat * PI / 180.0)) -PI / 2.0);
minlon=lonn;
minlat=latt;
//maxLat, maxLon = MetersToLatLon(bounds[2], bounds[3])
lonn = (maxx / originShift) * 180.0;
latt = (maxy / originShift) * 180.0;
latt = 180 /PI * (2 * atan(exp( lat * PI / 180.0)) -PI / 2.0);
maxlon=lonn;
maxlat=latt;
}
double Mercator::Resolution(double zoom )
{
return initialResolution /(pow(2,zoom));
}
int Mercator::ZoomForPixelSize(double pixelSize )
{
for (int i=0;i<18;i++)
{
if (pixelSize>Resolution(i))
{
if(i!=0)
return i-1;
}
//else
// /*return 0;*/
}
}
struct Zdzx
{
int rx, ry, rxsize, rysize;
int wx, wy, wxsize, wysize;
};
void geo_query( double minx, double maxy,double miny,double maxx ,double omaxy,int xsize,int ysize,double xx,double xx1,double xx5,Zdzx &cx)
{
int rx, ry, rxsize, rysize;
int wx, wy, wxsize, wysize;
int rxshift=0,ryshift=0;
wxsize = 256;
wysize = 256;
rx= int((minx - xx)/xx1 + 0.001);
ry= int((maxy - omaxy)/xx5 + 0.001);
rxsize= (int)( (maxx - minx) / xx1+ 0.5);
rysize= (int)( (miny - maxy) / xx5+ 0.5);
wx = 0;
if (rx<0)
{
rxshift = abs(rx);
wx = (int)( wxsize * rxshift / rxsize+0.001) ;
wxsize = wxsize - wx;
rxsize = rxsize -( int)( rxsize * rxshift / rxsize+0.5) ;
rx=0;
};
if (rx+rxsize>xsize)
{
wxsize = (int)( wxsize * (xsize - rx) / rxsize);
rxsize = xsize - rx;
};
wy=0;
if (ry<0)
{
ryshift = abs(ry);
wy = (int)( wysize * ryshift/ rysize );
wysize = wysize - wy;
rysize = rysize -( int)( rysize * ryshift/ rysize );
ry = 0;
};
if (ry+rysize > ysize)
{
wysize = (int)( wysize * (ysize - ry) / rysize);
rysize = ysize - ry;
};
cx.rx=rx;
cx.ry=ry;
cx.rxsize=rxsize;
cx.rysize=rysize;
cx.wx=wx;
cx.wxsize=wxsize;
cx.wy=wy;
cx.wysize=wysize;
};
CString CreateFolder(CString path1,CString path2,CString path3,CString filename,CString fileExtension)
{
CString path=path1;
path+="//"+path2;
CreateDirectory(path,NULL);
path+="//"+path3;
CreateDirectory(path,NULL);
path+="//"+filename+fileExtension;
return path;
};
int main()
{
CPLErr errocode;//错误标记
start=clock(); //开始的时候记录时间
GDALAllRegister();
GDALDataset *poDataset;
poDataset = (GDALDataset *) GDALOpen( "d:/test/jl1.tif", GA_ReadOnly );
const char * oTargetSRS=NULL;
const char * oSourceSRS=GDALGetProjectionRef(poDataset);
CString ss;
ss="PROJCS[\"Google Maps Global Mercator\",\n\
GEOGCS[\"WGS 84\",\n\
DATUM[\"WGS_1984\",\n\
SPHEROID[\"WGS 84\",6378137,298.2572235630016,\n\
AUTHORITY[\"EPSG\",\"7030\"]],\n\
AUTHORITY[\"EPSG\",\"6326\"]],\n\
PRIMEM[\"Greenwich\",0],\n\
UNIT[\"degree\",0.0174532925199433],\n\
AUTHORITY[\"EPSG\",\"4326\"]],\n\
PROJECTION[\"Mercator_1SP\"],\n\
PARAMETER[\"central_meridian\",0],\n\
PARAMETER[\"scale_factor\",1],\n\
PARAMETER[\"false_easting\",0],\n\
PARAMETER[\"false_northing\",0],\n\
UNIT[\"metre\",1,\n\
AUTHORITY[\"EPSG\",\"9001\"]]]";
oTargetSRS=ss;
GDALDataset *poDataset5=
(GDALDataset *)GDALAutoCreateWarpedVRT ( poDataset, oSourceSRS, oTargetSRS, GRA_NearestNeighbour, 0.0, NULL);
double adfGeoTransform[6],zuichude[6];
poDataset5->GetGeoTransform( adfGeoTransform ) ;
poDataset->GetGeoTransform( zuichude ) ;
///////////////////////////////////////////////////////////////////////////
double ominx,ominy,omaxx,omaxy;
int xsize,ysize,tilesize=256;
xsize=poDataset5->GetRasterXSize();
ysize=poDataset5->GetRasterYSize();
ominx = adfGeoTransform[0];
omaxx = adfGeoTransform[0]+xsize*adfGeoTransform[1];
omaxy= log(tan((90 +zuichude[3]) * PI/ 360.0 ))/(PI/180.0)*o
没有合适的资源?快使用搜索试试~ 我知道了~
GEOTIFF图片切割
共85个文件
h:59个
user:3个
dll:3个
需积分: 18 23 下载量 187 浏览量
2012-11-26
01:59:25
上传
评论 1
收藏 5.65MB RAR 举报
温馨提示
c++ win32控制台程序,实现对GEOtiff图片进行切割,并保存结果
资源推荐
资源详情
资源评论
收起资源包目录
Mapcut.rar (85个子文件)
Mapcut
zhh2.suo 28KB
Debug
zhh2.exp 15KB
zhh2.pdb 1.82MB
zhh2.exe 128KB
zhh2.lib 25KB
zhh2.ilk 912KB
zhh2
resource.h 383B
gdal_i.lib 917KB
zhh2.cpp 22KB
gdal17.dll 5.49MB
zhh2.vcproj.E36309439A6842A.Administrator.user 1KB
Debug
vc90.pdb 452KB
vc90.idb 579KB
BuildLog.htm 9KB
mt.dep 69B
zhh2.exe.intermediate.manifest 861B
zhh2.obj 384KB
proj.dll 215KB
zhh2.vcproj 4KB
CreatDIR.cpp 3KB
stdafx.h 233B
CreatDIR.h 117B
zhh2.vcproj.Nelson-PC.Nelson.user 1KB
stdafx.cpp 209B
zhh2.vcproj.F9C31A2C779147E.Administrator.user 1KB
Microsoft.VC90.DebugOpenMP.manifest 477B
vcomp90d.dll 90KB
targetver.h 498B
include
gdal
cpl_wince.h 2KB
gdalwarper.h 15KB
cpl_win32ce_api.h 3KB
cpl_config_extras.h 471B
ogr_attrind.h 4KB
cpl_list.h 3KB
gvgcpfit.h 3KB
ogr_srs_esri_names.h 5KB
cpl_quad_tree.h 4KB
ogr_expat.h 2KB
cpl_hash_set.h 3KB
cpl_minizip_ioapi.h 3KB
cpl_csv.h 3KB
rawdataset.h 6KB
gdal_proxy.h 16KB
gdal_version.h 699B
cpl_http.h 3KB
ogr_geos.h 2KB
cpl_vsi.h 10KB
cpl_config.h 3KB
cpl_multiproc.h 5KB
ogr_geometry.h 23KB
swq.h 6KB
ogr_featurestyle.h 19KB
ogr_api.h 21KB
cpl_odbc.h 9KB
gdal_priv.h 30KB
gdaljp2metadata.h 5KB
cpl_port.h 17KB
vrtdataset.h 24KB
ogr_spatialref.h 24KB
cpl_error.h 5KB
cpl_minizip_unzip.h 13KB
ogr_srs_api.h 32KB
cpl_string.h 10KB
gdal_alg.h 17KB
gdal_vrt.h 4KB
cpl_vsi_virtual.h 5KB
gdalgrid.h 4KB
gdal_pam.h 12KB
ogr_p.h 5KB
cpl_time.h 2KB
gdal.h 33KB
gdal_frmts.h 6KB
ogrsf_frmts.h 12KB
cplkeywordparser.h 3KB
cpl_conv.h 11KB
thinplatespline.h 5KB
gdal_rat.h 5KB
ogr_feature.h 13KB
cpl_atomic_ops.h 4KB
gdal_alg_priv.h 5KB
ogr_core.h 15KB
memdataset.h 5KB
cpl_minixml.h 6KB
zhh2.ncb 11.49MB
zhh2.sln 878B
共 85 条
- 1
资源评论
Geomaticer_WangG
- 粉丝: 10
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功