예제 #1
0
 def __DrawRect(self,dc,x,y,w=None,h=None,x2=None,y2=None, \
         color=wx.BLACK,linew=1,brush=wx.TRANSPARENT_BRUSH):
     """绘制矩形
     @type dc: wxDC
     @param dc: 绘制DC
     @type x,y: int
     @param x,y: 绘制起始位置
     @type w,h: int
     @param w,h: 绘制的宽高(可以和后面的x2,y2互选)
     @type x2,y2: int
     @param x2,y2: 绘制的终止位置(该参数组和前面的wh是互斥的)
     @type color: wxColour
     @param color: 绘制颜色(外框)
     @type linew: int
     @param linew: 线宽
     @type brush: wxBrush
     @param brush: 填充颜色的画刷
     """
     peno = dc.GetPen()
     brusho = dc.GetBrush()
     pen = wx.Pen(color, linew, wx.SOLID)
     dc.SetPen(pen)
     #brush2 = wx.Brush(wx.Colour(255,255,12,77))
     dc.SetBrush(brush)
     if w is not None and h is not None:
         dc.DrawRectangle(x, y, w, h)
     if x2 is not None and y2 is not None:
         w = math.fabs(x - x2)
         h = math.fabs(y - y2)
         x = choose(x > x2, x2, x)
         y = choose(y > y2, y2, y)
         dc.DrawRectangle(x, y, w, h)
     dc.SetPen(peno)
     dc.SetBrush(brusho)
예제 #2
0
 def __GetBlockCount(self,w,h):
     """获取这一层图层一共有多少个瓦片
     @type w,h: int
     @param w,h: 图层有多少宽高
     @rtype: list
     @return: 返回横向和纵向有多少个瓦片
                 - 横向瓦片个数
                 - 纵向瓦片个数
     """
     bxcount = choose(w%self.blockw==0,w/self.blockw,w/self.blockw+1)
     bycount = choose(h%self.blockh==0,h/self.blockh,h/self.blockh+1)
     return bxcount,bycount
예제 #3
0
 def __init__(self,initConsole=True):
     dlevel = GSSCONF['debug']
     self.level = level = choose(dlevel,logging.DEBUG,logging.INFO)
     logging.getLogger('').setLevel(level)
     if initConsole:
         self.regStreamHandler(level)
     logging.addLevelName(100,_('message'))
예제 #4
0
def isCrackTa(ta):
    """判断是否是破碎边缘三角形
    """
    if ta.p1.z==ta.p2.z==ta.p3.z or \
        ta.p1.z!=ta.p2.z!=ta.p3.z!=ta.p1.z:#三点都在同一高度或者都不在同一高度
        return None
    same_e = None
    if ta.e1.p1.z == ta.e1.p2.z:
        same_e = ta.e1
    elif ta.e2.p1.z == ta.e2.p2.z:
        same_e = ta.e2
    elif ta.e3.p1.z == ta.e3.p2.z:
        same_e = ta.e3
    else: return None
    ta2 = choose(same_e.t1==ta,same_e.t2,same_e.t1)
    if ta2.__class__==OutSide:
        return None
    if ta2.p1.z!=ta2.p2.z!=ta2.p3.z:#另一个三角形三点不在一个平面,就不是
        return None
    p1 = ta.getPointByEdge(same_e)
    p2 = ta2.getPointByEdge(same_e)
    ta2ps = [ta2.p1,ta2.p2,ta2.p3]
    ta2ps = [e for e in ta2ps if e!=p2]
    #print ta2lines
    if getCos(p2,ta2ps[0],ta2ps[1])>=0:
        return None#如果角度小于90,则不是
    #看是否可以交换线段(两条线段是否相交)
    if same_e.iscross(TINEdge(p1,p2)):
        return ta,ta2,same_e,p1,p2
    else:
        return None
