热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

多源在线与离线数据读取之四(Android移动端开发读取四川地理信息中心切片底图)

本系列专题本来上次想一次性写完,无奈工作太忙,上月就中断了一个月,这个月补上两篇,在此对各位表示抱歉。本实例主要是针对四川地理信息中心的切片,如果利用ArcGISforAndroidAPI进行解

本系列专题本来上次想一次性写完,无奈工作太忙,上月就中断了一个月,这个月补上两篇,在此对各位表示抱歉。


本实例主要是针对四川地理信息中心的切片,如果利用ArcGIS for Android API进行解析,并读入作用底图。

1)基础准备:下载Java版的Json解析库(http://code.google.com/p/json-simple/)、熟悉四川地理信息中心切片规则

2)关于四川地理信息中心的切片规则这就不做介绍了,在以前专题已介绍过,详见:http://www.scgis.net/

3)代码说明

AgsLOD.java:切片等级信息定义文件,在这定义了比例尽、等级、分辨率

package com.esri.arcgis.android.samples;

import com.esri.core.internal.d.c;

public class AgsLOD extends c {
private static final long serialVersiOnUID= 4341699179151728883L;

private int level;
private double resolution;
private double scale;

public AgsLOD(int level, double scale, double resolution) {
super();

this.level = level;
this.scale = scale;
this.resolution = resolution;
}

public int a() {
return this.level;
}

public double b() {
return this.resolution;
}

public double c() {
return this.scale;
}
}

GetToken .java :通过 Web 请求提交用户名跟密码,获取 Token 字符口串,并对字符串进行解析,用于获取地图切片。

package com.esri.arcgis.android.samples;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class GetToken {
//get token
public String sendPost(String url) {
StringBuilder result = new StringBuilder();
try {
URL httpurl = new URL(url);
HttpURLConnection httpCOnn= (HttpURLConnection) httpurl
.openConnection();
httpConn.setDoInput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(
httpConn.getInputStream(),"UTF-8"));
String line;
while ((line = in.readLine()) != null) {
result .append(line);
}
//System.out.println(result);
in.close();
//get token
return result.toString().split("\"")[15];
} catch (Exception e) {
e.printStackTrace();
}
return null;
}}


SCGISModel.java:切片参数定义文件,包括切片的空间参考等基础信息

package com.esri.arcgis.android.samples;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.d.k;

import com.esri.core.map.TiledLayerModel;

public class SCGISModel extends TiledLayerModel {
private static final long serialVersiOnUID= 7726567118839553087L;

private String location;
private String token;
public SCGISModel(String location, SpatialReference sr, Envelope full,
k tileInfo) {
super(sr, full, tileInfo);
this.location = location;
this.token=new GetToken().sendPost("http://www.scgis.net.cn/imap/iMapServer/Token/getToken?username=test20110703&password=test20110703&IpAddress=&TimeSpan=100M&st=1302073818076");
}

@Override
public byte[] getTile(int level, int row, int col) throws Exception {
byte[] result = null;
try {
int levelCustom = level + 1;
String bundlesDir = location
+ levelCustom
+ File.separator
+ row
+ File.separator
+ col
+ "?token="+this.token;
;

ByteArrayOutputStream bos = new ByteArrayOutputStream();

URL sjwurl = new URL(bundlesDir);
HttpURLConnection httpUrl = null;
BufferedInputStream bis = null;
byte[] buf = new byte[1024];

httpUrl = (HttpURLConnection) sjwurl.openConnection();
httpUrl.connect();
bis = new BufferedInputStream(httpUrl.getInputStream());

while (true) {
int bytes_read = bis.read(buf);
if (bytes_read > 0) {
bos.write(buf, 0, bytes_read);
} else {
break;
}
}
;
bis.close();
httpUrl.disconnect();

result = bos.toByteArray();

} catch (Exception ex) {
ex.printStackTrace();
}

return result;
}

}

SCGISMapServices.java:继承tiledLayer,自定义切片类。

package com.esri.arcgis.android.samples;
import java.util.ArrayList;
import android.content.Context;
import android.util.AttributeSet;

import com.esri.android.map.TiledLayer;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.d.c;
import com.esri.core.internal.d.k;
import com.esri.core.map.TiledLayerModel;

public class SCGISMapServices extends TiledLayer {
private String location = "http://www.scgis.net.cn/iMap/iMapServer/NewRest/services/SCTileMap/tile/";

private SpatialReference spatialReference = SpatialReference.create(4326);
private Envelope fullExtent = new Envelope(95.918, 24.898, 110.14, 35.209);
private k tileInfo;

public SCGISMapServices(Context context, AttributeSet attrs) {
super(context, attrs);
try {
init();
} catch (Exception ex) {
ex.printStackTrace();
}
}

@Override
protected TiledLayerModel initModel() throws Exception {
return new SCGISModel(location, spatialReference, fullExtent, tileInfo);
}

private void init() {
try {
tileInfo = new k();
tileInfo.f = new Point(-180, 90);


tileInfo.a = 256;
tileInfo.b = 256;
tileInfo.h = new ArrayList();

double resolution = 0.010998662747496;
double scale=4622333.68;
for (int j = 0, jcount = 11; j int level = j;
tileInfo.h.add(new AgsLOD(level, scale, resolution));
resolution/=2;
scale/=2;
}
} catch (Exception e) {
e.printStackTrace();
}
}

}
4)效果图如下:



如果需代码学习的同学,在本系列专题之五后面留下邮箱,可将此系列专题的所有代码提供出来供大学学习!






推荐阅读
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 图像因存在错误而无法显示 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • springmvc学习笔记(十):控制器业务方法中通过注解实现封装Javabean接收表单提交的数据
    本文介绍了在springmvc学习笔记系列的第十篇中,控制器的业务方法中如何通过注解实现封装Javabean来接收表单提交的数据。同时还讨论了当有多个注册表单且字段完全相同时,如何将其交给同一个控制器处理。 ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • 怎么在PHP项目中实现一个HTTP断点续传功能发布时间:2021-01-1916:26:06来源:亿速云阅读:96作者:Le ... [详细]
  • Java中包装类的设计原因以及操作方法
    本文主要介绍了Java中设计包装类的原因以及操作方法。在Java中,除了对象类型,还有八大基本类型,为了将基本类型转换成对象,Java引入了包装类。文章通过介绍包装类的定义和实现,解答了为什么需要包装类的问题,并提供了简单易用的操作方法。通过本文的学习,读者可以更好地理解和应用Java中的包装类。 ... [详细]
  • PDO MySQL
    PDOMySQL如果文章有成千上万篇,该怎样保存?数据保存有多种方式,比如单机文件、单机数据库(SQLite)、网络数据库(MySQL、MariaDB)等等。根据项目来选择,做We ... [详细]
author-avatar
浪子烦恼猪_309
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有