├── README.md
├── .idea
├── description.html
├── project-template.xml
├── encodings.xml
├── .gitignore
├── modules.xml
└── misc.xml
├── out
└── production
│ └── testjava
│ └── com
│ └── company
│ ├── Main.class
│ └── Test.class
├── tianditudownloader.sh
├── testjava.iml
└── src
└── com
└── company
├── Main.java
└── Test.java
/README.md:
--------------------------------------------------------------------------------
1 | # tianditudownloader
2 |
--------------------------------------------------------------------------------
/.idea/description.html:
--------------------------------------------------------------------------------
1 | Simple Java application that includes a class with main() method
--------------------------------------------------------------------------------
/.idea/project-template.xml:
--------------------------------------------------------------------------------
1 |
2 | IJ_BASE_PACKAGE
3 |
--------------------------------------------------------------------------------
/out/production/testjava/com/company/Main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reference/tianditudownloader/main/out/production/testjava/com/company/Main.class
--------------------------------------------------------------------------------
/out/production/testjava/com/company/Test.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/reference/tianditudownloader/main/out/production/testjava/com/company/Test.class
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/tianditudownloader.sh:
--------------------------------------------------------------------------------
1 | echo "# tianditudownloader" >> README.md
2 | git init
3 | git add README.md
4 | git commit -m "first commit"
5 | git branch -M main
6 | git remote add origin https://github.com/reference/tianditudownloader.git
7 | git push -u origin main
8 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/testjava.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/com/company/Main.java:
--------------------------------------------------------------------------------
1 | package com.company;
2 |
3 | import java.io.File;
4 | import java.net.MalformedURLException;
5 | import java.net.URL;
6 |
7 | public class Main {
8 |
9 | public static void main(String[] args) {
10 | double[] re = Test.getResolutions(18);
11 | double[] extent = {106.54,21.59,108.26,23.20};
12 |
13 | for(int z=0;z<18;z++){
14 | int totalX = (int)Math.ceil(360.0/(re[z]*256.0)); //列数向上取整
15 | int totalY = (int)Math.ceil(180.0/(re[z]*256.0)); //行数向上取整 */
16 |
17 | //起始结束列
18 | int sX = (int)Math.floor(((extent[0] + 180) / 360) * totalX);
19 | int eX = (int)Math.floor(((extent[2] + 180) / 360) * totalX);
20 |
21 | //起始结束行
22 | int sY = (int)Math.floor(((90 - extent[3]) / 180) * totalY);
23 | int eY = (int)Math.floor(((90 - extent[1]) / 180) * totalY);
24 |
25 | for(int y=sY;y<=eY;y++){
26 | for(int x=sX;x<=eX;x++){
27 | //http://t0.tianditu.com/vec_w/wmts?service=wmts&request=gettile&version=1.0.0&layer=vec&format=tiles&tilematrixset=w&tk=502e05b68ea427c201f63ec608d7f0d7
28 | String urlstr = "http://t0.tianditu.com/DataServer?T=vec_c&x="+x+"&y="+y+"&l="+z+"&tk=502e05b68ea427c201f63ec608d7f0d7";
29 | //天地图服务器t0-t8间选一个
30 | System.out.println(urlstr);
31 | String path = "/Users/admin/Desktop/maptiles/"+z + File.separator+y+File.separator+x+".png";
32 | File file = new File(path);
33 | URL url = null;
34 | try {
35 | url = new URL(urlstr);
36 | Test.download(url,file);
37 | } catch (Exception e) {
38 | e.printStackTrace();
39 | }
40 | }
41 | }
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/com/company/Test.java:
--------------------------------------------------------------------------------
1 | package com.company;
2 |
3 | import java.io.*;
4 | import java.net.HttpURLConnection;
5 | import java.net.URL;
6 |
7 | public class Test {
8 | /**
9 | * 远程文件下载
10 | * @param url 下载地址
11 | * @param file 保存文件地址
12 | */
13 | public static boolean download(URL url, File file) throws IOException {
14 | boolean flag = true;
15 | DataOutputStream dos = null;
16 | DataInputStream dis = null;
17 | try {
18 | if(!file.getParentFile().exists()) file.getParentFile().mkdirs();
19 | HttpURLConnection conn = (HttpURLConnection) url.openConnection();
20 | dos = new DataOutputStream(new FileOutputStream(file));
21 | dis = new DataInputStream(conn.getInputStream());
22 | byte[] data = new byte[2048];
23 | int i = 0;
24 | while ((i = dis.read(data)) != -1) {
25 | dos.write(data, 0, i);
26 | }
27 | dos.flush();
28 | } catch (IOException e) {
29 | flag = false;
30 | throw e;
31 | } finally {
32 | if(dis != null) dis.close();
33 | if(dos != null) dos.close();
34 | }
35 | return flag;
36 | }
37 |
38 | /**
39 | * 计算分辨率
40 | * @param maxLevel 最大级别
41 | */
42 | public static double[] getResolutions(int maxLevel){
43 | double max = 360.0/256.0;
44 | double[] resolutions = new double[maxLevel+1];
45 | for(int z=0;z<=maxLevel;z++) resolutions[z] = max/Math.pow(2, z);
46 | return resolutions;
47 | }
48 |
49 | public static void main(String[] arg) throws IOException{
50 | double[] re = getResolutions(18);
51 | double[] extent = {106.54,21.59,108.26,23.20};
52 |
53 | for(int z=0;z<18;z++){
54 | int totalX = (int)Math.ceil(360.0/(re[z]*256.0)); //列数向上取整
55 | int totalY = (int)Math.ceil(180.0/(re[z]*256.0)); //行数向上取整 */
56 |
57 | //起始结束列
58 | int sX = (int)Math.floor(((extent[0] + 180) / 360) * totalX);
59 | int eX = (int)Math.floor(((extent[2] + 180) / 360) * totalX);
60 |
61 | //起始结束行
62 | int sY = (int)Math.floor(((90 - extent[3]) / 180) * totalY);
63 | int eY = (int)Math.floor(((90 - extent[1]) / 180) * totalY);
64 |
65 | for(int y=sY;y<=eY;y++){
66 | for(int x=sX;x<=eX;x++){
67 | String urlstr = "http://t0.tianditu.com/DataServer?T=cva_c&x="+x+"&y="+y+"&l="+z; //天地图服务器t0-t8间选一个
68 | System.out.println(urlstr);
69 | String path = "D:/打包/"+z+File.separator+y+File.separator+x+".png";
70 | File file = new File(path);
71 | URL url = new URL(urlstr);
72 | download(url,file);
73 | }
74 | }
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------