예제 #5
0
파일: Geom.py 프로젝트: hotlinv/geosings
def GetPointOnLineByDist(p2, p1, dist):
    """在一根线段上取靠近第一点的距离dist的点位置
    @type p2: point
    @param p2: 线段的起始点
    @type p1: point
    @param p1: 线段的终止点
    @type dist: number
    @param dist: 距离位置(必须大于零)
    """
    assert (dist > 0)  #距离必须大于零
    if p1[0] == p2[0]:
        y = choose(p2[1] > p1[1], p2[1] - dist, p2[1] + dist)
        return p1[0], y
    K = (p1[1] - p2[1]) / float((p1[0] - p2[0]))
    Q = float(p1[1] - p2[1] - K * p1[0])
    M = (dist * dist - p2[0] * p2[0] - Q * Q) / (K * K + 1)
    T = (K * Q - p2[0]) / (K * K + 1)
    x1 = math.sqrt(M + T * T) - T
    x2 = -math.sqrt(M + T * T) - T
    y1 = K * (x1 - p1[0]) + p1[1]
    y2 = K * (x2 - p1[0]) + p1[1]
    #print p2,p1,x1,y1,x2,y2,(p2[0]-p1[0]),(p2[0]-x1),(p2[1]-p1[1]),(p2[1]-y1)
    if ((p2[0]-p1[0])*(p2[0]-x1)>=0) and \
            ((p2[1]-p1[1])*(p2[1]-y1)>=0):
        return x1, y1
    else:
        return x2, y2
예제 #6
0
파일: Geom.py 프로젝트: hotlinv/geosings
def up_endian_type(wkb):
    """解析字节顺序
    @type wkb: binary str
    @param wkb: 要解析的二进制wkb
    @rtype: list
    @return: 返回一个列表
                - endian 字符串表达字节顺序
                - wkbtype wkb所表示的类型
                - endian_t 系统字节类型,表示字节顺序
    """
    endian_t = struct.unpack('b', wkb[0])[0]
    endian = choose(endian_t, '<', '>')
    wkbtype = struct.unpack(endian + 'I', wkb[1:5])[0]
    return endian, wkbtype, endian_t
예제 #7
0
def WriteRightElev(p1, p2, taa):
    """给内插的点付正确的高程值
    """
    global turnUpOrDown1
    global turnUpOrDown2
    elevthis = taa[0].p1.z#等高高程
    totlelong1=len2p(p1,insertps[0])
    totlelong2=len2p(p2,insertps[1])
    for i in range(0,len(insertps)-2,2):
        totlelong1+=len2p(insertps[i],insertps[i+2])
    for i in range(1,len(insertps)-2,2):
        totlelong2+=len2p(insertps[i],insertps[i+2])
    if p1.z!=p2.z:
        elevmid=choose(p1.z>p2.z,p2.z+(totlelong2/(totlelong1+totlelong2)*(p1.z-p2.z)), \
                p1.z+(totlelong1/(totlelong1+totlelong2)*(p2.z-p1.z)))
    else:
        if turnUpOrDown1*turnUpOrDown1>0:
            elevmid = elevthis+(turnUpOrDown1+turnUpOrDown2)/2.0/2.0
        else:
            elevmid = elevthis
    print "mid:",elevmid, "elev this",elevthis,"point count:",len(insertps)
    #mp = insertps[len(insertps)-1]
    #mp.z = elevmid
    nowlong1=len2p(p1,insertps[0])
    for ip in range(0,len(insertps),2):
        if ip==0:
            nowlong1=len2p(p1,insertps[0])
        else:
            nowlong1+=len2p(insertps[ip-2],insertps[ip])
        mp = insertps[ip]
        mp.z = p1.z+(nowlong1/totlelong1*(elevmid-p1.z))
        print '\n',"0000000000000",mp.z,ip,mp.x,mp.y
    nowlong2=len2p(p2,insertps[1])
    for ip in range(1,len(insertps),2):
        if ip==1:
            nowlong2=len2p(p2,insertps[1])
        else:
            nowlong2+=len2p(insertps[ip-2],insertps[ip])
        mp = insertps[ip]
        mp.z = p2.z+(nowlong2/totlelong2*(elevmid-p2.z))
        print '\n',"11111111111",mp.z,ip,mp.x,mp.y
