GIS瓦片1-google瓦片规则

2024-03-13 04:36
文章标签 规则 google gis 瓦片

本文主要是介绍GIS瓦片1-google瓦片规则,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

谷歌瓦片

地址

  • http://mt0.google.cn/vt?lyrs=y@178&hl=zh-Hans-CN&gl=CN&x=26056&y=12694&z=15
  • http://mt2.google.cn/vt/lyrs=m@167000000&hl=zh-CN&gl=cn&x=420&y=193&z=9
  1. mt0:服务器名 mt = (x + y) % 4
  2. hl语言
  3. x:瓦片X轴的信息编号
  4. y:瓦片Y轴的信息编号
  5. z:瓦片的缩放级别
  6. 谷歌lyrs类型:
    * h =仅限道路
    * m =标准路线图
    * p =地形
    * r =某种改变的路线图
    * s =仅限卫星
    * t =仅限地形
    * y =杂

参考系

标准墨卡托投影(等角圆术地图投影) EPSG:900913
纬度范围:[-85.05113,85.05113]
经度范围:[-180,180]

金字塔

  • 瓦片尺寸 256*256
  • x范围[0,2^level-1], level为级别z
  • y范围[0,2^level-1],level为级别z
  • level层每一块数据的横向经度差为 360/2^level
  • level层每一块数据的纵向纬度差为180/2^level
    xyz 计算左上角经纬度
    (lon,lat)=(360/2^zzxx-180, 180/2^zzyy-90)
    知道经纬度计算 z层xy
    x=(lon+180)*2^z /360
    y=(lat+90)*z^z / 360

代码实现

java

Downloader:

package XXXXXXpackage;import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;public class Downloader {private static int minLevel = 0;private static int maxLevel = 10;private static String dir = "D:\\data\\google_v\\";private static int maxRunningCount = 16;private static int maxRequestLength = 100;public static void download() {ExecutorService pool = Executors.newFixedThreadPool(maxRunningCount);for (int z = minLevel; z <= maxLevel; z++) {int curDt = 0;int requests[][] = null;int maxD = (int) (Math.pow(2, z));for (int x = 0; x < maxD; x++) {for (int y = 0; y < maxD; y++) {if (curDt % maxRequestLength == 0) {String threadName = "dt_" + z + "_" + curDt;DownloadThread dt = new DownloadThread(threadName, dir, requests);pool.execute(dt);curDt = 0;requests = new int[maxRequestLength][3];}requests[curDt][0] = y;requests[curDt][1] = x;requests[curDt][2] = z;curDt++;}}DownloadThread dt = new DownloadThread("", dir, requests);pool.execute(dt);}pool.shutdown();}public static void main(String[] strs) {download();}
}

DownLoadThread

