CZML中的动态面——如何将一个面区域由小变大(县到省的过程)(6)整个过程中所有代码

这篇博客提供了CZML中动态显示面区域变化的完整代码,从县逐步扩展到省级范围。尽管代码中包含一些试验性的部分且未添加注释,博主分享了这一过程的实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本想将代码文件缀在上一篇的后面,但因为没这个功能,所以新开一篇,放置代码,其中有些是废的,有些是摸索中写的,没有写注释,不知道以后自己能不能看懂。。。。。。哈哈哈哈哈哈哈

import json
import numpy
 
def openShpJson(fileName):
    with open(fileName,'r',encoding='utf-8') as f:
        data = json.load(f)
        p = data['features'][0]['geometry']['rings'][0]
        pstr = json.dumps(p, indent=4)
        #pstr = json.dumps(data, indent=4)
        #print(pstr)
    return p

def openJson(fileName):
    with open(fileName,'r',encoding='utf-8') as f:
        data = json.load(f)
        p = [[float(x) for x in inner] for inner in data]
        pstr = json.dumps(p, indent=4)
        #pstr = json.dumps(data, indent=4)
        print(pstr)
    return p
        
def czml(fileName):
    with open(fileName,'r',encoding='utf-8') as f:
        data = json.load(f)
        p = data[1]['polygon']['positions']['references']
        pstr = json.dumps(p, indent=4)
        p2 = data[2]
        pstr2 = json.dumps(p2, indent=4)
        print(pstr)
        print(pstr2)

def creat_v(i,time,p):
    v = {
            "id": "",
            "position": {
                "interpolationAlgorithm": "LINEAR",
                "interpolationDegree": 1,
                "interval": "2012-08-04T16:00:00Z/2012-08-04T17:00:00Z",
                "epoch": "2012-08-04T16:00:00Z",
                "cartographicDegrees": []
            }
        }
    v['id'] = "v%s" % i
    cd = v['position']['cartographicDegrees']
    cd.extend([time,p[0],p[1],0])
    return v
    
def add_v(v,time,p):
    cd = v['position']['cartographicDegrees']
    cd.extend([time,p[0],p[1],0])
    return v

def ct(pos,pos2):
    pos = numpy.array(pos)
    pos2 = numpy.array(pos2)
    diffMat = pos - pos2
    sqDiffMat = diffMat**2
    sqDistances = sqDiffMat.sum(axis=0)
    distances = sqDistances**0.5
    return int(distances*333)

def dist(pos,pos2):
    p = numpy.pi/180
    a = numpy.sin(pos[1]*p)*numpy.sin(pos2[1]*p)
    b = numpy.cos(pos[1]*p)*numpy.cos(pos2[1]*p)*numpy.cos((pos2[0]-pos[0])*p)
    d = 6371.004*numpy.arccos(a+b)
    return d   

def czml_w(fileName,i,pos,pos2,t):
    with open(fileName,'r',encoding='utf-8') as f:
        data = json.load(f)
        p = data[1]['polygon']['positions']['references']
        
    vp = ["v%s#position" % i]
    p.extend(vp)
    v1 = creat_v(i,0,pos)
    v = add_v(v1,t,pos2)
    #print(v)
    data.append(v)
    
    with open(fileName, 'w',encoding='utf-8') as f:
        json.dump(data, f)
        
    #print("ok")

    
def abstract_f(f1,f2):
    with open(f1,'r',encoding='utf-8') as f:
        data = json.load(f)
        p = data['features'][0]['geometry']['rings'][0]
      
    data['features'][0]['geometry']['rings'][0] = p[::13]

    with open(f2, 'w',encoding='utf-8') as ft:
        json.dump(data, ft)
        
    print("ok") 

def classify0(inX,dataSet,labels,k):
	dataSetSize = dataSet.shape[0]
	diffMat = tile(inX,(dataSetSize,1)) - dataSet
	sqDiffMat = diffMat**2
	sqDistances = sqDiffMat.sum(axis=1)
	distances = sqDistances**0.5
	sortedDistIndicies = distances.argsort()
	classCount={}
	for i in range(k):
		voteIlabel = labels[sortedDistIndicies[i]]
		classCount[voteIlabel] = classCount.get(voteIlabel,0) + 1
	sortedClassCount = sorted(classCount.iteritems(),key = operator.itemgetter(1),reverse = True)
	return sortedClassCount[0][0]

def order2p(p1,p2):
    p1 = numpy.array(p1)
    p2 = numpy.array(p2)
    p = []
    for x in p1:
        dataSetSize = p2.shape[0]
        diffMat = numpy.tile(x,(dataSetSize,1)) - p2
        sqDiffMat = diffMat**2
        sqDistances = sqDiffMat.sum(axis=1)
        distances = sqDistances**0.5
        sortedDistIndicies = distances.argsort()
        #p = numpy.vstack((p,p2[sortedDistIndicies[0]])) 
        p.append(p2[sortedDistIndicies[0]].tolist())
        p2 = numpy.delete(p2,sortedDistIndicies[0],axis = 0)
    return p

def order2p2(p1,p2):
    p = []
    for x in p1:
        distance = []
        for y in p2:
            distance.append(dist(x,y))
        disarr = numpy.array(distance)
        sortdis = disarr.argsort()
        p.append(p2[sortdis[0]].tolist())
        p2 = numpy.delete(p2,sortdis[0],axis = 0)
    return p    

def myrange():
    mian = openJson('mp.json')
    da = openJson('dp.json')
    for i in range(len(mian)):
        czml_w('czml.json',i,mian[i],da[i],900)
        
    print("ok")

#openJson('mp.json')

myrange()
#p1 = [[0,1],[0,2],[0,3],[0,4],[0,5]]
#p2 = [[3,0],[5,0],[2,0],[1,0],[4,0]]
#print(order2p(p1,p2))
#abstract_f('da.json','da13.json')    
#pnum = openShpJson('mian.json')
#pnum2 = openShpJson('da13.json')
#print(len(pnum))
#print(len(pnum2))
#czml('czml.json')
#p1 = [100,90]
#p2 = [110,80]
#myV = creat_v(11,0,p1)
#print(myV)
#print(add_v(myV,600,p2))
#czml_w('czml.json',11)
#p1 = [101.006713,31.3392944]
#p2 = [102.446952,33.5661315] 
#print(dist(p1,p2))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值