예제 #8
0
def findElevRange(taarr):
    global turnUpOrDown1
    global turnUpOrDown2
    turnUpOrDown1 = 0
    turnUpOrDown2 = 0
    tao1,tao2 = taarr[0],taarr[len(taarr)-1]
    elev = tao1.p1.z
    tans1 = tao1.getAdjacentTriangles()
    tans2 = tao2.getAdjacentTriangles()
    #找出不在同一高度的的三角形
    sel_pe = []
    for ta in tans1:
        if not isTa3pSameElev(ta):
            if ta.p1.z != elev:
                sel_pe.append([ta.p1,ta.getEdgeByPoint(ta.p1)])
            if ta.p2.z != elev:
                sel_pe.append([ta.p2,ta.getEdgeByPoint(ta.p2)])
            if ta.p3.z != elev:
                sel_pe.append([ta.p3,ta.getEdgeByPoint(ta.p3)])
    print sel_pe[0][0].z,sel_pe[1][0].z,elev,"#"*10
    lager1 = sel_pe[0][0].z>elev and sel_pe[1][0].z>elev
    lager2 = sel_pe[0][0].z<elev and sel_pe[1][0].z<elev
    print lager1,lager2
    if lager1 or lager2:#要提到和elev一个档次
        tp1,tp2 = id(sel_pe[0][1].p1),id(sel_pe[0][1].p2)
        tp3,tp4 = id(sel_pe[1][1].p1),id(sel_pe[1][1].p2)
        p1 = choose((tp1==tp3 or tp1==tp4), sel_pe[0][1].p1, sel_pe[0][1].p2)
        if lager1:
            turnUpOrDown1 = max(elev-sel_pe[0][0].z, \
                    elev-sel_pe[1][0].z) #下坡
        else:
            turnUpOrDown1 = min(elev-sel_pe[0][0].z, \
                    elev-sel_pe[1][0].z) #上坡
    else:
        if sel_pe[0][1].len()>sel_pe[1][1].len():
            p1 = sel_pe[0][0]
        else:
            p1 = sel_pe[1][0]
    sel_pe = []
    for ta in tans2:
        if not isTa3pSameElev(ta):
            if ta.p1.z != elev:
                sel_pe.append([ta.p1,ta.getEdgeByPoint(ta.p1)])
            if ta.p2.z != elev:
                sel_pe.append([ta.p2,ta.getEdgeByPoint(ta.p2)])
            if ta.p3.z != elev:
                sel_pe.append([ta.p3,ta.getEdgeByPoint(ta.p3)])
    print sel_pe[0][0].z,sel_pe[1][0].z,"#"*10
    lager1 = sel_pe[0][0].z>elev and sel_pe[1][0].z>elev
    lager2 = sel_pe[0][0].z<elev and sel_pe[1][0].z<elev
    if lager1 or lager2:#要提到和elev一个档次
        tp1,tp2 = id(sel_pe[0][1].p1),id(sel_pe[0][1].p2)
        tp3,tp4 = id(sel_pe[1][1].p1),id(sel_pe[1][1].p2)
        p2 = choose((tp1==tp3 or tp1==tp4), sel_pe[0][1].p1, sel_pe[0][1].p2)
        if lager1:
            turnUpOrDown2 = max(elev-sel_pe[0][0].z, \
                    elev-sel_pe[1][0].z) #下坡
        else:
            turnUpOrDown2 = min(elev-sel_pe[0][0].z, \
                    elev-sel_pe[1][0].z) #上坡
    else:
        if sel_pe[0][1].len()>sel_pe[1][1].len():
            p2 = sel_pe[0][0]
        else:
            p2 = sel_pe[1][0]
    return p1,p2
예제 #9
0
파일: Geom.py 프로젝트: hotlinv/geosings
def make_endian_type(wkbtype):
    """封装字节顺序
    """
    endian_t = choose(BTOR == "<", 1, 0)
    return struct.pack(BTOR + 'bI', endian_t, wkbtype)
예제 #10
0
파일: Geom.py 프로젝트: hotlinv/geosings
"""
定义几何形状的操作

 - writer:linux_23; create: 2007.6.6; version:1; 创建
"""

import struct, Numeric, ogr, math
import sys as msys

endian_name = msys.byteorder

wkbXDR = '>'  # Big Endian
wkbNDR = '<'  # Little Endian
from geosings.core.system import choose

BTOR = choose(endian_name == 'little', wkbNDR, wkbNDR)


def up_endian_type(wkb):
    """解析字节顺序
    @type wkb: binary str
    @param wkb: 要解析的二进制wkb
    @rtype: list
    @return: 返回一个列表
                - endian 字符串表达字节顺序
                - wkbtype wkb所表示的类型
                - endian_t 系统字节类型,表示字节顺序
    """
    endian_t = struct.unpack('b', wkb[0])[0]
    endian = choose(endian_t, '<', '>')
    wkbtype = struct.unpack(endian + 'I', wkb[1:5])[0]