Example #1
0
    def drawSubGiMap(self, idx, bufferWidth, bufferHeight, bmp):
        """
        Draw two relative Gi* maps for current Gi* map
        """
        dc = wx.BufferedDC(None, bmp)
        dc.SetBrush(wx.WHITE_BRUSH)
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangle(0, 0, bufferWidth, bufferHeight)

        if not "Linux" in stars.APP_PLATFORM:
            # not good drawing effect using GCDC in linux
            dc = wx.GCDC(dc)

        view = View2ScreenTransform(self.extent, bufferWidth, bufferHeight)

        p_values = self.space_gstar[idx]
        z_values = self.space_gstar_z[idx]

        not_sig = list(np.where(p_values > 0.05)[0])
        sig = set(np.where(p_values <= 0.05)[0])
        hotspots = list(sig.intersection(set(np.where(z_values >= 0)[0])))
        coldspots = list(sig.intersection(set(np.where(z_values < 0)[0])))
        id_groups = [not_sig, hotspots, coldspots]

        from stars.visualization.maps.BaseMap import PolygonLayer
        draw_layer = PolygonLayer(self, self.layer, build_spatial_index=False)
        #edge_clr = wx.Colour(200,200,200, self.opaque)
        edge_clr = self.color_schema_dict[self.layer.name].edge_color
        draw_layer.set_edge_color(edge_clr)
        draw_layer.set_data_group(id_groups)
        draw_layer.set_fill_color_group(self.gi_color_group)
        draw_layer.draw(dc, view)

        return bmp
Example #2
0
    def drawSubView(self, lisa_idx, bufferWidth, bufferHeight, bmp):
        dc = wx.BufferedDC(None, bmp)
        dc.SetBrush(wx.WHITE_BRUSH)
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangle(0, 0, bufferWidth, bufferHeight)

        if not "Linux" in stars.APP_PLATFORM:
            # not good drawing effect using GCDC in linux
            dc = wx.GCDC(dc)

        view = View2ScreenTransform(self.extent, bufferWidth, bufferHeight)

        ml = self.moran_locals[lisa_idx]
        # 0 not significant, 1 HH, 2 LL, 3 LH, 4 HL, 5 Neighborless
        sigFlag = ml[2]
        clusterFlag = ml[3]
        lm_sig = np.array(sigFlag)
        lm_q = np.array(clusterFlag)

        id_groups = [[] for i in range(6)]
        for i, sig in enumerate(lm_sig):
            if sig > 0:
                id_groups[lm_q[i]].append(i)
            else:
                id_groups[0].append(i)

        from stars.visualization.maps.BaseMap import PolygonLayer
        draw_layer = PolygonLayer(self, self.layer, build_spatial_index=False)
        #edge_clr = wx.WHITE#wx.Colour(200,200,200, self.opaque)
        edge_clr = self.color_schema_dict[self.layer.name].edge_color
        draw_layer.set_edge_color(edge_clr)
        draw_layer.set_data_group(id_groups)
        draw_layer.set_fill_color_group(self.lisa_color_group)
        draw_layer.draw(dc, view)
