Example #1
0
    def test_bbox(self):
        srs = SpatialReference()
        srs.ImportFromEPSG(27700)  # British national grid
        uk_area = core.boundary_from_envelope(core.Envelope(0, 700000, 1300000, 0, srs))
        self.assertTrue(uk_area.contains_point(1, 1))
        self.assertTrue(uk_area.contains_point(690000, 1200000))
        self.assertTrue(uk_area.contains_point(10000, 10000))

        latlng_srs = SpatialReference()
        latlng_srs.ImportFromEPSG(4326)  # WGS 84 lat/lng
        uk_latlng = uk_area.transform_to(latlng_srs, 1000, 1.0)
        self.assertTrue(uk_latlng.contains_point(-1.826189, 51.178844))  # Stonehenge
        self.assertTrue(uk_latlng.contains_point(-3.07, 58.64))  # John o'Groats
        self.assertTrue(uk_latlng.contains_point(-5.716111, 50.068611))  # Land's End
        self.assertTrue(uk_latlng.contains_point(-4.333333, 53.283333))  # Anglesey
        self.assertTrue(not uk_latlng.contains_point(-8.47, 51.897222))  # Cork
        self.assertTrue(not uk_latlng.contains_point(2.3508, 48.8567))  # Paris
Example #2
0
    def render_callable(self, context, spatial_reference=None):
        if self.geom is None:
            return lambda: None

        if not self.stroke and not self.fill:
            return lambda: None

        minx, miny, maxx, maxy = context.clip_extents()

        skirt = 0

        if self.stroke:
            skirt += context.get_line_width()

        scale = max([abs(x) for x in context.device_to_user_distance(1,1)])
        skirt += self.marker_radius * scale

        boundary = boundary_from_envelope(Envelope(minx-skirt, maxx+skirt, maxy+skirt, miny-skirt, spatial_reference))

        geometry = self.geom.within(boundary, spatial_reference)

        def f():
            for g in geometry:
                if g.geom_type == 'Point':
                    self._render_point(g, context)
                elif g.geom_type == 'MultiPoint':
                    [self._render_point(x, context) for x in g]
                elif g.geom_type == 'LineString':
                    self._render_line_string(g, context)
                elif g.geom_type == 'MultiLineString':
                    [self._render_line_string(x, context) for x in g]
                elif g.geom_type == 'LinearRing':
                    self._render_line_string(g, context, close_path=True)
                elif g.geom_type == 'Polygon':
                    self._render_polygon(g, context)
                elif g.geom_type == 'MultiPolygon':
                    [self._render_polygon(x, context) for x in g]
                else:
                    log.warning('Unknown geometry type: ' + str(g.geom_type))

        return f