Пример #1
0
def Label(order):
    """标注一个图层
    @type order: str
    @param order: 要标注的图层名称,以及要标志的域名
    @rtype: ActionResult
    @return: 返回操作的状态。
    """
    ordermap = order.split()
    layname = ordermap[0]
    confstr = " ".join(ordermap[1:])
    conflist = confstr.split(";")
    confmap = {}
    for conf in conflist:
        try:
            key, val = conf.split("=")
            confmap[key] = val
        except:
            pass
    try:
        from geosings.ui.PyMainPanel import GetMainPanel
        layer = GetMainPanel().canvas.map.GetLayer(layname)
        layer.labelProps = AnnotateProps(confmap)
    except:
        info('can not get layer %s. ', layname)
        raise
    return ActionResult.UpdateAll
Пример #2
0
def UnLabel(layername):
    """取消标注一个图层
    """
    try:
        from geosings.ui.PyMainPanel import GetMainPanel
        layer = GetMainPanel().canvas.map.GetLayer(layername)
        layer.labelProps = None
    except:
        info('can not get layer.%s', layname, mainDocument.ErrNo)
        raise
    return ActionResult.UpdateAll
Пример #3
0
def Table(layername=None):
    """展示一个图层的属性表
    @type layername: str
    @param layername: 要获取属性表的图层名称
    @rtype: ActionResult
    @return: 返回操作的状态
    """
    try:
        from geosings.ui.PyMainPanel import GetMainPanel
        if layername is None:
            _map = GetMainPanel().canvas.map
            selection = _map.GetSelectedLayersItems()
            if len(selection) > 0:
                layer = _map.GetLayer(selection[0])
            else:
                layer = _map.GetLayer(_map.GetLayerCount() - 1)
        else:
            layer = GetMainPanel().canvas.map.GetLayer(layername)
        if not layer: raise LayerNoFoundErr()
        tabFrame = TableFrame(GetMainPanel())
        tabctrl = ReportAttrTable(layer)
        cols, vals = tabctrl.GetTable()
        tabFrame.SetData(cols, vals)
        tabFrame.Show()
    except:
        info('can not tab layer:%s' % layername, mainDocument.ErrNo)
        raise
    return ActionResult.UpdateAll
Пример #4
0
def Open_R(path="", force=False):
    """打开一个图层的操作
    @type path: str
    @param path: 打开Layer所要用的连接字符串
    @type force: bool
    @param force: 如果有Layer已经打开且Document没有保存,是否强制打开
    @rtype: ActionResult
    @return: 返回操作的状态。
    """
    if path == "":
        dlg = OpenLayerDlg(None, 'r')
        if dlg.ShowModal() == wx.ID_OK:
            path = dlg.GetPath()
            dlg.Destroy()
        else:
            dlg.Destroy()
            return ActionResult.Successed
    try:
        #factory = LayerFactory()
        layer = OpenR(path)
        from geosings.ui.PyMainPanel import GetMainPanel
        GetMainPanel().canvas.map.AddLayer(layer)
    except:
        error('open file failure : %s', mainDocument.ErrNo)
        raise
        #return ActionResult.Failuse
    return ActionResult.UpdateAll
Пример #5
0
 def SentOrder(self,keyname="",keycode=0):
     """命令分发
     @type keyname: str
     @param keyname: 命令名
     @type keycode: int
     @param keycode: 命令码
     """
     #from UISettings import MSGKEY
     from geosings.core.system.GssConfDict import GSSMSGS as MSGKEY
     from geosings.ui.PyMainPanel import GetMainPanel
     debug("sent order: %s %s", keyname, keycode)
     if keycode==58:# ':' input the order
         #self.EnableInput(True)
         GetMainPanel().EnableInput(True)
         pass
     elif keyname==MSGKEY["MSG_KEY_MODE_ZOOMIN"]: #大写表示放大
         self.ctrl.RegHandler(ZoomInHandler(self.ctrl))
     elif keyname==MSGKEY["MSG_KEY_MODE_ZOOMOUT"]: #小写表示缩小
         self.ctrl.RegHandler(ZoomOutHandler(self.ctrl))
     elif keyname == MSGKEY["MSG_KEY_MODE_NO"]:
         self.ctrl.RegHandler(NoModeHandler(self.ctrl))
     elif keyname == MSGKEY["MSG_KEY_MODE_PAN"]:
         self.ctrl.RegHandler(PanHandler(self.ctrl))
     elif keyname == MSGKEY["MSG_KEY_MODE_INFO"]:
         self.ctrl.RegHandler(InfoHandler(self.ctrl))
     elif keycode==27 or keyname==MSGKEY["MSG_KEY_DRAW"]:
         self.ctrl.ReDraw()
     elif keyname==MSGKEY["MSG_KEY_FULL"]:
         self.ctrl.geoext = None
         self.ctrl.ReDraw()