Example #3
0
    def drawSubLISA(self, lisa_idx, bufferWidth, bufferHeight, bmp):
        """
        Draw two relative LISA maps for current Markov LISA map
        """
        dc = wx.BufferedDC(None, bmp)
        dc.SetBrush(wx.WHITE_BRUSH)
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangle(0, 0, bufferWidth, bufferHeight)

        if not "Linux" in stars.APP_PLATFORM:
            # not good drawing effect using GCDC in linux
            dc = wx.GCDC(dc)

        view = View2ScreenTransform(self.extent, bufferWidth, bufferHeight)

        lm = self.moran_locals[lisa_idx]
        # 0 not significant, 1 HH, 2 LL, 3 LH, 4 HL, 5 Neighborless
        try:
            # LISA from c++ DLL call
            localMoran, sigLocalMoran, sigFlag, clusterFlag = lm
            lm_moran = np.array(localMoran)
            lm_p_sim = np.array(sigLocalMoran)
            lm_sig = np.array(sigFlag)
            lm_q = np.array(clusterFlag)
            candidates = np.where(lm_sig < 1)[0]
            id_groups = []
            id_groups.append(list(candidates))
            for i in range(1, n):
                cluster = set(np.where(lm_q == i)[0]) - set(candidates)
                id_groups.append(cluster)
        except:
            # LISA from Pysal call
            sigFlag = lm[2]
            clusterFlag = lm[3]
            lm_sig = np.array(sigFlag)
            lm_q = np.array(clusterFlag)
            id_groups = [[] for i in range(6)]
            for i, sig in enumerate(lm_sig):
                if sig > 0:
                    id_groups[lm_q[i]].append(i)
                else:
                    id_groups[0].append(i)

        from stars.visualization.maps.BaseMap import PolygonLayer
        draw_layer = PolygonLayer(self, self.layer, build_spatial_index=False)
        #edge_clr = wx.Colour(200,200,200, self.opaque)
        edge_clr = self.color_schema_dict[self.layer.name].edge_color
        draw_layer.set_edge_color(edge_clr)
        draw_layer.set_data_group(id_groups)
        lisa_color_group = [
            self.NOT_SIG_color, self.HH_color, self.LL_color, self.LH_color,
            self.HL_color, self.OBSOLETE_color
        ]
        draw_layer.set_fill_color_group(lisa_color_group)
        draw_layer.draw(dc, view)

        return bmp
Example #4
0
    def __init__(self, parent, shapefileObject, name):
        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)

        from stars.visualization.maps.BaseMap import PolygonLayer, PointLayer, LineLayer

        self.layer = shapefileObject
        self.dbf = self.layer.dbf
        self.name = name
        self.parent = parent
        self.current_selected = {}  # {id: centroid}
        self.isEvtHandle = False

        tID = wx.NewId()
        self.table = DataListCtrl(
            self,
            tID,
            self.dbf,
            style=wx.LC_REPORT
            | wx.LC_VIRTUAL
            #| wx.BORDER_SUNKEN
            | wx.BORDER_NONE
            | wx.LC_EDIT_LABELS
            #| wx.LC_SORT_ASCENDING
            #| wx.LC_NO_HEADER
            | wx.LC_VRULES
            | wx.LC_HRULES
            #| wx.LC_SINGLE_SEL
        )

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.table, 1, wx.EXPAND)

        if self.layer.shape_type == stars.SHP_POINT:
            self.draw_layer = PointLayer(self, self.layer)
        elif self.layer.shape_type == stars.SHP_LINE:
            self.draw_layer = LineLayer(self, self.layer)
        elif self.layer.shape_type == stars.SHP_POLYGON:
            self.draw_layer = PolygonLayer(self, self.layer)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)

        # table events
        self.table.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
        self.table.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)

        # register event_handler to THE OBSERVER
        while parent != None:
            if isinstance(parent, stars.Main):
                self.observer = parent.observer
            parent = parent.GetParent()

        self.Register(stars.EVT_OBJS_SELECT, self.OnRecordsSelect)
        self.Register(stars.EVT_OBJS_UNSELECT, self.OnNoRecordSelect)

        self.parent.Bind(wx.EVT_CLOSE,
                         self.OnClose)  # OnClose Only send to Frame/Dialog
