The AreaCity open source library organizes the four-level administrative division data of provinces, cities, districts, counties, townships and streets, and is equipped with online tools to convert it into three-level and four-level linkage JavaScript codes, which can be imported into the database using the built-in conversion tool software; the data comes from: The Bureau of Statistics, the Ministry of Civil Affairs, the administrative division of Tencent Map, and the administrative division of AutoNavi are integrated from these four platforms.
Data online preview: https://xiangyuecn.gitee.io/areacity-jsspider-statsgov/
GitHub address: https://github.com/xiangyuecn/AreaCity-JsSpider-StatsGov
As of the date of publication (2022-02-12), the open source library released the latest version of the newly compiled data on February 06, 2022; the administrative division data is updated frequently, only districts and counties have many changes every year, the Bureau of Statistics, the Ministry of Civil Affairs New data is released every year, but it needs to be processed by itself; therefore, the provincial and urban data need to be synchronized and maintained frequently. Fortunately, this open source library has continuous long-term maintenance, and it is relatively easy to update after new data is released.
Because the open source library update and maintenance data is relatively timely, as long as the open source library is not closed, the extraction method introduced in this article is always applicable, not only for this year; is much better than the data uploaded to the download platform that will not be updated for ten thousand years. .
In addition to the four-level administrative division data, the open source library can also preview and download the three-level coordinate vector boundaries of provinces and cities online, and the geo-fence data of townships and streets, and provides conversion tool software that can easily import the database, convert it into shp, geojson, sql format, coordinate system conversion; I will post a tutorial on the use of coordinate boundaries later. This article only introduces the extraction and use of the four-level administrative division data.
The latest version of general json format file extraction
At the bottom of the data online preview page, an online conversion tool is provided. When you open it, you will find the latest version of the data in the current library (the open source library updates and maintains data in a timely manner), which can convert the four-level data of provinces, municipalities, and towns into json format. The file and control options are also rich. If you want to export the first-level, second-level, third-level, and fourth-level data, you can:
After conversion, you can download it directly to the json file:
The file contains n: city name, i: city ID, p: superior ID, y: pinyin prefix, all of which are single letters as keys, the purpose is to reduce the file size, if you want keys such as name and id, you can click " Online editing UserFormat source code" implements exporting the complete data format by default.
JSON files are very convenient for cross-platform use, not only in web pages, but also in mobile apps, desktop programs, and back-end code.
The latest version of multi-level linkage js version data code extraction
Under the data online preview page, an online conversion tool is provided. When you open it, you will see the latest version of the data in the current library (the open source library updates and maintains data in a timely manner), which can convert the four-level data of provinces, cities and towns into multi-level data. Linkage js, the control options are also rich, and it can be converted into two-level, three-level, and four-level linkage, and you can also directly experience the four-level linkage drop-down selection on the page:
After conversion, you can download it directly to the js file:
In fact, the data in json format has been embedded in the js code, and the multi-level linkage js code has been encapsulated. We only need to follow the instructions in the code and call the method to quickly realize multi-level linkage in the html page. There are event callbacks.
The latest version of data import database
Download it before importing:
- [Conversion tool software] In the data online preview page, click conversion tool software link to download the conversion tool provided by the open source library. Using this tool, the four-level administrative division data of provinces, cities and towns can be imported into MySQL, SQL Server database, or converted to sql file (imported into other compatible databases);
- [ok_data_level4.csv data file] On the data online preview page, click the displayed data download link to download the
ok_data_level4.csv
data file.
Note: The files must be downloaded from the open source library. The open source library updates and maintains data in a timely manner. Do not download from other download platforms. Otherwise, those uploaded to the download platform that have not been updated for ten thousand years are very likely to be downloaded to the old version.
The conversion tool software only supports Windows computers, and a virtual machine can be used on Mac to use the software.
When ready, open the conversion tool and start importing data into the database (MySQL imported here is the same as importing SQL Server):
- Click the "Advanced >>" button in the tool to open the custom script interface;
- In the script interface, click Select File at the top and select the downloaded
ok_data_level4.csv
data file; - In the built-in script drop-down box, select the "Import database for provinces, municipalities and towns" option, and then click the Apply button;
- In the database settings on the left interface, select the type as MySQL, and fill in the database connection port + database name + account password;
- Click the "Import Database" button in the custom script interface, wait for a while, and more than 40,000 pieces of data will be imported into the database in less than 3 minutes.
The import was successful, and it took 2 minutes and 22 seconds for more than 40,000 pieces of data:
MySQL client to view data:
above operations are also applicable to SQL Server, the same steps as . In addition, the built-in script also supports the "province, city, town, and town to SQL" function, which can directly export SQL files, which can be imported into other compatible databases.
Some points to note about the data
The open source library will try to be consistent with the update frequency of the Ministry of Civil Affairs, but because the two most important data sources, National Bureau of Statistics and
Tencent map, the update frequency of administrative divisions is not as high as that of the Ministry of Civil Affairs; therefore, the three-level accuracy and The accuracy of the Ministry of Civil Affairs is one order of magnitude, and it is more complete; the fourth-level town level is mainly provided by the administrative division of the
Tencent map, and the Tencent data source is not frequently updated, so it will lead to a small number of new and adjusted cities. Fourth There is no data in the level (it will be filled with the data of the superior level), this defect should be considered before use.
The data is supplemented by the superior data (for details, please refer to the data rules at the back of the library document), so that any data can satisfy the 4-level structure of provinces, municipalities and towns, and there is no isolation (ID is globally unique), so no matter where it comes from The lower-level selection can be carried out effectively. This kind of filled-in data can be identified by the ID structure. As long as the ID is the ID of the superior + multiple 0s, it means that the data is filled-in data, such as: Dongguan (4419)-Dongguan (441900), it is easy to identify 441900 is the padding data for padding.
There are very few data about supplementary behavior, about 50, mainly: Zhitongzi City (Dongguan, Danzhou, etc.), county-level cities directly under the provincial government (Jiyuan, Qianjiang, etc.), their next level only has supplementary. Qi this data. In addition, there is only one piece of data for the subordinates of the municipalities directly under the Central Government (Beijing, Tianjin, etc.), and the ID ends with 01 (excluding Chongqing, which is divided into two cities and counties).
For reasons such as straight bobbins, etc., why not directly raise the lower level to the district level, and use the method of filling and filling to align the data, please refer to issue#9 .
The data does not include most of the administrative , such as Xiong'an New District, Tianfu New District, Suzhou Industrial Park, etc.
Coordinates and vector boundary data of provinces, cities, counties and towns
In the data online preview page, you can also download the three-level coordinate boundary data of the province and city, and the coordinate boundary data of the township level. Through the conversion tool software, you can easily import the database, convert it into shp, geojson, sql format, and convert the coordinate system.
I will post a tutorial on the use of coordinate boundaries later, so stay tuned~
ECharts Map Level 4 Drilldown Online Test and Preview + Code Generation: https://xiangyuecn.gitee.io/areacity-jsspider-statsgov/assets/geo-echarts.html
【END】
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。