Пример #6
0
def Close(name=None):
    """移除一个图层的操作
    @type name: str
    @param name: 要移除的图层的名称
    @rtype: ActionResult
    @return: 返回操作的状态。
    """
    try:
        from geosings.ui.PyMainPanel import GetMainPanel
        if name is None or name == "":
            GetMainPanel().canvas.map.RemoveLayer()
        else:
            GetMainPanel().canvas.map.RemoveLayer(name)
    except:
        info('can not close layer.%s' % name, mainDocument.ErrNo)
        raise
    return ActionResult.UpdateAll
Пример #7
0
def ZoomTo(name):
    """放大到一个图层范围
    @type name: str
    @param name: 要查看的图层名称
    @rtype: ActionResult
    @return: 返回操作的状态。
    """
    try:
        from geosings.ui.PyMainPanel import GetMainPanel
        map = GetMainPanel().canvas.map
        findn = map.GetLayerAt(name)
        if findn != -1:
            layer = map.layers[findn]
            GetMainPanel().canvas.geoext = layer.geoext
        else:
            raise LayerNoFoundErr()
    except (GssException, e):
        info('can not zoom to layer %s. %s', name, e.GetMessage())
        raise
    return ActionResult.UpdateAll
Пример #8
0
def ExportMap(oimgPath):
    """导出一个图层为一个图片
    """
    from geosings.ui.core.wxDC import MemDCClass
    from geosings.ui.PyMainPanel import GetMainPanel
    panel = GetMainPanel()
    canvas = panel.canvas
    rect = canvas.GetClientRect()
    dcobj = MemDCClass(rect.GetWidth(), rect.GetHeight())
    dc = dcobj.GetMemDC()
    canvas.DoDrawing(dc)
    dcobj.SaveImage(oimgPath)
    dcobj.SaveGeoInfo(mainDocument.geoext, oimgPath)
Пример #9
0
def Top(name):
    """将一个图层置顶
    @type name: str
    @param name: 要置顶的图层名称
    @rtype: ActionResult
    @return: 返回操作的状态。
    """
    try:
        from geosings.ui.PyMainPanel import GetMainPanel
        GetMainPanel().canvas.map.TopLayer(name)
    except:
        info('can not top layer %s.', name)
        raise
    return ActionResult.UpdateAll
Пример #10
0
def UVisible(layername):
    """使一个图层不可见
    @type layername: str
    @param layername: 要不可见的图层名称
    @rtype: ActionResult
    @return: 返回操作的状态
    """
    try:
        from geosings.ui.PyMainPanel import GetMainPanel
        GetMainPanel().canvas.map.UVisibleLayer(layername)
    except:
        info('can not !v layer.%s %s' % (layername, mainDocument.ErrNo))
        raise
    return ActionResult.UpdateAll
Пример #11
0
    def SetResult(self, features):
        from geosings.ui.PyMainPanel import GetMainPanel
        #组织搜索数据集
        rs = []
        keys = features.keys()
        for k in keys:
            fs = features[k]
            rs.extend([["feature_"+str(f.GetFID()), \
                    '%s : %s' % (_("Layer"),k), "", \
                    (lambda x:lambda evt:GetMainPanel().canvas.WinkFeatures([x]))(f)] \
                    for f in fs])

        self.found.SetRecordset(rs)

        self.Layout()
Пример #12
0
def Search(selstr):
    """搜索匹配的字符串
    @type selstr: str
    @parame selstr: 需要匹配的字符串
    """
    from geosings.core.system.EncodeTran import astr2sth
    from geosings.ui.PyMainPanel import GetMainPanel
    layers = GetMainPanel().canvas.map.GetSelectedLayers()
    if len(layers) == 0:  #如果没有选中任何图层,就全部扫描过去
        layers = GetMainPanel().canvas.map.layers
    features = {}
    for layer in layers:
        name = layer.name
        dataset = layer.DataSet()
        layerdefn = dataset.GetLayerDefn()
        fieldcount = layerdefn.GetFieldCount()
        strfields = []
        for fi in range(fieldcount):
            fielddefn = layerdefn.GetFieldDefn(fi)
            if fielddefn.GetType()==ogr.OFTString or \
                fielddefn.GetType()==ogr.OFTWideString:
                strfields.append(fielddefn.GetName())
        if len(strfields) > 0:
            fs1 = __searchStr(astr2sth(selstr, "utf-8"), dataset, strfields)
            fs2 = __searchStr(astr2sth(selstr, "cp936"), dataset, strfields)
            if (len(fs1) > 0 or len(fs2) > 0) and (name not in features):
                features[name] = []
            if len(fs1) > 0:
                features[name].extend(fs1)
            if len(fs2) > 0:
                features[name].extend(fs2)
            #dataset.SetAttributeFilter(oldexp)
        info("select %d feature from layer %s", len(features[name]), name)

    from geosings.ui.PyMainPanel import GetMainPanel
    GetMainPanel().searchPanel.SetResult(features)