Example #5
0
 def __init__(self, parent, shapefileObject, name):
     wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
     
     from stars.visualization.maps.BaseMap import PolygonLayer, PointLayer, LineLayer
     
     self.layer = shapefileObject
     self.dbf = self.layer.dbf
     self.name = name
     self.parent = parent
     self.current_selected = {}  # {id: centroid}
     self.isEvtHandle = False
     
     tID = wx.NewId()
     self.table = DataListCtrl(
         self, 
         tID,
         self.dbf,
         style=wx.LC_REPORT 
         | wx.LC_VIRTUAL
         #| wx.BORDER_SUNKEN
         | wx.BORDER_NONE
         | wx.LC_EDIT_LABELS
         #| wx.LC_SORT_ASCENDING
         #| wx.LC_NO_HEADER
         | wx.LC_VRULES
         | wx.LC_HRULES
         #| wx.LC_SINGLE_SEL
     )
     
     sizer = wx.BoxSizer(wx.VERTICAL)
     sizer.Add(self.table, 1, wx.EXPAND)
    
     if self.layer.shape_type == stars.SHP_POINT:
         self.draw_layer = PointLayer(self,self.layer)
     elif self.layer.shape_type == stars.SHP_LINE:
         self.draw_layer = LineLayer(self, self.layer)
     elif self.layer.shape_type == stars.SHP_POLYGON:
         self.draw_layer = PolygonLayer(self,self.layer)  
          
     self.SetSizer(sizer)
     self.SetAutoLayout(True)
     
     # table events
     self.table.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
     self.table.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
     
     # register event_handler to THE OBSERVER
     while parent != None:
         if isinstance(parent, stars.Main):
             self.observer = parent.observer
         parent = parent.GetParent()
         
     self.Register(stars.EVT_OBJS_SELECT, self.OnRecordsSelect)
     self.Register(stars.EVT_OBJS_UNSELECT, self.OnNoRecordSelect)
     
     self.parent.Bind(wx.EVT_CLOSE, self.OnClose) # OnClose Only send to Frame/Dialog
Example #6
0
 def draw_space_in_buffer(self, space_shp, width=6000,height=6000):
     """
     Function for fast space-time query: how many points
     sit in each polygon
     """
     from stars.visualization.maps.BaseMap import PolygonLayer
     from stars.visualization.utils import View2ScreenTransform,DrawPurePoints
     # specify different color for each polygon
     poly_color_dict = {}
     n = len(space_shp)
     
     if n > 10000:
         width = 9000
         height = 9000
     
     id_group = []
     color_group = []
     color_range = 254*254*254 - 1
     used_color = {}
     for i in range(n):
         color_idx = random.randint(1,color_range)
         while color_idx in used_color: 
             color_idx = random.randint(1,color_range)
         used_color[color_idx] = True
         r = color_idx & 255
         g = (color_idx>>8) & 255
         b = (color_idx>>16) & 255
         id_group.append([i])
         color_group.append(wx.Color(r,g,b))
         poly_color_dict[(r,g,b)] = i
         
     # draw polygon to an empty_buffer
     polygon_layer = PolygonLayer(self, space_shp)
     polygon_layer.set_edge_color(wx.Color(0,0,0,0))
     polygon_layer.set_data_group(id_group)
     polygon_layer.set_fill_color_group(color_group)
     #polygon_layer.set_edge_color_group(color_group)
     
     view = View2ScreenTransform(space_shp.extent, width, height)
     buffer = wx.EmptyBitmap(width, height)
     dc = wx.BufferedDC(None, buffer)
     dc.Clear()
     polygon_layer.draw(dc, view, drawRaw=True)
     
     """
     _points = []
     for p in points: 
         x,y = view.view_to_pixel(p[0],p[1])
         x,y = int(round(x)), int(round(y))
         _points.append((x,y))
     DrawPurePoints(dc, _points)
     """
     bmp = wx.ImageFromBitmap(buffer)
     #buffer.SaveFile('test.bmp',wx.BITMAP_TYPE_BMP)
     return bmp,view,poly_color_dict
