Exemplo n.º 1
0
    def Draw(self, fig=None, ax=None, m=None):
        # ================================

        if fig == None:
            fig = plt.figure()

        if ax == None:
            ax = fig.add_subplot(111)
            ax.set_xlabel('Longitude')
            ax.set_ylabel('Latitude')

        if m == None:
            for i in range(self.n):
                plot.plot(self.lon[i],self.lat[i],                       \
                        linestyle='',                                  \
                        marker=marker_string(self.PLOT.SYMBOL.get()),  \
                        ms=self.PLOT.SIZE.get(),                       \
                        visible=self.PLOT.SHOW.get(),                  \
                        label=self.PLOT.LABEL.get(),                   \
                        alpha=self.PLOT.ALPHA.get(),                   \
                        color=self.PLOT.COLOR.get())
        else:
            for i in range(self.n):
                m.plot(self.lon[i],self.lat[i],                       \
                        linestyle='',                                  \
                        marker=marker_string(self.PLOT.SYMBOL.get()),  \
                        ms=self.PLOT.SIZE.get(),                       \
                        visible=self.PLOT.SHOW.get(),                  \
                        label=self.PLOT.LABEL.get(),                   \
                        alpha=self.PLOT.ALPHA.get(),                   \
                        color=self.PLOT.COLOR.get())

        ax.legend()
        plt.show()
Exemplo n.º 2
0
def drawing(fig, ax, m, MARKER):
    # ======================================
    ''' Draw a 2D vector plot. Option of vectors or stream function'''

    __version__ = "1.0"
    __author__ = "Quim Ballabrerera"
    __date__ = "May 2018"

    west = m.__dict__['xmin']
    east = m.__dict__['xmax']
    south = m.__dict__['ymin']
    north = m.__dict__['ymax']
    #west,east = ax.get_xlim()
    #south,north = ax.get_ylim()
    xv = []
    yv = []
    lv = []
    for i in range(MARKER.n):
        xx, yy = m(MARKER.lon[i], MARKER.lat[i])
        if xx > west and xx < east and \
           yy > south and yy < north:
            xv.append(xx)
            yv.append(yy)
            lv.append(MARKER.label[i])
    nn = len(xv)

    if nn > 0:
        if MARKER.textmode.get():
            # Here, every marker is identified by its label
            for i in range(nn):
                ax.text(
                    xv[i],
                    yv[i],
                    lv[i],
                    ha=MARKER.PLOT.HA.get(),
                    va=MARKER.PLOT.VA.get(),
                    wrap=MARKER.PLOT.WRAP.get(),
                    style=MARKER.PLOT.STYLE.get(),
                    weight=MARKER.PLOT.WEIGHT.get(),
                    color=MARKER.PLOT.TCOLOR.get(),
                    size=MARKER.PLOT.TSIZE.get(),
                    zorder=MARKER.PLOT.ZORDER.get(),
                )
                m.plot(
                    xv[i],
                    yv[i],
                    linestyle='',
                    marker=marker_string(MARKER.PLOT.SYMBOL.get()),
                    ms=MARKER.PLOT.SIZE.get(),
                    alpha=MARKER.PLOT.ALPHA.get(),
                    color=MARKER.PLOT.COLOR.get(),
                    zorder=MARKER.PLOT.ZORDER.get(),
                )

        else:
            m.plot(
                xv,
                yv,
                linestyle='',
                marker=marker_string(MARKER.PLOT.SYMBOL.get()),
                ms=MARKER.PLOT.SIZE.get(),
                visible=MARKER.PLOT.SHOW.get(),
                label=MARKER.LABEL.get(),
                alpha=MARKER.PLOT.ALPHA.get(),
                color=MARKER.PLOT.COLOR.get(),
                zorder=MARKER.PLOT.ZORDER.get(),
            )
Exemplo n.º 3
0
def drawing(ax,proj,MARKER):
# ======================================
  ''' Draw a 2D vector plot. Option of vectors or stream function'''

  __version__ = "1.0"
  __author__  = "Quim Ballabrerera"
  __date__    = "May 2018"

  if not MARKER.show.get():
    return

  west, east, south, north = ax.get_extent()
  
  xv = []
  yv = []
  lv = []
  for i in range(MARKER.n):
    if MARKER.lon[i] > west and MARKER.lon[i] < east and \
       MARKER.lat[i] > south and MARKER.lat[i] < north:
      xv.append(MARKER.lon[i])
      yv.append(MARKER.lat[i])
      lv.append(MARKER.label[i])
  nn = len(xv)
  
  lmrk = None

  xpad = MARKER.PLOT.XPAD.get()
  ypad = MARKER.PLOT.YPAD.get()

  if nn > 0:
    if MARKER.textmode.get():
      # Here, every marker is identified by its label
      for i in range(nn):
        ax.text(xpad+xv[i],ypad+yv[i],lv[i],
                 ha=MARKER.PLOT.HA.get(),
                 va=MARKER.PLOT.VA.get(),
                 wrap=MARKER.PLOT.WRAP.get(),
                 style=MARKER.PLOT.STYLE.get(),
                 weight=MARKER.PLOT.WEIGHT.get(),
                 color=MARKER.PLOT.TCOLOR.get(),
                 size=MARKER.PLOT.TSIZE.get(),
                 zorder=MARKER.PLOT.ZORDER.get(),
                 rotation=MARKER.PLOT.ANGLE.get(),
                 transform=ccrs.PlateCarree())
                 #transform=proj)
 
        if MARKER.PLOT.SHOW.get():
          lines = []
          labels = []
          lmrk, = ax.plot(xv[i],yv[i],linestyle='',
                  marker=marker_string(MARKER.PLOT.SYMBOL.get()),
                  ms=MARKER.PLOT.SIZE.get(),
                  label=MARKER.LABEL.get(),
                  alpha=MARKER.PLOT.ALPHA.get(),
                  color=MARKER.PLOT.COLOR.get(),
                  zorder=MARKER.PLOT.ZORDER.get(),
                  transform=ccrs.PlateCarree())
                  #transform=proj)
