天地图下载工具

package com;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;

public class ThreadTileCreate extends Thread{

private int  minxt;
        private int  minyt;
        private int  maxxt;
        private int  maxyt;
        private int  zoomt;
        private static int threadCount = 0;
        private int threadNum = ++threadCount;
       
        public static void main(String[] args)
        {
           
            //System.out.println("最小经度");
            double minlon = 73.5;
            //System.out.println("最小纬度");
            double minlat = 3.5;
            //System.out.println("最大经度");
            double maxlon = 135;
            //System.out.println("最大纬度");
            double maxlat = 53.8;
           
           
            //下载级别
            int zoom = 5;   // 6,7,8,9,10
            int nGrid = (int)Math.pow(2, zoom);
            double dx = nGrid;
            dx = dx/360;
   
            int minx = nGrid - (int)(dx * (180.0-minlon));
            double y =  Math.sin(maxlat *Math.PI / 180);
            y = Math.log((1.0+y)/(1.0-y));
           
            int miny = (int)Math.abs((0.5-y/(4.0*Math.PI))*nGrid);//注意最大纬度及最小行号
            int maxx = nGrid - (int)(dx * (180.0-maxlon));
           
            y =  Math.sin(minlat *Math.PI / 180);
            y = Math.log((1.0+y)/(1.0-y));
            int maxy = (int)Math.abs((0.5-y/(4.0*Math.PI))*nGrid);//注意最小纬度及最大行号
           
           
           
            int il = 10;
            int jr = 10;
            //启用的线程数
            int threadCount = il*jr;
            System.out.println("即将启用的线程数为:"+threadCount+"个!");
           
            //各个线程要切的范围
            int ax = (maxx-minx)/jr;
            int by = (maxy-miny)/il;
           
            //System.out.println(maxx+"=="+minx+"=="+maxy+"=="+miny+"=="+ax+"=="+by);
            int minxv =0;
            int maxxv =0;
            int maxyv =0;
            int minyv =0;
           
            for(int j=0;j<jr;j++)
            {
                for(int i=0; i<il; i++)
                {
                    try
                    {
                        Thread.sleep(50);
                        minxv = ax*i+minx;
                        if(i==il-1)
                        {
                            maxxv = maxx;
                        }else
                        {
                            maxxv = ax*(i+1)+minx;
                        }
                       
                        minyv = by*j+miny;
                        if(j==jr-1)
                        {
                            maxyv = maxy;
                        }else
                        {
                            maxyv =by*(j+1)+miny;
                        }
                        //System.out.println(maxxv+"=="+minxv+"=="+maxyv+"=="+minyv+"=="+ax+"=="+by);
                       
                        ThreadTileCreate t = new ThreadTileCreate();
                        t.setMaxxt(maxxv);
                        t.setMaxyt(maxyv);
                        t.setMinxt(minxv);
                        t.setMinyt(minyv);
                        t.setZoomt(zoom);
                        t.start();
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
           
        }
        public void run()
        {
            System.out.println(threadNum+"开始下载数据..."+maxxt+"=="+minxt+"=="+maxyt+"=="+minyt+"=="+zoomt);
            DownImage(minxt, minyt, maxxt, maxyt,zoomt);
            System.out.println(threadNum+"结束下载数据.");
        }
       
        public static void DownImage(int minx,int miny,int maxx,int maxy,int zoom) {

System.out.println("正在下载数据第" + zoom+ "层...");
            for(int i=minx;i<maxx+1; i++){
                for(int j=miny; j<maxy+1; j++){
                    //道路标注
                    String url =  "http://t3.tianditu.com/cva_w/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=cva&STYLE=default&FORMAT=tiles&TILEMATRIXSET=w&TILEMATRIX=" + zoom + "&TILEROW=" + j + "&TILECOL=" + i;
                    //道路图
                    String url1 = "http://t3.tianditu.com/vec_w/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=vec&STYLE=default&FORMAT=tiles&TILEMATRIXSET=w&TILEMATRIX=" + zoom + "&TILEROW=" + j + "&TILECOL=" + i;
                    //地形标注
                    //String url2 = "http://t0.tianditu.com/cta_w/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=cta&STYLE=default&FORMAT=tiles&TILEMATRIXSET=w&TILEMATRIX=" + zoom + "&TILEROW=" + j + "&TILECOL=" + i;
                    //地形
                    //String url3 = "http://t0.tianditu.com/ter_w/wmts?SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&LAYER=ter&STYLE=default&FORMAT=tiles&TILEMATRIXSET=w&TILEMATRIX=" + zoom + "&TILEROW=" + j + "&TILECOL=" + i;
                   
                    //道路标注
                    //String url =  "http://t7.tianditu.com/DataServer?T=cva_c&x="+i+"&y="+j+"&l=" + zoom;
                    //道路图
                    //String url1 = "http://t2.tianditu.com/DataServer?T=vec_c&x="+i+"&y="+j+"&l=" + zoom;
                   
                   
                   
                    try {
                       
                        if(downImage(i,j,zoom,url,0) == -1)
                        {
                            System.out.println(url);
                        }
                        if(downImage(i,j,zoom,url1,1) == -1)
                        {
                            System.out.println(url1);
                        }
                        /*if(zoom<15){
                            if(downImage(i,j,
                            zoom,url2,2) == -1)
                            {
                                System.out.println(url2);
                            }
                            if(downImage(i,j,zoom,url3,3) == -1)
                            {
                                System.out.println(url3);
                            }
                        }*/

} catch (IOException e) {
                        //TODO Auto-generated catch block
                        //e.printStackTrace();
                    }
                }
            }
           
        } 
        private static int downImage(int x,int y,int z,String ul,int num) throws IOException{
            URL url;
            try {
                url = new URL(ul);
               
                String path = "";
                if(num == 0)
                    path = "f:\\TDTMap\\Label\\" + z + "\\";
                else if(num == 1)
                    path = "f:\\TDTMap\\Map\\" + z + "\\";
                else if(num == 2)
                    path = "f:\\TDTMap\\TLabel\\" + z + "\\";
                else if(num == 3)
                    path = "f:\\TDTMap\\TMap\\" + z + "\\";
               
                String fname = x + "-" + y +  ".png";
                File f = new File(path);
                if(!f.exists()){
                    f.mkdirs();
                }
                if(new File(path + fname).exists())
                {
                    return 0;
                }
                HttpURLConnection con;
                con = (HttpURLConnection) url.openConnection(); 
                int state = con.getResponseCode(); 
                if (state == 200) {
                    File outFile = new File(path + fname);
                    OutputStream os = new FileOutputStream(outFile);
                    InputStream is = url.openStream();
                    byte[] buff = new byte[1024];
                    while(true) {
                        int readed = is.read(buff);
                        if(readed == -1) {
                            break;
                        }
                        byte[] temp = new byte[readed];
                        System.arraycopy(buff, 0, temp, 0, readed);
                        os.write(temp);
                    }
                    is.close();
                    os.close();
                }
                else
                {
                    return -1;
                }
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
           
            return 0;
        }
        public int getMinxt() {
            return minxt;
        }
        public void setMinxt(int minxt) {
            this.minxt = minxt;
        }
        public int getMinyt() {
            return minyt;
        }
        public void setMinyt(int minyt) {
            this.minyt = minyt;
        }
        public int getMaxxt() {
            return maxxt;
        }
        public void setMaxxt(int maxxt) {
            this.maxxt = maxxt;
        }
        public int getMaxyt() {
            return maxyt;
        }
        public void setMaxyt(int maxyt) {
            this.maxyt = maxyt;
        }
        public int getZoomt() {
            return zoomt;
        }
        public void setZoomt(int zoomt) {
            this.zoomt = zoomt;
        }       
    }

-----------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------

时间: 2024-10-12 21:19:40

天地图下载工具的相关文章

linux下多线程下载工具axel的编译安装

axel 是Linux 命令行下多线程的下载工具,支持断点续传,速度通常情况下是Wget的几倍 官方主页:http://axel.alioth.debian.org/ 源码下载: #curl -O http://pkgs.fedoraproject.org/repo/pkgs/axel/axel2.4.tar.gz/a2a762fce0c96781965c8f9786a3d09d/axel-2.4.tar.gz 编译安装: # tar -xvf axel-2.4.tar.gz  && cd

wget下载工具

转自于:http://www.jb51.net/LINUXjishu/86326.html 1.使用wget下载单个文件  1 e.g. 2 3 wget http://cn.wordpress.org/wordpress-3.1-zh_CN.zip 4 5 #下载文件,并保存在当前目录下 6 #下载过程显示进度条,当前下载速度,剩余下载时间等 2.使用wget -O 下载并以不同的文件名保存  1 e.g. 2 3 wget http://www.centos.bz/download?id=1

Linux下多线程下载工具MWget和Axel使用介绍

linux运维在操作linux过程中,用得最多的linux下载工具想必一定是wget,没有看到哪一台服务器没装过wget的,或许有人使用ftp下载,也有人使用多线程的axel以及ProZilla,毫无疑问这两个工具都非常的出色,但是对于习惯使用wget的人来说显得不适应,于是老外便开发了多线程版本的wget工具mwget,m表示multi多线程的意思. mwget官方地址:http://sourceforge.net/projects/kmphpfm/?source=dlp # cd /usr/

Ubuntu下很给力的下载工具

Windows下的下载工具--迅雷,之所下面载速度快,乃是它能搜索资源.为己所用,而不是只从原始地址这单一资源处下载. Ubuntu下也有类似的工具,那就是aira2. aira2是一个命令行下载工具,能够配合其它图形界面的下载软件使用.我用的是uget+aria2.uget本身是一个小巧有用的多线程下载工具,加上aria2作为插件,下载速度有明显提高. 一.安装. uget和aria2都能够在"软件中心"中安装,可是版本号太老啦,无法发挥作用,所以不妨在终端中加入ppa进行安装: 1

google兴趣点下载工具

继上次百度兴趣点版本的发布以后,发现百度只能下载本国数据,并且数据完整度还是和google的少一些,所以本次经过钻研与解密,实现了google地图下载工具,版本的主要功能如下: 1.支持多线程下载,支持16进程下载,用户自己选择设置. 2.支持全球数据下载. 3.数据完整性高,按分类下载,可以选择已有分类,也可以输入分类或者关键字下载. 4.数据坐标精确,数据无偏移. 联系方式QQ:204843224 本工具用于学术研究及技术讨论,获取的数据不用于商业盈利,数据版权归Google及其合作单位所有

HttpUtils.java 网络下载工具类

package Http; import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL; /** * 网络下载工具类 * 功能:下载字节数组,下载文本数据 * 下载数字数组(文本 图片 mp3) * 下载文本数据 * Created by lxj-pc on 2017/

兴趣点下载工具

最近自己写了一个百度POI下载工具,通过大家的反馈还是蛮好的,也感谢大家对工具的喜欢,也希望工具可以帮助大家在工作中解决一下问题.接下来对工具的功能进行一下描述,希望刚接触的朋友多了解一下它的价值及意义. 全国任意范围抓取:本工具是本人充分了解了百度兴趣点的展示方式以后根据展示的规则去抓取的,支持全国范围内的多有POI 数据的抓取. 数据全面,不留任何死角,百度有多少就能抓多少. 经过比较准确的纠偏处理,可提供火星坐标,WGS84原始坐标,无偏移.如果有意想要可联系:QQ694056037

Ubuntu系统下载工具的推荐

大家在上手一段时间Ubuntu系统后可能突然想起最近新出了一些电影,想要下载来看看,但是wine运行迅雷要么没反应.要么启动了也不能下载,针对这个问题,根据我的使用体验推荐大家两款下载工具: 1.Deluge 这是一款挽救BT的下载软件,支持去年悄然流行的Magnet磁力链接,“磁力链接”的技术原理类似“指纹识别”,能将不同文件内容的Hash 结果,生成一个纯文本的“数字指纹”,以此来识别文件,而不是像过去的BT种子基于文件的位置或者名称识别文件. 磁力链接可以解决BT下载不稳定.断种不能续传的

汉澳sinox高速下载工具axel

汉澳sinox高速下载工具axel 一直用wget.浏览器单线程下载等啊等,没完没了,必须使出刹手锏. 汉澳sinox高速下载工具axel,不是exel,读作 阿克啸 安装 cd /usr/ports/ftp/axel;make install clean 然后运行axel -n 10 网址,其中-n 后面指定多线程数量. 然后就以10倍速度download,不需要安装旋风下载等等,那还不稳定.