Example #7
0
 def drawSubLISA(self, lisa_idx, bufferWidth, bufferHeight,bmp):
     """
     Draw two relative LISA maps for current Markov LISA map
     """
     dc = wx.BufferedDC(None, bmp)
     dc.SetBrush(wx.WHITE_BRUSH)
     dc.SetPen(wx.TRANSPARENT_PEN)
     dc.DrawRectangle(0,0,bufferWidth,bufferHeight)
     
     if not "Linux" in stars.APP_PLATFORM:
         # not good drawing effect using GCDC in linux
         dc = wx.GCDC(dc)
     
     view = View2ScreenTransform(
         self.extent, 
         bufferWidth, 
         bufferHeight
         ) 
     
     lm = self.moran_locals[lisa_idx]
     # 0 not significant, 1 HH, 2 LL, 3 LH, 4 HL, 5 Neighborless
     try:
         # LISA from c++ DLL call
         localMoran, sigLocalMoran, sigFlag, clusterFlag = lm
         lm_moran = np.array(localMoran)
         lm_p_sim = np.array(sigLocalMoran)
         lm_sig = np.array(sigFlag)
         lm_q = np.array(clusterFlag)
         candidates = np.where(lm_sig<1)[0]
         id_groups = []
         id_groups.append(list(candidates))
         for i in range(1,n):
             cluster = set(np.where(lm_q==i)[0]) - set(candidates)
             id_groups.append(cluster)
     except:
         # LISA from Pysal call
         sigFlag = lm[2]
         clusterFlag = lm[3]
         lm_sig = np.array(sigFlag)
         lm_q = np.array(clusterFlag)
         id_groups = [[] for i in range(6)]
         for i,sig in enumerate(lm_sig):
             if sig > 0:
                 id_groups[lm_q[i]].append(i)
             else:
                 id_groups[0].append(i)
         
     from stars.visualization.maps.BaseMap import PolygonLayer
     draw_layer = PolygonLayer(self, self.layer, build_spatial_index=False)
     #edge_clr = wx.Colour(200,200,200, self.opaque)
     edge_clr = self.color_schema_dict[self.layer.name].edge_color
     draw_layer.set_edge_color(edge_clr)
     draw_layer.set_data_group(id_groups)
     lisa_color_group = [self.NOT_SIG_color,self.HH_color,self.LL_color,
                         self.LH_color,self.HL_color,self.OBSOLETE_color]
     draw_layer.set_fill_color_group(lisa_color_group)
     draw_layer.draw(dc, view)        
     
     return bmp
Example #8
0
 def drawSubLISAMap(self, idx, bufferWidth, bufferHeight,bmp):
     """
     Draw two relative LISa maps for current LISA map
     """
     dc = wx.BufferedDC(None, bmp)
     dc.SetBrush(wx.WHITE_BRUSH)
     dc.SetPen(wx.TRANSPARENT_PEN)
     dc.DrawRectangle(0,0,bufferWidth,bufferHeight)
     
     if not "Linux" in stars.APP_PLATFORM:
         # not good drawing effect using GCDC in linux
         dc = wx.GCDC(dc)
     
     view = View2ScreenTransform(
         self.extent, 
         bufferWidth, 
         bufferHeight
         ) 
     
     moran_local = self.space_moran_locals[idx]
     sigFlag     = moran_local[2]
     clusterFlag = moran_local[3]
     lm_sig      = np.array(sigFlag)
     lm_q        = np.array(clusterFlag)
     id_groups   = [[] for i in range(6)]
     # 0 not significant, 1 HH, 2 LL, 3 LH, 4 HL, 5 Neighborless
     for i,sig in enumerate(lm_sig):
         if sig > 0:
             id_groups[lm_q[i]].append(i)
         else:
             id_groups[0].append(i)
     
     from stars.visualization.maps.BaseMap import PolygonLayer
     draw_layer = PolygonLayer(self, self.layer, build_spatial_index=False)
     #edge_clr = wx.Colour(200,200,200, self.opaque)
     edge_clr = self.color_schema_dict[self.layer.name].edge_color
     draw_layer.set_edge_color(edge_clr)
     draw_layer.set_data_group(id_groups)
     draw_layer.set_fill_color_group(self.lisa_color_group)
     draw_layer.draw(dc, view)        
     
     return bmp
Example #9
0
    def drawSubGiMap(self, idx, bufferWidth, bufferHeight,bmp):
        """
        Draw two relative Gi* maps for current Gi* map
        """
        dc = wx.BufferedDC(None, bmp)
        dc.SetBrush(wx.WHITE_BRUSH)
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangle(0,0,bufferWidth,bufferHeight)

        if not "Linux" in stars.APP_PLATFORM:
            # not good drawing effect using GCDC in linux
            dc = wx.GCDC(dc)

        view = View2ScreenTransform(
            self.extent,
            bufferWidth,
            bufferHeight
            )

        p_values = self.space_gstar[idx]
        z_values = self.space_gstar_z[idx]

        not_sig = list(np.where(p_values>0.05)[0])
        sig     = set(np.where(p_values<=0.05)[0])
        hotspots = list(sig.intersection(set(np.where(z_values>=0)[0])) )
        coldspots = list(sig.intersection(set(np.where(z_values<0)[0])) )
        id_groups = [not_sig,hotspots,coldspots]

        from stars.visualization.maps.BaseMap import PolygonLayer
        draw_layer = PolygonLayer(self, self.layer, build_spatial_index=False)
        #edge_clr = wx.Colour(200,200,200, self.opaque)
        edge_clr = self.color_schema_dict[self.layer.name].edge_color
        draw_layer.set_edge_color(edge_clr)
        draw_layer.set_data_group(id_groups)
        draw_layer.set_fill_color_group(self.gi_color_group)
        draw_layer.draw(dc, view)

        return bmp
