当前位置:网站首页>1: Mosaic of 100W basic geographic information data

1: Mosaic of 100W basic geographic information data

2022-06-24 18:41:00 Geographical space of ruiduobao

background

It was officially released yesterday 1:100 Public version of basic geographic information data set , But this data is divided , We still need to do some merging .

Processing flow

Mainly used python Preprocess and merge data .

gdb turn shp vector

Use QGIS Of OSGeo4W Shell Software , Can be gdb The database is exported to shp vector .

ogr2ogr -f “ESRI Shapefile” F:\keshan\shp_get\I51 F:\keshan\shp100w\I51.gdb -lco ENCODING=UTF-8,

The format is :ogr2ogr -f + Format name + Save the path + Original file path + Encoding mode

import os
from tqdm import tqdm

Path = 'F:\keshan\shp100w/'  
folder_names = os.listdir(Path)
# Script : Reference resources ogr2ogr -f "ESRI Shapefile" F:\keshan\shp_get\2 F:\keshan\shp100w\A49.gdb -lco ENCODING=UTF-8
bat_part1="ogr2ogr -f \"ESRI Shapefile\" F:\keshan\shp_get\\"
bat_part2=" F:\keshan\shp100w\\"
bat_part3=" -lco ENCODING=UTF-8"
#  Loop Directory 
for folder_name in tqdm(folder_names):
    bat_text=bat_part1+folder_name.replace(".gdb","")+bat_part2+folder_name+bat_part3
    print(bat_text)

Through the above script , Batch generate Export shp Of .bat Content . Package this content into .bat file , Input start+.bat route , Run the file

The operation results are as follows :

Open every file , Is the vector of the framing :

shp Vector merge

Use scripts , Traversal folder , Move all vector files with the same name into the same file :

import os
import shutil
from tqdm import tqdm

# Create local folder function 
def mkdir(path):
    #  Introduce modules 
    #  Remove the first space 
    path = path.strip()
    #  Remove the tail  \  Symbol 
    path = path.rstrip("\\")

    #  Determine if the path exists 
    #  There is  True
    #  non-existent  False
    isExists = os.path.exists(path)

    #  Judge the result 
    if not isExists:
        #  Create a directory if it doesn't exist 
        #  Create directory manipulation functions 
        os.makedirs(path)

        print(path + '  Create success ')
        return True
    else:
        #  Do not create if directory exists , And prompt that the directory already exists 
        print(path + '  directory already exists ')
        return False

Path = 'F:\keshan\shp_get/'
# Saved categories shp file location 
Save_Fenlei= 'F:\keshan\shp_100w_fenlei/'

folder_names = os.listdir(Path)
#  Loop Directory 
for folder_name in tqdm(folder_names):
    floder_PATH = os.path.join(Path, folder_name)
    file_names = os.listdir(floder_PATH)
    for file_names in file_names:
        # Get file path and name 
        file_path =os.path.join(floder_PATH, file_names)
        file_name=file_names.split(".")[0]
        file_suffix = file_names.split(".")[1]
        # Move the file to the specified directory   Name as file Copy the file named file_dir In the folder of 
        dir_path = Save_Fenlei +file_name
        #  Create folder   A folder where individual files are saved 
        mkdir(dir_path)
        # Change file name 
        file_new_name = file_name.split(".")[0]+"_"+folder_name+"."+file_suffix
        dst_name=os.path.join(dir_path, file_new_name)
        #  The specified file file Move to file_dir In the folder of 
        shutil.copy(file_path, dst_name)

Here we are , We have obtained... For each category shp vector , Load into gis In the software .

Now let's merge the vectors , First of all, I thought of arcgis and qgis Manual operation . But I'm lazy , Don't like repetitive operation , So I wrote a script to merge each category :

import os
import geopandas as gpd
import pandas as pd
from tqdm import tqdm

# Classified shp
Path = 'F:\keshan\shp_100w_fenlei/'
#  Saved merge file location 
Save_shp = r'F:\keshan\100Wmerge\shp/'
Save_geojson = r'F:\keshan\100Wmerge\geojson/'

folder_names = os.listdir(Path)
#  Loop Directory 
for folder_name in tqdm(folder_names):
    try:

        folder_name_path=os.path.join(Path, folder_name)

        file = os.listdir(folder_name_path)
	    # Traverse shp File merge 
        path = [os.path.join(folder_name_path, i) for i in file if ".shp" in i]
        gdf = gpd.GeoDataFrame(pd.concat([gpd.read_file(i) for i in path],
                                ignore_index=True), crs=gpd.read_file(path[0]).crs)
	   # export shp
        gdf_path_name_shp =Save_shp+folder_name+".shp"
        gdf.to_file(gdf_path_name_shp, driver="ESRI Shapefile", encoding="utf-8")

       # export geojson
        gdf_path_name_json =Save_geojson+folder_name+".gson"
        gdf.to_file(gdf_path_name_json, driver='GeoJSON', encoding="utf-8")
    
    except:
        pass


Through this step ,ANNP This national vector is merge Okay , Put it in gis View... In the software :

thus , We got shp and geojson Two formats of 1:100w National Geographic basic information data :

Here is why we export another one separately geojson The file of , Because of my own prejudice :gson Than shp To use ,qgis Than arcgis Well done .

other

thus , The data has been converted , You can use it directly . The data types are as follows :

There's a lot of data , You can see :

I saw a post posted on the remote sensing forum , You can go download This consolidated version of the data :

Reference resources

National Geographic information system resource directory .https://www.webmap.cn/main.do?method=index

Geodata Geographic Data Institute .2021 National edition 1:100 10000 public version of basic geographic information data

原网站

版权声明
本文为[Geographical space of ruiduobao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211332146411.html