SQL Server 2008 提供了空间数据的操作方法,但是我们在处理大批量数据的时候发现,数据库提供的空间数据查询的速度太慢了,没有办法解决这个问题,因此,引申出通过第三方类库来直接操作缓存数据的方式去解决空间数据查询速度缓慢的方法。
解决步骤:
1.系统启动时加载空间数据到服务器缓存中。
2.通过第三方类库查询数据并返回。
3.涉及到插入数据等,会更新缓存。
官网地址
- https://developers.arcgis.com/java/10-2/
- 版本号 10.2.4
API文档
- https://developers.arcgis.com/java/10-2/api-reference/
开发环境
- JDK:1.8
- Tomcat:7.0
- 因为在JDK和Tomat版本上曾经有过奇怪的错误,所以现在锁定在这两个版本之上,具体的错误信息就不贴了,有时间的朋友可以自己测试一下。
Jar包列表
- 安装ArcGIS_Runtime_SDK_Java_1024.exe,在SDK路径下可找到全部Jar包,这里我采用本地化的方式加载进去,重命名了一下。
<!-- ArcGis -->
<dependency>
<groupId>com.esri</groupId>
<artifactId>ArcGIS_Runtime_Java</artifactId>
<version>10.2.4</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/ArcGIS_Runtime_Java-10.2.4.jar</systemPath>
</dependency>
<dependency>
<groupId>com.esri</groupId>
<artifactId>ArcGIS_Runtime_Java_Toolkit</artifactId>
<version>10.2.4</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/ArcGIS_Runtime_Java_Toolkit-10.2.4.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>httpclient</artifactId>
<version>2009.12</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/httpclient-2009.12.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>httpcore</artifactId>
<version>2009.06</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/httpcore-2009.06.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>httpmime</artifactId>
<version>2009.12</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/httpmime-2009.12.jar</systemPath>
</dependency>
<dependency>
<groupId>org.codehaus</groupId>
<artifactId>jackson-core-lgpl</artifactId>
<version>2012.02</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/jackson-core-lgpl-2012.02.jar</systemPath>
</dependency>
<dependency>
<groupId>org.codehaus</groupId>
<artifactId>jackson-mapper-lgpl</artifactId>
<version>2012.02</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/jackson-mapper-lgpl-2012.02.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>apache-mime4j</artifactId>
<version>2009.03</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/apache-mime4j-2009.03.jar</systemPath>
</dependency>
<dependency>
<groupId>jcifs</groupId>
<artifactId>jcifs</artifactId>
<version>2012.03</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/jcifs-2012.03.jar</systemPath>
</dependency>
<dependency>
<groupId>jcommon</groupId>
<artifactId>jcommon</artifactId>
<version>2011.10</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/jcommon-2011.10.jar</systemPath>
</dependency>
<dependency>
<groupId>jfreechart</groupId>
<artifactId>jfreechart</artifactId>
<version>2011.11</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/jfreechart-2011.11.jar</systemPath>
</dependency>
<dependency>
<groupId>json</groupId>
<artifactId>json</artifactId>
<version>2009.02</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/json-2009.02.jar</systemPath>
</dependency>
差异说明
第三方类库所提供的方法也是非常多,但是有些比较实用的方法并没有提供,这个很无奈,只能自己想办法对数据进行处理;但是相比直接采用数据库查询而言,查询的速度绝对是一流的,所以,看实际需求来确定开发方式就好了。
示例说明
数据格式互转很重要,可以很轻松的应用到服务器端和客户端。
转载链接
- http://blog.youkuaiyun.com/gary__123456/article/details/71270125
Geometry转换成Json数据
Point point = new Point(113, 23);
String json = GeometryEngine.geometryToJson(SpatialReference.create(SpatialReference.WKID_WGS84), point);
Log.w("TAG", "json===" + json);
Json转换为Geometry数据
try {
String jsonStr = "{\"x\":113.0,\"y\":23.0,\"spatialReference\":{\"wkid\":4326}}";
JsonFactory jsonFactory = new JsonFactory();
JsonParser jsonParser = jsonFactory.createJsonParser(jsonStr);
MapGeometry mapGeometry = GeometryEngine.jsonToGeometry(jsonParser);
Point mPoint = (Point) mapGeometry.getGeometry();
Log.i("TAG","mPoint---"+mPoint.getX()+"==="+mPoint.getY());
} catch (IOException e) {
e.printStackTrace();
}
示例1-通过移动设备显示屏幕范围内的数据
要点:获取移动设备屏幕上四个角的坐标值最小最大xy值来执行查询操作,通过最小最大xy值可以构建一个面,通过判断数据是否包含在整个面内来确定
public void setPolygon(String xmin,String ymin,String xmax,String ymax) {
Polygon polygon = new Polygon();
polygon.startPath(Double.parseDouble(xmin),Double.parseDouble(ymin));
polygon.lineTo(Double.parseDouble(xmax),Double.parseDouble(ymin));
polygon.lineTo(Double.parseDouble(xmax),Double.parseDouble(ymax));
polygon.lineTo(Double.parseDouble(xmin),Double.parseDouble(ymax));
polygon.lineTo(Double.parseDouble(xmin),Double.parseDouble(ymin));
}
判断方法:intersects判断是否包含
boolean flag = GeometryEngine.intersects(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference);
示例2-点击移动设备屏幕,查询所点击的位置数据
要点:获取所点击位置的坐标点,通过判断数据库点的数据位置距离所点击的位置最近的则可以确定
public void setPoint(String x,String y) {
Point point = new Point();
point.setX(Double.parseDouble(x));
point.setY(Double.parseDouble(y));
}
判断方法:distance获取两者之间的距离
double distance = GeometryEngine.distance(Geometry geometry1, Geometry geometry2, SpatialReference spatialReference);