Example #10
0
 def draw3DMap(self, bmp, idx, bufferWidth, bufferHeight):
     dc = wx.BufferedDC(None, bmp)
     dc.SetBrush(wx.WHITE_BRUSH)
     dc.SetPen(wx.TRANSPARENT_PEN)
     dc.DrawRectangle(0,0,bufferWidth,bufferHeight)
     
     if not "Linux" in stars.APP_PLATFORM:
         # not good drawing effect using GCDC in linux
         dc = wx.GCDC(dc)
     
     view = View2ScreenTransform(
         self.extent, 
         bufferWidth, 
         bufferHeight
     ) 
     view.zoom_extent = self.map_query_region 
     subBmpHeight = self.bufferHeight / self.t
     ratio = bufferHeight / float(subBmpHeight)
     from stars.visualization.maps.BaseMap import PolygonLayer
     draw_layer = PolygonLayer(self, self.layer, build_spatial_index=False)
     
     p_values = self.space_gstar[idx]
     z_values = self.space_gstar_z[idx]
     
     not_sig = list(np.where(p_values>0.05)[0])
     sig     = set(np.where(p_values<=0.05)[0])
     hotspots = list(sig.intersection(set(np.where(z_values>=0)[0])) )
     coldspots = list(sig.intersection(set(np.where(z_values<0)[0])) )
     id_groups = [not_sig,hotspots,coldspots]
         
     self.id_groups = id_groups
     draw_layer.set_data_group(id_groups)
     draw_layer.set_fill_color_group(self.gi_color_group)
     draw_layer.set_edge_color(stars.DEFAULT_MAP_EDGE_COLOR)
     
     edge_clr = wx.Colour(200,200,200, self.opaque)
     draw_layer.set_edge_color(edge_clr)
     draw_layer.draw(dc, view, draw3D=ratio)
