• 大小: 154KB
    文件类型: .zip
    金币: 2
    下载: 2 次
    发布日期: 2021-06-17
  • 语言: Python
  • 标签:

资源简介

下载中国县级行政区划的边界数据并处理成geojson数据和Echarts的json数据

资源截图

代码片段和文件信息

#--*-- coding:utf-8 --*--
import urllib2
import json
from urllib import urlencode


def saveToJSON(namedata):
    file = open(name+‘.json‘‘w‘)
    print json.dumps(data).encode(‘utf-8‘)
    file.write(json.dumps(data).encode(‘utf-8‘))
    file.close()




def parse_str_to_json(dataStr):
    str1 = ‘(‘
    pos = dataStr.index(str1)

    if pos < 0:
        print(“返回的数据格式不正确 示例为: jsonp_xxxxx_({...})  {...}内为json格式 “)
        return

    newJsonStr = dataStr[pos+1:-1]
    return json.loads(newJsonStr)




def parse_json_to_geo(jsonData citycode):
    geojson = {}
    coordinates = []
    id = ‘‘
    name = ‘‘
    count = 0
    print len(jsonData[‘districts‘])
    for district in jsonData[‘districts‘]:
        id = district[‘adcode‘]
        name = district[‘name‘]
        code = district[‘citycode‘]
        print code
        if code != citycode:
            print name + ‘ - (‘ + id + ‘) ‘+code+‘ IS NOT ‘+citycode
            continue
        polylineArrStr = district[‘polyline‘]
        polylineArr = polylineArrStr.split(‘|‘)
        count = len(polylineArr)
        if count > 1:
            coordinategroup = []
            for polyline in polylineArr:
                pointStrArr = polyline.split(‘;‘)

                cordinate = []
                for pointStr in pointStrArr:
                    pointArr = pointStr.split(‘‘)
                    lng = float(pointArr[0])
                    lat = float(pointArr[1])
                    coordArr = [lnglat]
                    cordinate.append(coordArr)
        
                coordinategroup.append(cordinate)
            coordinates.append(coordinategroup)
        else:
            for polyline in polylineArr:
                pointStrArr = polyline.split(‘;‘)

                cordinate = []
                for pointStr in pointStrArr:
                    pointArr = pointStr.split(‘‘)
                    lng = float(pointArr[0])
                    lat = float(pointArr[1])
                    coordArr = [lnglat]
                    cordinate.append(coordArr)
        
                coordinates.append(cordinate)

    geojson[‘type‘] = ‘Feature‘
    geojson[‘id‘] = id
    geojson[‘properties‘] = {}
    geojson[‘properties‘][‘name‘] = name
    geojson[‘geometry‘] = {}
    geojson[‘geometry‘][‘type‘] =  ‘MultiPolygon‘ if count > 1 else ‘Polygon‘
    geojson[‘geometry‘][‘coordinates‘] = coordinates
    print geojson
    return geojson


def get_str_from_amap(key):
    encodeUrl = urlencode({ ‘subdistrict‘:‘1‘
                            ‘level‘:‘district‘
                            ‘extensions‘:‘all‘
                            ‘key‘:‘608d75903d29ad471362f8c58c550daf‘
                            ‘s‘:‘rsv3‘
                            ‘output‘:‘json‘
                            ‘keywords‘:key
                            ‘callback‘:‘jsonp_146292_‘
                            ‘platform‘:‘JS‘
                            ‘logversion‘:‘2.0‘
                            ‘sdkversion‘:‘1.3‘
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-08-03 02:32  GeoJSON-for-ECharts-master\
     目录           0  2016-08-03 02:32  GeoJSON-for-ECharts-master\.vscode\
     文件        1691  2016-08-03 02:32  GeoJSON-for-ECharts-master\.vscode\launch.json
     文件           0  2016-08-03 02:32  GeoJSON-for-ECharts-master\1.json
     文件         483  2016-08-03 02:32  GeoJSON-for-ECharts-master\README.md
     文件        9481  2016-08-03 02:32  GeoJSON-for-ECharts-master\example.json
     文件        5296  2016-08-03 02:32  GeoJSON-for-ECharts-master\geoData.py
     文件          20  2016-08-03 02:32  GeoJSON-for-ECharts-master\merge.py
     文件       14645  2016-08-03 02:32  GeoJSON-for-ECharts-master\东西湖区.json
     文件       54227  2016-08-03 02:32  GeoJSON-for-ECharts-master\新洲区.json
     文件       12626  2016-08-03 02:32  GeoJSON-for-ECharts-master\武昌区.json
     文件      261793  2016-08-03 02:32  GeoJSON-for-ECharts-master\武汉市.json
     文件       13798  2016-08-03 02:32  GeoJSON-for-ECharts-master\汉南区.json
     文件        4948  2016-08-03 02:32  GeoJSON-for-ECharts-master\汉阳区.json
     文件       37347  2016-08-03 02:32  GeoJSON-for-ECharts-master\江夏区.json
     文件        4339  2016-08-03 02:32  GeoJSON-for-ECharts-master\江岸区.json
     文件        7042  2016-08-03 02:32  GeoJSON-for-ECharts-master\江汉区.json
     文件       38696  2016-08-03 02:32  GeoJSON-for-ECharts-master\洪山区.json
     文件        7719  2016-08-03 02:32  GeoJSON-for-ECharts-master\硚口区.json
     文件       24618  2016-08-03 02:32  GeoJSON-for-ECharts-master\蔡甸区.json
     文件        5756  2016-08-03 02:32  GeoJSON-for-ECharts-master\青山区.json
     文件       35963  2016-08-03 02:32  GeoJSON-for-ECharts-master\黄陂区.json

评论

共有 条评论