package ??;import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;public class DownloadThread extends Thread {private static int BUFFER_SIZE = 1024 * 8;// 缓冲区大小private static int MAX_TRY_DOWNLOAD_TIME = 128;private static int CURRENT_PROXY = 0;private String threadName = "";private String dir;// private int level;private String tmpDir;private Proxy proxy;private int[][] requests;private String ext = ".png";private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");public DownloadThread(String threadName, String dir, int[][] requests) {this.threadName = threadName;this.dir = dir;this.requests = requests;}@Overridepublic void run() {Date now = new Date();System.out.println(dateFormat.format(now) + "\t" + threadName + ":\t开始运行");long t1 = System.currentTimeMillis();long totalLength = download();long t2 = System.currentTimeMillis();double speed = (double) totalLength / (t2 - t1);now = new Date();if (speed < 0.5) {CURRENT_PROXY++;}System.out.println(dateFormat.format(now) + "\t" + threadName + ":\t完成运行\t" + speed + "kB/s");}public long download() {long totalLength = 0;if (requests == null) {return 0;}//System.out.println(requests.length);for (int i = 0; i < requests.length; i++) {int yy = requests[i][0];int xx = requests[i][1];int zz = requests[i][2];int yyg = (int) (Math.pow(2, zz) - 1 - requests[i][0]);this.tmpDir = dir + "/tmp/" + zz + "/";File tmpDirFile = new File(tmpDir);if (tmpDirFile.exists() == false) {tmpDirFile.mkdirs();}String dirStr = dir + "/download/" + zz + "/" + yy + "/";File fileDir = new File(dirStr);if (fileDir.exists() == false) {fileDir.mkdirs();}String fileStr = dirStr + yy + "_" + xx + ext;File file = new File(fileStr);// double lat1 = (yy) * dDegree - 90;// double lat2 = (yy + 1) * dDegree - 90;String url = "http://mt0.google.com/vt/lyrs=m@174000000&hl=zh-CN&src=app&x=" + xx + "&y=" + yyg + "&z=" + zz+ "&s=";// System.out.println(url);if (file.exists() == false) {String tmpFileStr = tmpDir + yy + "_" + xx + ext;boolean r = saveToFile(url, tmpFileStr);if (r == true) {totalLength += cut(tmpFileStr, fileStr);Date now = new Date();System.out.println(dateFormat.format(now) + "\t" + threadName + ":\t" + zz + "\\" + yy + "_" + xx + ext + "\t"+proxy+"\t完成!");} else {Date now = new Date();System.out.println(dateFormat.format(now) + "\t" + threadName + ":\t" + zz + "\\" + yy + "_" + xx + ext + "\t"+proxy+"\t失败!");}} else {Date now = new Date();System.out.println(dateFormat.format(now) + "\t" + threadName + ":\t" + zz + "\\" + yy + "_" + xx + ext + "已经下载!");}}return totalLength;}public static long cut(String srcFileStr, String descFileStr) {try {// int bytesum = 0;int byteread = 0;File srcFile = new File(srcFileStr);File descFile = new File(descFileStr);if (srcFile.exists()) { // 文件存在时InputStream is = new FileInputStream(srcFileStr); // 读入原文件FileOutputStream os = new FileOutputStream(descFileStr);byte[] buffer = new byte[1024 * 32];// int length;while ((byteread = is.read(buffer)) != -1) {// bytesum += byteread; //字节数 文件大小// System.out.println(bytesum);os.write(buffer, 0, byteread);}is.close();os.close();}srcFile.delete();return descFile.length();} catch (Exception e) {System.out.println("复制单个文件操作出错");e.printStackTrace();}return 0;}public boolean saveToFile(String destUrl, String fileName) {int currentTime = 0;while (currentTime < MAX_TRY_DOWNLOAD_TIME) {try {FileOutputStream fos = null;BufferedInputStream bis = null;HttpURLConnection httpConnection = null;URL url = null;byte[] buf = new byte[BUFFER_SIZE];int size = 0;// 建立链接url = new URL(destUrl);// url.openConnection(arg0)currentTime++;proxy = ProxyConfig.getProxy(CURRENT_PROXY);//if (proxy != null) {//	System.out.println(threadName + ":\t切换代理\t" + proxy.address().toString());//} else {//	System.out.println(threadName + ":\t使用本机IP");//}if (proxy == null) {httpConnection = (HttpURLConnection) url.openConnection();} else {httpConnection = (HttpURLConnection) url.openConnection(proxy);}httpConnection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); httpConnection.setConnectTimeout(60000);httpConnection.setReadTimeout(60000);// 连接指定的资源httpConnection.connect();// 获取网络输入流bis = new BufferedInputStream(httpConnection.getInputStream());// 建立文件fos = new FileOutputStream(fileName);// System.out.println("正在获取链接[" + destUrl + "]的内容;将其保存为文件[" +// fileName + "]");// 保存文件while ((size = bis.read(buf)) != -1){//	System.out.println(size);fos.write(buf, 0, size);}fos.close();bis.close();httpConnection.disconnect();// currentTime = MAX_TRY_DOWNLOAD_TIME;break;} catch (Exception e) {//e.printStackTrace();CURRENT_PROXY++;}}if (currentTime < MAX_TRY_DOWNLOAD_TIME) {return true;} else {return false;}}}

ProxyConfig

package org.gfg.downloader.google.vctor;import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;public class ProxyConfig {private static List<Proxy> proxies;private static int getTime = 0;@SuppressWarnings("unchecked")public static void inital() {// if (proxies == null) {proxies = null;proxies = new ArrayList<Proxy>();// } else {// proxies.clear();// }try {URL url = new URL("http://www.18daili.com/");URLConnection urlConnection = url.openConnection();urlConnection.setConnectTimeout(30000);urlConnection.setReadTimeout(30000);SAXReader reader = new SAXReader();// System.out.println(url);reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);Document doc = reader.read(urlConnection.getInputStream());if (doc != null) {Element root = doc.getRootElement();Element proxyListTable = getElementById(root, "proxyListTable");// System.out.println(proxyListTable.asXML());Iterator<Element> trs = proxyListTable.elementIterator();trs.next();while (trs.hasNext()) {Element tr = trs.next();Iterator<Element> tds = tr.elementIterator();String ip = tds.next().getText();String port = tds.next().getText();// System.out.println(ip+":"+port);Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(ip, Integer.valueOf(port)));proxies.add(proxy);System.out.println("添加代理\t" + proxy);}}} catch (Exception e) {// e.printStackTrace();}}private static Element getElementById(Element element, String id) {Element needElement = null;Iterator<Element> subElements = element.elementIterator();while (subElements.hasNext()) {Element subElement = subElements.next();String getId = subElement.attributeValue("id");if (getId != null && getId.equals(id)) {needElement = subElement;break;} else {needElement = getElementById(subElement, id);if (needElement != null) {break;}}}return needElement;}synchronized public static Proxy getProxy(int i) {getTime++;if (getTime % 1024 == 0 || proxies == null) {inital();getTime = 0;System.out.println("重新生成代理列表!");System.out.println("当前共有" + proxies.size() + "个代理!");}if (i % 8 == 0) {return null;}int index = i % proxies.size();index = Math.abs(index);return proxies.get(index);}public static void main(String... str) {inital();}}

这篇关于GIS瓦片1-google瓦片规则的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/803655

相关文章

GIS图形库更新2024.8.4-9.9

更多精彩内容请访问 dt.sim3d.cn ,关注公众号【sky的数孪技术】,技术交流、源码下载请添加微信:digital_twin123 Cesium 本期发布了1.121 版本。重大新闻,Cesium被Bentley收购。 ✨ 功能和改进 默认启用 MSAA,采样 4 次。若要关闭 MSAA,则可以设置scene.msaaSamples = 1。但是通过比较,发现并没有多大改善。

消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法

消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法   消除安卓SDK更新时的“https://dl-ssl.google.com refused”异常的方法 [转载]原地址:http://blog.csdn.net/x605940745/article/details/17911115 消除SDK更新时的“

Adblock Plus官方规则Easylist China说明与反馈贴(2015.12.15)

-------------------------------特别说明--------------------------------------- 视频广告问题:因Adblock Plus的局限,存在以下现象,优酷、搜狐、17173黑屏并倒数;乐视、爱奇艺播放广告。因为这些视频网站的Flash播放器被植入了检测代码,而Adblock Plus无法修改播放器。 如需同时使用ads

全英文地图/天地图和谷歌瓦片地图杂交/设备分布和轨迹回放/无需翻墙离线使用

一、前言说明 随着风云局势的剧烈变化,对我们搞软件开发的人员来说,影响也是越发明显,比如之前对美对欧的软件居多,现在慢慢的变成了对大鹅和中东以及非洲的居多,这两年明显问有没有俄语或者阿拉伯语的输入法的增多,这要是放在2019年以前,一年也遇不到一个人问这种需求场景的。 地图应用这块也是,之前的应用主要在国内,现在慢慢的多了一些外国的应用场景,这就遇到一个大问题,我们平时主要开发用的都是国内的地

com.google.gson.JsonSyntaxException:java.lang.IllegalStateException异常

用Gson解析json数据的时候,遇到一个异常,如下图: 这个异常很简单,就是你的封装json数据的javabean没有写对,你仔细查看一下javabean就可以了 比如:我的解析的代码是             Gson gson = new Gson();             ForgetJson rb = gson.fromJson(agResult.mstrJson, For

Google Earth Engine——高程数据入门和山体阴影和坡度的使用

目录 山体阴影和坡度 对图像应用计算 应用空间减速器 高程数据 通过从“重置”按钮下拉菜单中选择“清除脚本”来清除脚本。搜索“elevation”并单击 SRTM Digital Elevation Data 30m 结果以显示数据集描述。单击导入,将变量移动到脚本顶部的导入部分。将默认变量名称“image”重命名为“srtm”。使用脚本将图像对象添加到地图: Map

关联规则(一)Apriori算法

此篇文章转自 http://blog.sina.com.cn/s/blog_6a17628d0100v83b.html 个人觉得比课本上讲的更通俗易懂! 1.  挖掘关联规则 1.1   什么是关联规则 一言蔽之,关联规则是形如X→Y的蕴涵式,表示通过X可以推导“得到”Y,其中X和Y分别称为关联规则的先导(antecedent或left-hand-side, LHS)和后

电子电气架构---私有总线通信和诊断规则

电子电气架构—私有总线通信和诊断规则 我是穿拖鞋的汉子,魔都中坚持长期主义的汽车电子工程师。 老规矩,分享一段喜欢的文字,避免自己成为高知识低文化的工程师: 屏蔽力是信息过载时代一个人的特殊竞争力,任何消耗你的人和事,多看一眼都是你的不对。非必要不费力证明自己,无利益不试图说服别人,是精神上的节能减排。 无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事.而不是让内心的烦躁、

The import com.google cannot be resolved

The import com.google cannot be resolved,报错: 第一感觉就是缺少jar包,因为项目用maven管理,所以在pom.xml中添加: <dependency>  <groupId>com.google.code.gson</groupId>  <artifactId>gson</artifactId>  <version>2.3.1</ver

C++常见异常汇总(三): fatal error: google/protobuf/port_def.inc

文章目录 1、fatal error : sw/redis++/redis.h2、fatal error: dwarf.h: No such file or directory3、fatal error: elfutils/libdw.h: No such file or directory4、fatal error: libunwind.h: No such file or directo