Example #11
0
class DataTablePanel(wx.Panel, AbstractCanvas,listmix.ColumnSorterMixin):
    """
    Panel displaying dbf DataTable.
    The wxPanel container for DataList (wx.ListCtrl).
    """
    def __init__(self, parent, shapefileObject, name):
        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
        
        from stars.visualization.maps.BaseMap import PolygonLayer, PointLayer, LineLayer
        
        self.layer = shapefileObject
        self.dbf = self.layer.dbf
        self.name = name
        self.parent = parent
        self.current_selected = {}  # {id: centroid}
        self.isEvtHandle = False
        
        tID = wx.NewId()
        self.table = DataListCtrl(
            self, 
            tID,
            self.dbf,
            style=wx.LC_REPORT 
            | wx.LC_VIRTUAL
            #| wx.BORDER_SUNKEN
            | wx.BORDER_NONE
            | wx.LC_EDIT_LABELS
            #| wx.LC_SORT_ASCENDING
            #| wx.LC_NO_HEADER
            | wx.LC_VRULES
            | wx.LC_HRULES
            #| wx.LC_SINGLE_SEL
        )
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.table, 1, wx.EXPAND)
       
        if self.layer.shape_type == stars.SHP_POINT:
            self.draw_layer = PointLayer(self,self.layer)
        elif self.layer.shape_type == stars.SHP_LINE:
            self.draw_layer = LineLayer(self, self.layer)
        elif self.layer.shape_type == stars.SHP_POLYGON:
            self.draw_layer = PolygonLayer(self,self.layer)  
             
        self.SetSizer(sizer)
        self.SetAutoLayout(True)
        
        # table events
        self.table.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
        self.table.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
        
        # register event_handler to THE OBSERVER
        while parent != None:
            if isinstance(parent, stars.Main):
                self.observer = parent.observer
            parent = parent.GetParent()
            
        self.Register(stars.EVT_OBJS_SELECT, self.OnRecordsSelect)
        self.Register(stars.EVT_OBJS_UNSELECT, self.OnNoRecordSelect)
        
        self.parent.Bind(wx.EVT_CLOSE, self.OnClose) # OnClose Only send to Frame/Dialog
        
    def OnClose(self, event):
        self.Unregister(stars.EVT_OBJS_SELECT, self.OnRecordsSelect)
        self.Unregister(stars.EVT_OBJS_UNSELECT, self.OnNoRecordSelect)
        event.Skip()
                
    def update_table(self, dbf):
        """
        Get and display data from dbf File on DataList (wx.ListCtrl)
        """
        self.table.ClearAll()
        self.table.SetItemCount(dbf.n_records)
        
        n_columns = len(dbf.header)
        self.table.InsertColumn(0, "ID")
        for i,item in enumerate(dbf.header):
            self.table.InsertColumn(i+1, item)
      
    def OnItemSelected(self, event):
        if self.isEvtHandle == False:
            # prevent backforce Event
            if self.table.SelectedItemCount == 1:
                self.current_selected = {}
            if not self.current_selected.has_key(event.m_itemIndex):
                dummy_region = []
                # find centroid of current_select objec
                if self.layer.shape_type == stars.SHP_POLYGON:
                    centroids = self.layer.centroids[event.m_itemIndex]
                    for centroid in centroids:
                        dummy_region += centroid + centroid
                else:
                    point = list(self.layer.shape_objects[event.m_itemIndex])
                    dummy_region = point + point
                    
                self.current_selected[event.m_itemIndex] = dummy_region
                
                # trigger Upadte Event to notify other
                # widgets to drawing the selected items
                self.OnRecordsSelect(None)
        event.Skip()
     
    def OnItemDeselected(self, event):
        if self.isEvtHandle == False:
            # prevent backforce Event
            if self.current_selected.has_key(event.m_itemIndex):
                self.current_selected.pop(event.m_itemIndex)
                # trigger Upadte Event to notify other
                # widgets to drawing the selected items
                self.OnRecordsSelect(None)
        event.Skip()
       
    def unhighlight_selected(self):
        for item in self.current_selected:            
            self.table.SetItemState(item, 0, wx.LIST_STATE_SELECTED)# | wx.LIST_STATE_FOCUSED) 
            
    def highlight_selected(self):
        if len(self.current_selected) > 0:
            first = self.current_selected.keys()[0]
            for item in self.current_selected:
                if item == first:
                    self.table.EnsureVisible(item)
                self.table.SetItemState(item, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED)#|wx.LIST_STATE_FOCUSED) 
        
        
    #------------------------------
    # Belows are Event handlers
    #------------------------------
    def OnRecordsSelect(self, event):
        if event == None:
            # trigger other widgets
            data = AbstractData(self)
            data.shape_ids[self.name] =  self.current_selected.keys()
            data.boundary = self.current_selected.values()
            self.UpdateEvt(stars.EVT_OBJS_SELECT, data)
        else:
            # trigged by other widgets
            self.isEvtHandle = True
            data = event.data
            if data.shape_ids.has_key(self.name):
                # unselect first
                self.unhighlight_selected()
                # then select trigged
                selected_id_list = data.shape_ids[self.name]
                self.current_selected = {}
                for i in selected_id_list:
                    self.current_selected[i] = None
                self.highlight_selected()
            else:
                # unselect first
                self.unhighlight_selected()
                self.current_selected = {}
                # try to test if query regions can be used
                # to find shape ids
                query_regions = data.boundary
                if query_regions == None or len(query_regions) == 0:
                    pass
                else:
                    if isinstance(query_regions[0], float):
                        query_regions = [query_regions]
                    for region in query_regions:
                        shape_ids, query_region = self.draw_layer.get_selected_by_region(None, region)
                        for id in shape_ids:
                            self.current_selected[id] = None
                    self.highlight_selected()
            self.isEvtHandle = False
    
    def OnNoRecordSelect(self, event):
        self.isEvtHandle = True
        for item in self.current_selected:            
            self.table.SetItemState(item, 0, wx.LIST_STATE_SELECTED)# | wx.LIST_STATE_FOCUSED) 
        self.isEvtHandle = False
