Пример #1
0
def flatten():
    def get_vol_name(towerid, lines, codes):
        ret = ''
        for line in lines:
            if towerid in line['properties']['nodes']:
                c = line['properties']['voltage']
                if codes['voltage_level'].has_key(c):
                    ret = codes['voltage_level'][c]
                    break
        return ret    
        
    db_util.init_global()
    towers = db_util.mongo_find('kmgd', 'features', conditions={"properties.webgis_type":"point_tower", "geometry2d.type":"Point"})
    lines = db_util.mongo_find('kmgd', 'network', conditions={"properties.webgis_type":"polyline_line"})
    codes = db_util.mongo_find_one('kmgd', 'codes', {})
    ll = []
    #print(len(l))
    for i in towers:
        o = {}
        tower_id = i['_id']
        
        o['_id'] = ObjectId(tower_id)
        o['lng'] = i['geometry']['coordinates'][0]
        o['lat'] = i['geometry']['coordinates'][1]
        o['name'] = i['properties']['name']
        o['voltage'] = get_vol_name(tower_id, lines, codes)
        ll.append(unicode(o).replace(' u', ''))
    s = '\n'.join(ll)
    with open(JSONFILE1, 'w') as f:
        f.write(s)
Пример #2
0
def test11():
    ret = []
    pointlist = mongo_find('kmgd', 'features', {})
    for p in pointlist:
        if p['properties'].has_key('function_pos_type'):
            p['properties']['function_type'] = p['properties']['function_pos_type']
            del p['properties']['function_pos_type']
            ret.append(p)
    mongo_action('kmgd', 'features', 'save', ret)
Пример #3
0
def flatten2():
    db_util.init_global()
    l = db_util.mongo_find('kmgd', 'network', conditions={"properties.webgis_type":"polyline_line"})
    
    ll = []
    print(len(l))
    for i in l:
        o = {}
        o['nodes'] = i['properties']['nodes']
        lll = [ObjectId(ii) for ii in o['nodes']]
        o['nodes'] = lll
        o['name'] = i['properties']['name']
        ll.append(unicode(o).replace(' u', ''))
    s = '\n'.join(ll)
    with open(JSONFILE2, 'w') as f:
        f.write(s)
Пример #4
0
def test7():
    def get_line_id(alist, code):
        return _.find(alist, lambda x: x['properties'].has_key('func_pos_code') and x['properties']['func_pos_code'] == code)
        # return _.matches_property('properties.func_pos_code', code)(alist)
    def get_point_id(alist, code):
        return _.find(alist, lambda x: x['properties'].has_key('function_pos_code') and x['properties']['func_pos_code'] == code)


    XLS_FILE = ur'D:\2014项目\配电网故障定位\yx_line.xls'
    book = xlrd.open_workbook(XLS_FILE)
    startrowidx = 1
    toplines = set()
    for sheet in book.sheets():
        for row in range(startrowidx, sheet.nrows):
            if len(sheet.cell_value(row, 6)):
                toplines.add(sheet.cell_value(row, 6))
    # if True:
    #     print (toplines)
    #     return

    ret = []

    idx = 0
    features = mongo_find('kmgd', 'features', {'properties.webgis_type':'point_dn'})
    for topline in toplines:
        polyline_dn = mongo_find_one('kmgd', 'network', {'properties.webgis_type':'polyline_dn',
                                                     'properties.func_pos_code':topline})
        if polyline_dn:
            idx1 = 0
            for feature in features:
                if feature.has_key('properties') and feature['properties'].has_key('line_func_code') and feature['properties']['line_func_code'] == topline:
                    if not polyline_dn['properties'].has_key('nodes'):
                        polyline_dn['properties']['nodes'] = []
                    if not feature['_id'] in polyline_dn['properties']['nodes']:
                        polyline_dn['properties']['nodes'].append(feature['_id'])
                        idx1 += 1
            print('%d-%s nodes:%d' % (idx, polyline_dn['_id'], len(polyline_dn['properties']['nodes'])))
            idx += 1
            ret.append(polyline_dn)
            # if idx > 10:
            #     break
    mongo_action('kmgd', 'network', 'save', ret)
Пример #5
0
        break
    print(json.dumps(ret, ensure_ascii=False, indent=4))
    # mongo_action('kmgd', 'features', 'save', ret)

def test6():
    def get_line_id(alist, code):
        return _.find(alist, lambda x: x['properties'].has_key('func_pos_code') and x['properties']['func_pos_code'] == code)
        # return _.matches_property('properties.func_pos_code', code)(alist)
    def get_point_id(alist, code):
        return _.find(alist, lambda x: x['properties'].has_key('function_pos_code') and x['properties'][
                                                                                            'func_pos_code'] == code)
    ret = []
    linesmap = {}
    with codecs.open(ur'd:\linesmap.json', 'r', 'utf-8-sig') as f:
        linesmap = json.loads(f.read())
    polyline_dn = mongo_find('kmgd', 'network', {'properties.webgis_type':'polyline_dn'})
    # towers = mongo_find('kmgd', 'features', {'properties.webgis_type':'point_tower'})
    idx = 0
    for k in linesmap.keys():
        codes = _.uniq(_.flatten(linesmap[k]))
        o = get_line_id(polyline_dn, k)
        if o:
            # l = mongo_find('kmgd', 'features', {'properties.line_func_code':k})
            # ids = _.pluck(l, '_id')
            ll = mongo_find('kmgd', 'features', {'properties.function_pos_code':{'$in':codes}})
            if len(ll):
                lll = _.pluck(ll, '_id')
                o['properties']['nodes'] = lll
                # o = add_mongo_id(o)
                ret.append(o)
                idx += 1