2026年11月份实时最新获取地图边界数据方法,省市区县街道村居委会多级联动【文末附实时geoJson数据下载】

本文介绍通过高德开放平台API实时获取省市区县等多级行政区划边界数据(GeoJSON),结合AMapUI的DistrictExplorer模块解析地理特征,并使用ECharts注册地图、渲染可视化图表及实现点击下钻功能。重点涵盖API调用、GeoJSON结构标准化、echarts.registerMap配置及事件驱动的层级切换逻辑,解决静态地图数据陈旧问题。

​
动态生成最新行政区划 GeoJSON 数据并结合 ECharts 实现地图下钻功能
在开发基于地图的数据可视化应用时,一个常见的挑战是获取准确且最新的行政区划边界数据(GeoJSON)。许多现有的在线资源可能数据陈旧,无法反映最新的行政区划调整。本文将介绍一种解决方案,通过调用高德开放平台的 API 动态获取最新的行政区划边界,并结合 ECharts 实现可下钻的地图可视化。

第一部分:通过高德开放平台 API 获取行政区划边界数据
高德地图提供了强大的“行政区查询服务”(AMap.DistrictSearch),可以实时获取全国范围内的行政区划信息,包括其地理边界。

  1. 准备工作:引入 API 与申请 Key

首先,您需要到高德开放平台申请一个 Key,用于 API 调用。然后,在页面中引入高德地图的 JS API 脚本。

  1. 调用接口获取行政区列表

通过实例化 AMap.DistrictSearch 并调用其 search 方法,可以获取指定区域的下一级行政区列表。以获取中国所有省级单位为例:

// 初始化行政区查询实例
const opts = {
subdistrict: 1, // 返回下一级行政区
showbiz: false // 最后一级不返回街道信息
};
const district = new AMap.DistrictSearch(opts);

// 查询“中国”的下一级行政区
district.search(‘中国’, (status, result) => {
if (status === ‘complete’) {
// result.districtList[0] 包含了省级列表数据
processData(result.districtList[0], 100000);
}
});
3. 获取 GeoJSON 格式的边界数据

获取到行政区列表后,需要利用 AMapUI 的 DistrictExplorer 模块来加载指定区域的边界数据(feature)。

function loadMapData(areaCode, callback) {
AMapUI.loadUI([‘geo/DistrictExplorer’], DistrictExplorer => {
const districtExplorer = new DistrictExplorer();

    districtExplorer.loadAreaNode(areaCode, (error, areaNode) => {
        if (error) {
            console.error(error);
            return;
        }
        
        // 构建标准的 GeoJSON 对象
        const geoJson = {
            type: "FeatureCollection",
            features: areaNode.getSubFeatures() // 获取子区域的边界数据
        };
        
        callback(geoJson);
    });
});

}
关键点:areaNode.getSubFeatures() 返回的是一个 feature 数组,为了符合标准的 GeoJSON 格式,需要将其包裹在一个 { “type”: “FeatureCollection”, “features”: […] } 结构中。

第二部分:使用 ECharts 渲染地图
获取到标准的 GeoJSON 数据后,便可以利用 ECharts 将其渲染为地图。

  1. 引入 ECharts 库

在项目中引入 ECharts 库,例如使用 CDN:

  1. 注册并配置地图

在 ECharts 中,使用 echarts.registerMap 方法注册刚才获取的 GeoJSON 数据,然后在 option 中配置 series-map。

// 假设 geoJsonData 是上一步获取到的数据
// 假设 myChart 是已经初始化的 ECharts 实例

// 注册地图
echarts.registerMap(‘currentMap’, geoJsonData);

// 配置 ECharts Option
const option = {
series: [{
type: ‘map’,
map: ‘currentMap’, // 使用刚刚注册的地图
roam: false,
itemStyle: {
// …样式配置
},
data: [ /* 业务数据 */ ]
}]
};

myChart.setOption(option);
执行此步骤后,即可成功渲染出对应的行政区划地图。

第三部分:实现地图下钻功能
地图下钻功能的核心是监听 ECharts 的点击事件,获取被点击区域的 adcode,然后重复第一步和第二步的过程,获取并渲染更深层级的地图。

  1. 监听 ECharts 点击事件

myChart.on(‘click’, (params) => {
// params.data 中应包含下一级区域的 adcode
const cityCode = params.data.cityCode;
const level = params.data.level;

if (level === 'street') return; // 如果是街道级别,则不再下钻

// 使用 cityCode 再次调用高德API获取下一级数据
district.search(String(cityCode), (status, result) => {
    if (status === 'complete' && result.districtList.length > 0) {
        // 获取新的 geoJson 并重新渲染 ECharts
        loadMapData(cityCode, (geoJson) => {
            // ...重新执行注册和渲染的逻辑...
        });
    }
});

});
注:上述代码示例为核心逻辑展示,具体实现时可结合 Vue、React 等框架进行封装。

总结与资源
通过上述方法,可以构建一个数据实时、支持无限层级下钻的动态地图应用,有效解决了静态 GeoJSON 数据陈旧的问题。

对于希望直接查看完整实现或获取预生成数据的开发者,可以参考以下资源:

完整示例项目:https://github.com/TangSY/echarts-map-demo
在线体验与数据下载:https://geojson.hxkj.vip 该网站提供了基于此方法生成的最新省级、市级、区县级 GeoJSON 文件以及多级别行政编码数据的下载服务。
​

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值