Example #12
0
    def draw3DMap(self, bmp, idx, bufferWidth, bufferHeight):
        dc = wx.BufferedDC(None, bmp)
        dc.SetBrush(wx.WHITE_BRUSH)
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangle(0, 0, bufferWidth, bufferHeight)

        if not "Linux" in stars.APP_PLATFORM:
            # not good drawing effect using GCDC in linux
            dc = wx.GCDC(dc)

        view = View2ScreenTransform(self.extent, bufferWidth, bufferHeight)
        view.zoom_extent = self.map_query_region
        subBmpHeight = self.bufferHeight / self.t
        ratio = bufferHeight / float(subBmpHeight)
        from stars.visualization.maps.BaseMap import PolygonLayer
        draw_layer = PolygonLayer(self, self.layer, build_spatial_index=False)

        p_values = self.space_gstar[idx]
        z_values = self.space_gstar_z[idx]

        not_sig = list(np.where(p_values > 0.05)[0])
        sig = set(np.where(p_values <= 0.05)[0])
        hotspots = list(sig.intersection(set(np.where(z_values >= 0)[0])))
        coldspots = list(sig.intersection(set(np.where(z_values < 0)[0])))
        id_groups = [not_sig, hotspots, coldspots]

        self.id_groups = id_groups
        draw_layer.set_data_group(id_groups)
        draw_layer.set_fill_color_group(self.gi_color_group)
        draw_layer.set_edge_color(stars.DEFAULT_MAP_EDGE_COLOR)

        edge_clr = wx.Colour(200, 200, 200, self.opaque)
        draw_layer.set_edge_color(edge_clr)
        draw_layer.draw(dc, view, draw3D=ratio)
