概述:本文讲述如何通过高德的搜索接口获取北京市的充电桩的数据,并实现WEBGIS的展示。
效果:获取网络数据并保存
获取的数据
转换为Geojson
地图展示
查看充电桩信息
实现:1、获取数据并保存通过接口“http://ditu.amap.com/service/poiInfo?query_type=TQUERY&pagesize=20&pagenum=1&zoom=8&city=110000&keywords=充电桩”获取数据。
package com.lzugis.url;
import com.amazonaws.util.json.JSONArray;
import com.amazonaws.util.json.JSONObject;
import com.lzugis.CommonMethod;
public class GetChargingPile {
public static void main(String[] args) {
// TODO Auto-generated method stub
CommonMethod cm = new CommonMethod();
String file = "d://chargingpile.txt";
int pageSize = 20, total = 894;
int pageNum = total%50==0?(int)total/pageSize:(int)total/pageSize+1;
try{
cm.append2File(file, "districtname,districtcode,latitude,longitude,name,address,picinfo");
System.out.println("totalnum="+pageNum);
for(int i=0;i
2、格式转换为geojson# -*- coding: utf-8 -*-
import sys
from osgeo import gdal
from osgeo import ogr
#读取shap文件
def shp2json():
#为了支持中文路径,请添加下面这句代码
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8","NO")
#为了使属性表字段支持中文,请添加下面这句
gdal.SetConfigOption("SHAPE_ENCODING","")
#注册所有的驱动
ogr.RegisterAll()
#数据格式的驱动
driver = ogr.GetDriverByName('ESRI Shapefile')
ds = driver.Open(r'D:\data\gdal\chargingpile.shp');
if ds is None:
print "打开文件失败!"
sys.exit(1)
dv = ogr.GetDriverByName("GeoJSON")
if dv is None:
print "打开驱动失败!"
sys.exit(1)
dv.CopyDataSource(ds, r"D:\data\gdal\chargingpile.geojson")
ds.Destroy()
print "转换成功!"
def main():
shp2json();
if __name__ == "__main__":
main();
3、页面展示 $.get("../data/chargingpile.geojson",null,function(result){
result = eval("("+result+")");
var features = (new ol.format.GeoJSON()).readFeatures(result);
for(var i=0;i").append("所属区域:"+feature.get("districtna")+"
")
.append("区域编码:"+feature.get("districtco")+"
")
.append("位置:("+feature.get("longitude")+", "+feature.get("latitude")+")
")
.append("地址:"+feature.get("address")))
.append($("").attr("src",feature.get("picinfo")));
container.style.display = 'block';
title.innerHTML = feature.get("name");
title.style.display = 'block';
map.getView().setCenter(coordinate);
});
});
}
---------------------------------------------------------------------------------------------------------------技术博客CSDN:http://blog.csdn.NET/gisshixisheng博客园:http://www.cnblogs.com/lzugis/
在线教程http://edu.csdn.Net/course/detail/799Githubhttps://github.com/lzugis/联系方式q q:1004740957e-mail:niujp08@qq.com公众号:lzugis15Q Q 群:452117357(webgis) 337469080(Android)