This is the 55th article in the Technical Writing Project (including translation). Set a small goal of 999, at least 2 articles per week.

For work reasons, it was necessary to obtain all local POI, so there would be a limit in the number of direct calls to Autonavi API (theoretically, if more than 1000 poIS, part of the data would be easily lost, and such loss would be very hidden and difficult to verify). Finally, after some difficulties, we sorted out the data based on online data

  1. Register an Autonavi account and obtain an Autonavi key
  2. Download and install ArcMap/ArcGIS
  3. The grab region is segmented isometric and the latitude and longitude of the polygon is derived
  4. Rerun autonavi API based on the latitude and longitude after cutting




Lead to


Register an Autonavi account and create an application to obtain a key, this is to see the official website documents or online search on the line, not to say more



Obtain administrative division points,Lbs.amap.com/api/webserv…



Copy the polyline and use any modern editor (vs code,notepad++, etc.);Replace it with a newline character and insert it on the first linex,ySave asjn.csv 

Download and install ArcMap 10.2 according to ArcMap 0 (ArcGIS10.2 install (perfect version — can solve common problems)), and crack, but do not Chinese (later point set transfer line will be error)

Get the coordinate point after segmentation

Import point set

File->Add Data->Add XY Data…



If you do not know how to use Arcmap to switch folders, you are advised to directly put the files in the folderDocument \ ArcGIS \Next, automatically bring inx,yField, click OK



Administrative division point images appear

Point set line

ArcToolbox -> Data Management Tools -> Features ->Points To Line



Use the fishing net function to divide administrative areas equally



Do not choose cell size width/height, because the coordinates imported by Autonavi are Mars coordinates, which do not belong to standard GPS coordinates, and ArcGis does not recognize them



So I have to do my own calculation, suppose I need to cut Jinan into 3km X 3km cells, referenceHow many meters is one degree of longitude and latitude, longitude 1 degree =85.39km, latitude 1 degree = about 111km. (right-left)*85.39/3=49.78826191 (Top-Bottom)*111/3=57.060475 (Top-Bottom)*111/3=57.060475 (Top-Bottom)



Be careful not to chooseCreate Label Points(optional)Choice, because you don’t need it

Fill the administrative divisions with color

ArcToolbox -> Data Management Tools -> Features -> Feature To Polygon



Take the intersection of fishing net and administrative division (erase the mesh part of fishing net outside administrative division)



I’m going to export it for later



Gets the latitude and longitude of the grid point

Refer to the big guy’s articlePython3 crawls POI of Gaud mapTo download the fishing net diagonal coordinate acquisition tool developed by the author

Link: Link:Pan.baidu.com/s/11nwWHDf7…

Extraction code: RDUV



Get diagonal coordinates



Grab autonavi POI

98% of the code is copied from Python3’s POI code, with minor modifications to prevent throwing from dict fields and the addition of saving fields

import requests
import json
from pymongo import MongoClient
import time

client = MongoClient('localhost'.27017)
db = client.POI_Jinanshi
collection = db.table_1
polygon_list = list(a)with open("jn2.txt".'r', encoding='UTF-8') as txt_file:
    for each_line in txt_file:
        ifeach_line ! ="" andeach_line ! ="\n":
            fields = each_line.split("\n")
            polygon = fields[0]
            polygon_list.append(polygon)

def getjson(polygon, page) :
    headers = {
        'User-Agent': 'the Mozilla / 5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36'
    }
    pa = {
        'key': 'xxxxxxxxxxxxxxxxxxxxxx'.Request from the console
        'polygon': polygon,
        'types':'970000 | 990000'.# Not too much
        'city':'0531'.'offset': 20.'page': page,
        'extensions': 'all'.'output': 'JSON'
    }
    r = requests.get('https://restapi.amap.com/v3/place/polygon?', params=pa, headers=headers)
    decodejson = json.loads(r.text)
    return decodejson

for each_polygon in polygon_list:
    not_last_page = True
    page = 1
    while not_last_page:
        decodejson = getjson(each_polygon, page)
        print(decodejson)
        count = decodejson.get('count'.0)
        print(each_polygon, page)
        if decodejson['pois'] :for eachone in decodejson['pois']:
                data={
                    'name':eachone.get('name'.None), # POI name
                    'types':eachone.get('type'.None), #POI category
                    'address':eachone.get('address'.None), # POI address
                    'location':eachone.get('location'.None), # POI coordinates
                    'city':eachone.get('cityname'.None), # city
                    'county':eachone.get('adname'.None), # counties
                    'province':eachone.get('pname'.None), # provinces
                    'count':count, Article # number
                    'polygon':each_polygon # Polygon latitude and longitude, easy to grab again later
                }
                collection.insert_one(data)
                time.sleep(0.2)
            page += 1
        else:
            not_last_page = False
Copy the code

Want ads

Friends in Jinan, Shandong, welcome to join us and do things together. Long-term recruitment, Java programmer, big data engineer, operation and maintenance engineer, front-end engineer.

The resources