Пример #13
0
def Select(selstr):
    """选择Feature并高亮
    @type selstr: str
    @parame selstr: 选择条件
    """
    import re
    from geosings.ui.PyMainPanel import GetMainPanel
    #s = '* from aa where aaaa=11'
    restr = r'^\s*((utf8|cp936|gbk)\(){0,1}\*\){0,1}\sfrom\s(\w+)\swhere\s(.+)'
    m = re.match(restr, selstr)
    if m is None:
        info('error sql:select %s', selstr)
        raise InvalidSQLErr()
    g = m.groups()
    GetMainPanel().canvas.map.SetWhere(g[2], g[3], g[1])
    return ActionResult.UpdateAll
Пример #14
0
def ExportMapAll(oimgPath):
    """导出一个图层为一个图片
    """
    from geosings.ui.core.wxDC import MemDCClass
    from geosings.ui.PyMainPanel import GetMainPanel
    panel = GetMainPanel()
    canvas = panel.canvas
    geoext = mainDocument.geoext
    allgeoext = canvas.map.allGeoExt
    dcrect = canvas.GetClientRect()
    allw = allgeoext.GetWidth() / geoext.GetWidth() * dcrect.GetWidth()
    allh = allgeoext.GetHeight() / geoext.GetHeight() * dcrect.GetHeight()
    dcobj = MemDCClass(allw, allh)
    dc = dcobj.GetMemDC()
    canvas.DoDrawing(dc, all=True)
    dcobj.SaveImage(oimgPath)
    dcobj.SaveGeoInfo(allgeoext, oimgPath)
Пример #15
0
 def OnLeftDown(self, evt):
     from geosings.ui.PyMainPanel import GetMainPanel
     map = self.ctrl.map
     p = evt.GetPosition()
     notebook = GetMainPanel().nb
     for i in range(notebook.GetPageCount()):
         if notebook.GetPageText(i)==_("Attribute"):
             notebook.SetSelection(i)
     if len(self.ctrl.map.GetSelectedLayersItems())>0:
         dcrect = self.ctrl.GetClientRect()
         if self.ctrl.geoext is not None:
             GetMainPanel().infoPanel.RegHLDrawFoo(self.ctrl.WinkFeatures)
             fs = self.ctrl.map.GetFeaturesByPoint((p.x,p.y),dcrect,self.ctrl.geoext)
             GetMainPanel().infoPanel.SetFeatures(fs)
         self.ctrl.SetFocus()
     else:
         error(_("you should select a layer as hightlight"))
Пример #16
0
 def __init__(self, features):
     """初始化画板
     @type features: list
     @param features: 要绘制的要素列表
     """
     from geosings.ui.PyMainPanel import GetMainPanel
     layer = GetMainPanel().canvas.map.GetLayers()[0]
     VectorRender.__init__(self, layer)
     self.features = features
     self.wink = 1
     self.aimFoo = None
     self.symbols = {
         ogr.wkbPoint: self.__InitHLSymbol(ogr.wkbPoint),
         ogr.wkbMultiPoint: self.__InitHLSymbol(ogr.wkbMultiPoint),
         ogr.wkbLineString: self.__InitHLSymbol(ogr.wkbLineString),
         ogr.wkbMultiLineString:
         self.__InitHLSymbol(ogr.wkbMultiLineString),
         ogr.wkbPolygon: self.__InitHLSymbol(ogr.wkbPolygon),
         ogr.wkbMultiPolygon: self.__InitHLSymbol(ogr.wkbMultiPolygon)
     }
Пример #17
0
 def OnLink(self, evt):
     #print 'link'
     from geosings.ui.core.Brain import msgParser
     opname = evt.GetEventObject().GetLabel()
     for hlconf in self.hllist:
         #print hlconf['name'], opname
         if opname == hlconf['name']:
             msgParser.SendMsg(hlconf['foo'] + " " + self.name)
             result = msgParser.result
             if result == ActionResult.UpdateAll:
                 from geosings.ui.PyMainPanel import GetMainPanel
                 GetMainPanel().canvas.ReDraw()
             endfoo, endfooargs = None, None
             if 'end' in hlconf:
                 endfoo = hlconf['end']
             if 'endargs' in hlconf:
                 endfooargs = hlconf['endargs']
             if endfoo:
                 if endfooargs:
                     endfoo(endfooargs)
                 else:
                     endfoo()
             break
Пример #18
0
def Info(layername):
    """显示图层的信息
    @type layername: str
    @param layername: 要获取和显示信息的图层名称
    @rtype: ActionResult
    @return: 返回操作的状态
    """
    try:
        from geosings.ui.PyMainPanel import GetMainPanel
        layer = GetMainPanel().canvas.map.GetLayer(layername)
        if not layer: raise LayerNoFoundErr()
        #infoframe = HtmlFrame(None,-1,"")
        #infoctrl = ReportLayerInfoCtrl(layer)
        #infoframe.LoadString(infoctrl.Report())
        #infoframe.Show()
        import webbrowser
        webbrowser.open(
            "http://localhost:2386/LayerInfos?layer=%s&t=%s" %
            (layer.path, layer.type), 1)
    except:
        info('can not i layer.%s %s' % (layername, mainDocument.ErrNo))
        raise
    return ActionResult.UpdateAll