之前通过MSSQL2008数据库查询操作来查找判断,一个坐标位于哪个区域内,虽然是完成了开发基本要求,但是查询速度太慢了,现在通过数据加载初始化为服务器缓存的方式,再利用ArcGIS第三方类来操作,完成查询任务。速度从4s变为1s~
ArcGIS Runtime SDK for Java 网址
https://developers.arcgis.com/java/10-2/
版本号
10.2.4
注意事项:该版本需要安装里面的程序后,才能使用相关的Jar包,最新版100.1.0,尚未测试,该版本可以不安装程序也可以使用。
需求分析
MSSQL2008数据库中存储着Shp矢量数据,矢量数据为POLYGON面数据,每一条数据代表一个面(区域),通过输入坐标判断该点落于哪个面数据上,提取并返回该区域的名称。
API
https://developers.arcgis.com/java/10-2/api-reference/
Jar
ArcGIS_Runtime_Java
ArcGIS_Runtime_Java
httpclient
httpcore
httpmime
jackson-core-lgpl
jackson-mapper-lgpl
apache-mime4j
jcifs
jcommon
jfreechart
json
代码
package com.thinkgem.jeesite.modules.cms.web.front;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.MultiPath;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.SpatialReference;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.cms.entity.County;
import com.thinkgem.jeesite.modules.cms.service.CountyService;
import com.thinkgem.jeesite.modules.cms.utils.GCJ02toBD09;
import com.thinkgem.jeesite.modules.cms.utils.GCJ02toWGS84;
/**
* @author Administrator
*
*/
@Controller
@RequestMapping(value = "${frontPath}")
public class FrontContyController extends BaseController{
@Autowired
private CountyService countyService;
List countyList = new ArrayList();
List polygonList = new ArrayList();
@RequestMapping(value = "countyData")
public String countyData(String x, String y, HttpServletRequest request, HttpServletResponse response, Model model){
Point mapPoint = null;
Polygon polygon = null;
boolean flag;
String str="该坐标不在范围内";
//ArcGISRuntime.setInstallDirectory("C:\\Program Files (x86)\\ArcGIS SDKs\\java10.2.4");
if(countyList.size() == 0){
createDataList();
}
double[] temp = new double[2];
double[] temp1 = new double[2];
try { //坐标系转换
temp = GCJ02toBD09.bd_decrypt(Double.valueOf(y), Double.valueOf(x),0.0, 0.0);
temp1 = GCJ02toWGS84.gcj_To_Gps84(temp[1], temp[0]);
} catch (NumberFormatException e) {
str = "数据类型应为双精度->0.0";
}
Point poi = new Point(temp1[0],temp1[1]);
for(int i=0;i
{
mapPoint = (Point) GeometryEngine.project(poi, SpatialReference.create(4326), null);
polygon = (Polygon) GeometryEngine.project(polygonList.get(i), SpatialReference.create(4326), null);
flag = GeometryEngine.intersects(polygon, mapPoint, SpatialReference.create(4326));
if(flag) {
str = countyList.get(i).getName();
break;
}
}
model.addAttribute("message", str);
return "redirect:" + Global.getFrontPath();
}
/**
* 从数据库获取并封装数据
*/
public void createDataList() {
countyList = countyService.findList(null);
for(int i=0;i
MultiPath polygon = new Polygon();
String yy = countyList.get(i).getShape().substring(10, countyList.get(i).getShape().length()-2);
String ss[] = yy.split(",");
for(int j=0;j
String xx[] = ss[j].split("\\s+");
if(j == 0) {
polygon.startPath(Double.parseDouble(xx[0]),Double.parseDouble(xx[1]));
}
else {
polygon.lineTo(Double.parseDouble(xx[1]),Double.parseDouble(xx[2]));
}
}
polygonList.add((Polygon) polygon);
}
}
}
注意事项
ArcGISRuntime.setInstallDirectory()
如报错显示找不到路径,可能由于你安装程序后配置没有生效,重启后可解决,如还是不行,添加这行代码进行指向。