#          lines.append(lmrk)
#          legend = ax.legend(lines,['toto'])
                
    else:
      if MARKER.PLOT.SHOW.get():
        lmrk, = ax.plot(xv,yv,linestyle='',
                marker=marker_string(MARKER.PLOT.SYMBOL.get()),
                ms=MARKER.PLOT.SIZE.get(),
                visible=MARKER.PLOT.SHOW.get(),
                label=MARKER.LABEL.get(),
                alpha=MARKER.PLOT.ALPHA.get(),
                color=MARKER.PLOT.COLOR.get(),
                zorder=MARKER.PLOT.ZORDER.get(),
                transform=ccrs.PlateCarree())
                #transform=proj)

  return lmrk
Exemplo n.º 4
0
def drawing(ax,proj,SHAPE):
# ======================================
  '''Draw geometries from shapes files'''

  __version__ = "2.0"
  __author__  = "Emili Garcia, based on Joaquin Ballabrera geomarker.py"
  __date__    = "December 2020"

  if not SHAPE.show.get():
    return

  # Axis lims
  xmin, xmax = ax.get_xlim()
  ymin, ymax = ax.get_ylim()
  # Transform to lon,lat:
  xmin, ymin = ccrs.PlateCarree().transform_point(xmin,ymin,ax.projection)
  xmax, ymax = ccrs.PlateCarree().transform_point(xmax,ymax,ax.projection)

  xpad = SHAPE.PLOT.XPAD.get()
  ypad = SHAPE.PLOT.YPAD.get()

  # BBOX:
  if SHAPE.PLOT.BBOX.get():
    bbox = dict(facecolor=SHAPE.PLOT.BBOX_FACECOLOR.get(),
                alpha=SHAPE.PLOT.BBOX_ALPHA.get())
  else:
    bbox = None

  lshp = None

  # - - - - - - - - - - - - -
  if 'POINT' in SHAPE.type:
  # - - - - - - - - - - - - -

    for i in range(SHAPE.n):
      point = SHAPE.record[i]
      x = point.geometry.x
      y = point.geometry.y

      try:
        label = point.attributes[SHAPE.LABEL_KEY.get()]
        if label.upper() in SHAPE.namestohide:
          plotit = False     # Label in names to hide list
        else:
          plotit = True      # Label not in names to hide list
      except:
        label  = None
        plotit = True


      if x <= xmin or x>= xmax:
        plotit = False
      if y <= ymin or y>= ymax:
        plotit = False

      if plotit:
       
        lshp, = ax.plot(x,y,             \
                  linestyle='',                                   \
                  marker=marker_string(SHAPE.PLOT.SYMBOL.get()),  \
                  ms=SHAPE.PLOT.SIZE.get(),                       \
                  label=SHAPE.LABEL.get(),                        \
                  color=SHAPE.PLOT.COLOR.get(),                   \
                  alpha=SHAPE.PLOT.ALPHA.get(),                   \
                  zorder=SHAPE.PLOT.ZORDER.get(),
                  transform=ccrs.PlateCarree())

        if SHAPE.textmode.get():
          # Here, every marker is identified by its label
          ax.text(xpad+x,ypad+y,label,
                 ha=SHAPE.PLOT.HA.get(),
                 va=SHAPE.PLOT.VA.get(),
                 wrap=SHAPE.PLOT.WRAP.get(),
                 style=SHAPE.PLOT.STYLE.get(),
                 weight=SHAPE.PLOT.WEIGHT.get(),
                 color=SHAPE.PLOT.TCOLOR.get(),
                 size=SHAPE.PLOT.TSIZE.get(),
                 zorder=SHAPE.PLOT.ZORDER.get()+1,
                 rotation=SHAPE.PLOT.ANGLE.get(),
                 bbox=bbox,
                 transform=ccrs.PlateCarree())


  # - - - - - - - - - - - - -
  elif 'LINE' in SHAPE.type:
  # - - - - - - - - - - - - -

    for record in SHAPE.record:

      # Get label and check if has been asked not to be shown
      #
      try:
        label = record.attributes[SHAPE.LABEL_KEY.get()]
        if label.upper() in SHAPE.namestohide:
          plotit = False     # Label in names to hide list
        else:
          plotit = True      # Label not in names to hide list
      except:
        label  = None
        plotit = True


      if plotit:
        for line in record.geometry:
          x,y = line.xy
          lshp, = ax.plot(x,y,
                          linewidth=SHAPE.PLOT.LINEWIDTH.get(),
                          linestyle=SHAPE.PLOT.LINESTYLE.get(),
                          alpha=SHAPE.PLOT.ALPHA.get(),
                          color=SHAPE.PLOT.EDGECOLOR.get(),
                          zorder=SHAPE.PLOT.ZORDER.get(),
                          transform=ccrs.PlateCarree())

        if SHAPE.textmode.get():
          # Here, every marker is identified by its label

          # Get the center of the longest segment
          #
          lmax = 0
          for line in record.geometry:
            x,y = line.xy
            if len(x) > lmax:
              lmax = len(x)
              xmean = np.mean(x)
              ymean = np.mean(y)

          # Place the text
          #
          ax.text(xpad+xmean,ypad+ymean,label,
                  ha=SHAPE.PLOT.HA.get(),
                  va=SHAPE.PLOT.VA.get(),
                  wrap=SHAPE.PLOT.WRAP.get(),
                  style=SHAPE.PLOT.STYLE.get(),
                  weight=SHAPE.PLOT.WEIGHT.get(),
                  color=SHAPE.PLOT.TCOLOR.get(),
                  size=SHAPE.PLOT.TSIZE.get(),
                  zorder=SHAPE.PLOT.ZORDER.get()+1,
                  rotation=SHAPE.PLOT.ANGLE.get(),
                  bbox=bbox,
                  transform=ccrs.PlateCarree())


  # - - - - - - - - - - - - -
  else:
  # - - - - - - - - - - - - -
    # Geometries other than POINT or LINESTRINGS:
    #
    for record in SHAPE.record:

      # Get label and check if has been asked not to be shown
      #
      try:
        label = record.attributes[SHAPE.LABEL_KEY.get()]
        if label.upper() in SHAPE.namestohide:
          plotit = False     # Label in names to hide list
        else:
          plotit = True      # Label not in names to hide list
      except:
        label  = None
        plotit = True

      if plotit:
        if SHAPE.PLOT.FILLED.get():
          shape_feature = ShapelyFeature(record.geometry,ccrs.PlateCarree())
          ax.add_feature(shape_feature, 
                         linewidth=SHAPE.PLOT.LINEWIDTH.get(),
                         linestyle=SHAPE.PLOT.LINESTYLE.get(),
                         alpha=SHAPE.PLOT.ALPHA.get(),
                         edgecolor=SHAPE.PLOT.EDGECOLOR.get(),
                         facecolor=SHAPE.PLOT.FACECOLOR.get(),
                         zorder=SHAPE.PLOT.ZORDER.get())
        else:
          try:
            for element in record.geometry:
              x,y = element.exterior.coords.xy
              lshp, = ax.plot(x,y,
                            linewidth=SHAPE.PLOT.LINEWIDTH.get(),
                            linestyle=SHAPE.PLOT.LINESTYLE.get(),
                            alpha=SHAPE.PLOT.ALPHA.get(),
                            color=SHAPE.PLOT.EDGECOLOR.get(),
                            zorder=SHAPE.PLOT.ZORDER.get(),
                            transform=ccrs.PlateCarree())
          except:
              x,y = record.geometry.exterior.coords.xy
              lshp, = ax.plot(x,y,
                            linewidth=SHAPE.PLOT.LINEWIDTH.get(),
                            linestyle=SHAPE.PLOT.LINESTYLE.get(),
                            alpha=SHAPE.PLOT.ALPHA.get(),
                            color=SHAPE.PLOT.EDGECOLOR.get(),
                            zorder=SHAPE.PLOT.ZORDER.get(),
                            transform=ccrs.PlateCarree())
        if SHAPE.textmode.get():
          # label variable holds the name of the feature
          # We will label the largest feature
          amax = 0
          imax = -1
          for i  in range(len(record.geometry)):
            element = record.geometry[i]
            area = element.area
            if area > amax:
              amax = area
              imax = i

          # Now label at the center of the larger area:
          #
          geom = record.geometry[imax]
          xx = geom.centroid.x
          yy = geom.centroid.y
          ss = ax.text(xpad+xx,ypad+yy,label,
                  ha=SHAPE.PLOT.HA.get(),
                  va=SHAPE.PLOT.VA.get(),
                  wrap=SHAPE.PLOT.WRAP.get(),
                  style=SHAPE.PLOT.STYLE.get(),
                  weight=SHAPE.PLOT.WEIGHT.get(),
                  color=SHAPE.PLOT.TCOLOR.get(),
                  size=SHAPE.PLOT.TSIZE.get(),
                  zorder=SHAPE.PLOT.ZORDER.get()+1,
                  rotation=SHAPE.PLOT.ANGLE.get(),
                  bbox=bbox,
                  transform=ccrs.PlateCarree())

  return lshp