예제 #1
0
def polygon_layer(points, polygon_maker, layer_title):
  """ Return a KML Folder containing polygons for the given points.
    points: a list of point objects
    polygon_maker: Callback used to create a polygon from a point object.
        Args: layer_title, point, max_num_responses.
    layer_title: Title to use for the layer.
    returns: KML Folder containing polygons.
  """
  elements = []
  styles = []
  max_num_responses = max(x.count for x in points)
  for point in points:
    if point.count > 0:
      p = polygon_maker(layer_title, point, max_num_responses)
      styles.append(p.style)
      elements.append(p)
  return kml.Folder('%s (polygons)' % layer_title, styles, elements)

  dx = (rect.right - rect.left)/width
  dy = (rect.top - rect.bottom)/height
  image = create_image(points, boolean_data.make_boolean_pixel, width, height)
  image.save(filename)
  return kml.GroundOverlay('%s (%s overlay)' % (layer_title, res), '',
      filename, 1,
      geo.Rect(rect.top+dy, rect.right, rect.bottom+dy, rect.left))
예제 #2
0
 def testGridDiscardsPointsOutsideArea(self):
     points = self.makePoints(
         (0, 0),  # The only point inside the area.
         (-10, 0),
         (10, 0),
         (0, -10),
         (0, 10))
     grid = geo.grid(geo.Rect(1, 1, -1, -1), 1, 1, points)
     self.assertEqual([[points[0]]], grid)
예제 #3
0
 def __init__(self):
     pygame.init()
     self.running = True
     self.size = App.WINDOW_SIZE
     self.surface = pygame.display.set_mode(self.size, pygame.RESIZABLE)
     self.text = geo.RenderText('Hello World!')
     self.rect = geo.Rect((10, 10), (20, 20), Color.RED)
     imp.IMP().register(self.text)
     imp.IMP().register(self.rect)
     imp.IMP().event_dispatcher = events.EventDispatcher()
     self.wire_events()
예제 #4
0
 def testAggregateGridSimple(self):
     points = self.makePoints((0, 0), (0, 1), (1, 0), (1, 1))
     grid = geo.aggregate_grid(geo.Rect(2, 2, 0, 0), 2, 2, points)
     self.assertEqual(4, len(grid))
     self.assertEqual(1, len(grid[0]))
     self.assertEqual(1, len(grid[1]))
     self.assertEqual(1, len(grid[2]))
     self.assertEqual(1, len(grid[3]))
     self.assertEqual(points[0], grid[0][0])
     self.assertEqual(points[1], grid[1][0])
     self.assertEqual(points[2], grid[2][0])
     self.assertEqual(points[3], grid[3][0])
예제 #5
0
def heatmap_layer(rect, width, height, points, layer_title, res):
  """Return a KML GroundOverlay for the given points.  Currently saves the
  image under a random filename in the current directory.
  """
  # TODO(mivey): Find a better place to save, use mktemp to get a better name.
  filename = ''.join(random.choice(string.lowercase) for x in range(10))
  filename += '.png'
  dx = (rect.right - rect.left)/width
  dy = (rect.top - rect.bottom)/height
  image = create_image(points, boolean_data.make_boolean_pixel, width, height)
  image.save(filename)
  return kml.GroundOverlay('%s (%s overlay)' % (layer_title, res), '',
      filename, 1,
      geo.Rect(rect.top+dy, rect.right, rect.bottom+dy, rect.left))
예제 #6
0
    def testGridComplex(self):
        top_left = self.makePoints((0, 0), (0, 1), (1, 0), (1, 1), (2, 0),
                                   (2, 1))
        top_middle = self.makePoints((0, 2), (0, 3), (1, 2), (1, 3), (2, 2),
                                     (2, 3))
        top_right = self.makePoints((0, 4), (0, 5), (1, 4), (1, 5), (2, 4),
                                    (2, 5))
        bottom_left = self.makePoints((3, 0), (3, 1), (4, 0), (4, 1), (5, 0),
                                      (5, 1))
        bottom_middle = self.makePoints((3, 2), (3, 3), (4, 2), (4, 3), (5, 2),
                                        (5, 3))
        bottom_right = self.makePoints((3, 4), (3, 5), (4, 4), (4, 5), (5, 4),
                                       (5, 5))

        points = (top_left + top_middle + top_right + bottom_left +
                  bottom_middle + bottom_right)
        grid = geo.grid(geo.Rect(6, 6, 0, 0), 2, 3, points)

        self.assertEqual([
            top_left, top_middle, top_right, bottom_left, bottom_middle,
            bottom_right
        ], grid)
예제 #7
0
 def register_objs(self):
     self.text = geo.RenderText('Hello World!').center_on(
         tuple(x // 2 for x in self.size))
     self.rect = geo.Rect(tuple(x // 4 for x in self.size), (20, 20),
                          Color.RED)
     self.imp.register([self.text, self.rect])
예제 #8
0
 def testGridSimple(self):
     points = self.makePoints((0, 0), (0, 1), (1, 0), (1, 1))
     grid = geo.grid(geo.Rect(2, 2, 0, 0), 2, 2, points)
     self.assertEqual([[points[0]], [points[1]], [points[2]], [points[3]]],
                      grid)