Example #13
0
class DataTablePanel(wx.Panel, AbstractCanvas, listmix.ColumnSorterMixin):
    """
    Panel displaying dbf DataTable.
    The wxPanel container for DataList (wx.ListCtrl).
    """
    def __init__(self, parent, shapefileObject, name):
        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)

        from stars.visualization.maps.BaseMap import PolygonLayer, PointLayer, LineLayer

        self.layer = shapefileObject
        self.dbf = self.layer.dbf
        self.name = name
        self.parent = parent
        self.current_selected = {}  # {id: centroid}
        self.isEvtHandle = False

        tID = wx.NewId()
        self.table = DataListCtrl(
            self,
            tID,
            self.dbf,
            style=wx.LC_REPORT
            | wx.LC_VIRTUAL
            #| wx.BORDER_SUNKEN
            | wx.BORDER_NONE
            | wx.LC_EDIT_LABELS
            #| wx.LC_SORT_ASCENDING
            #| wx.LC_NO_HEADER
            | wx.LC_VRULES
            | wx.LC_HRULES
            #| wx.LC_SINGLE_SEL
        )

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.table, 1, wx.EXPAND)

        if self.layer.shape_type == stars.SHP_POINT:
            self.draw_layer = PointLayer(self, self.layer)
        elif self.layer.shape_type == stars.SHP_LINE:
            self.draw_layer = LineLayer(self, self.layer)
        elif self.layer.shape_type == stars.SHP_POLYGON:
            self.draw_layer = PolygonLayer(self, self.layer)

        self.SetSizer(sizer)
        self.SetAutoLayout(True)

        # table events
        self.table.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
        self.table.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)

        # register event_handler to THE OBSERVER
        while parent != None:
            if isinstance(parent, stars.Main):
                self.observer = parent.observer
            parent = parent.GetParent()

        self.Register(stars.EVT_OBJS_SELECT, self.OnRecordsSelect)
        self.Register(stars.EVT_OBJS_UNSELECT, self.OnNoRecordSelect)

        self.parent.Bind(wx.EVT_CLOSE,
                         self.OnClose)  # OnClose Only send to Frame/Dialog

    def OnClose(self, event):
        self.Unregister(stars.EVT_OBJS_SELECT, self.OnRecordsSelect)
        self.Unregister(stars.EVT_OBJS_UNSELECT, self.OnNoRecordSelect)
        event.Skip()

    def update_table(self, dbf):
        """
        Get and display data from dbf File on DataList (wx.ListCtrl)
        """
        self.table.ClearAll()
        self.table.SetItemCount(dbf.n_records)

        n_columns = len(dbf.header)
        self.table.InsertColumn(0, "ID")
        for i, item in enumerate(dbf.header):
            self.table.InsertColumn(i + 1, item)

    def OnItemSelected(self, event):
        if self.isEvtHandle == False:
            # prevent backforce Event
            if self.table.SelectedItemCount == 1:
                self.current_selected = {}
            if not self.current_selected.has_key(event.m_itemIndex):
                dummy_region = []
                # find centroid of current_select objec
                if self.layer.shape_type == stars.SHP_POLYGON:
                    centroids = self.layer.centroids[event.m_itemIndex]
                    for centroid in centroids:
                        dummy_region += centroid + centroid
                else:
                    point = list(self.layer.shape_objects[event.m_itemIndex])
                    dummy_region = point + point

                self.current_selected[event.m_itemIndex] = dummy_region

                # trigger Upadte Event to notify other
                # widgets to drawing the selected items
                self.OnRecordsSelect(None)
        event.Skip()

    def OnItemDeselected(self, event):
        if self.isEvtHandle == False:
            # prevent backforce Event
            if self.current_selected.has_key(event.m_itemIndex):
                self.current_selected.pop(event.m_itemIndex)
                # trigger Upadte Event to notify other
                # widgets to drawing the selected items
                self.OnRecordsSelect(None)
        event.Skip()

    def unhighlight_selected(self):
        for item in self.current_selected:
            self.table.SetItemState(
                item, 0, wx.LIST_STATE_SELECTED)  # | wx.LIST_STATE_FOCUSED)

    def highlight_selected(self):
        if len(self.current_selected) > 0:
            first = self.current_selected.keys()[0]
            for item in self.current_selected:
                if item == first:
                    self.table.EnsureVisible(item)
                self.table.SetItemState(
                    item, wx.LIST_STATE_SELECTED,
                    wx.LIST_STATE_SELECTED)  #|wx.LIST_STATE_FOCUSED)

    #------------------------------
    # Belows are Event handlers
    #------------------------------
    def OnRecordsSelect(self, event):
        if event == None:
            # trigger other widgets
            data = AbstractData(self)
            data.shape_ids[self.name] = self.current_selected.keys()
            data.boundary = self.current_selected.values()
            self.UpdateEvt(stars.EVT_OBJS_SELECT, data)
        else:
            # trigged by other widgets
            self.isEvtHandle = True
            data = event.data
            if data.shape_ids.has_key(self.name):
                # unselect first
                self.unhighlight_selected()
                # then select trigged
                selected_id_list = data.shape_ids[self.name]
                self.current_selected = {}
                for i in selected_id_list:
                    self.current_selected[i] = None
                self.highlight_selected()
            else:
                # unselect first
                self.unhighlight_selected()
                self.current_selected = {}
                # try to test if query regions can be used
                # to find shape ids
                query_regions = data.boundary
                if query_regions == None or len(query_regions) == 0:
                    pass
                else:
                    if isinstance(query_regions[0], float):
                        query_regions = [query_regions]
                    for region in query_regions:
                        shape_ids, query_region = self.draw_layer.get_selected_by_region(
                            None, region)
                        for id in shape_ids:
                            self.current_selected[id] = None
                    self.highlight_selected()
            self.isEvtHandle = False

    def OnNoRecordSelect(self, event):
        self.isEvtHandle = True
        for item in self.current_selected:
            self.table.SetItemState(
                item, 0, wx.LIST_STATE_SELECTED)  # | wx.LIST_STATE_FOCUSED)
        self.isEvtHandle = False