コード例 #1
0
 def test_bbox_split_srid_2154_no_cycle(self):
     bbox = bbox_split_srid_2154(self.bbox, by_x=2, by_y=2, cycle=False)
     polygon_1 = Polygon.from_bbox(next(bbox))
     polygon_2 = Polygon.from_bbox(next(bbox))
     polygon_3 = Polygon.from_bbox(next(bbox))
     polygon_4 = Polygon.from_bbox(next(bbox))
     self.assertEqual(
         polygon_1,
         "POLYGON ((200000 300000, 200000 750000, 650000 750000, 650000 300000, 200000 300000))"
     )
     self.assertEqual(
         polygon_2,
         "POLYGON ((200000 750000, 200000 1200000, 650000 1200000, 650000 750000, 200000 750000))"
     )
     self.assertEqual(
         polygon_3,
         "POLYGON ((650000 300000, 650000 750000, 1100000 750000, 1100000 300000, 650000 300000))"
     )
     self.assertEqual(
         polygon_4,
         "POLYGON ((650000 750000, 650000 1200000, 1100000 1200000, 1100000 750000, 650000 750000))"
     )
     with self.assertRaises(StopIteration):
         Polygon.from_bbox(next(bbox))
コード例 #2
0
 def test_bbox_split_srid_2154_cycle(self):
     bbox = bbox_split_srid_2154(self.bbox, by_x=2, by_y=2, cycle=True)
     polygon_1 = Polygon.from_bbox(next(bbox))
     polygon_2 = Polygon.from_bbox(next(bbox))
     polygon_3 = Polygon.from_bbox(next(bbox))
     polygon_4 = Polygon.from_bbox(next(bbox))
     self.assertEqual(
         polygon_1,
         "POLYGON ((200000 300000, 200000 750000, 650000 750000, 650000 300000, 200000 300000))"
     )
     self.assertEqual(
         polygon_2,
         "POLYGON ((200000 750000, 200000 1200000, 650000 1200000, 650000 750000, 200000 750000))"
     )
     self.assertEqual(
         polygon_3,
         "POLYGON ((650000 300000, 650000 750000, 1100000 750000, 1100000 300000, 650000 300000))"
     )
     self.assertEqual(
         polygon_4,
         "POLYGON ((650000 750000, 650000 1200000, 1100000 1200000, 1100000 750000, 650000 750000))"
     )
     polygon_5 = Polygon.from_bbox(next(bbox))
     self.assertEqual(polygon_1, polygon_5)
コード例 #3
0
# -*- coding: utf-8 -*-
import factory

from django.conf import settings
from django.contrib.gis.geos import Polygon, MultiPolygon

from mapentity.helpers import bbox_split_srid_2154

from geotrek.core.factories import TopologyFactory

from . import models


# Create 16 cities and 4 districts distinct same-area zone covering the spatial_extent and cycle on it
geom_city_iter = bbox_split_srid_2154(settings.SPATIAL_EXTENT, by_x=4, by_y=4, cycle=True)
geom_district_iter = bbox_split_srid_2154(settings.SPATIAL_EXTENT, by_x=2, by_y=2, cycle=True)
geom_area_iter = bbox_split_srid_2154(settings.SPATIAL_EXTENT, by_x=2, by_y=2, cycle=True)


class CityFactory(factory.Factory):
    FACTORY_FOR = models.City

    code = factory.Sequence(lambda n: u"#%s" % n)  # id (!) with max_length=6
    name = factory.Sequence(lambda n: u"City name %s" % n)
    geom = factory.Sequence(lambda _: MultiPolygon(Polygon.from_bbox(geom_city_iter.next()), srid=settings.SRID))


class DistrictFactory(factory.Factory):
    FACTORY_FOR = models.District

    name = factory.Sequence(lambda n: u"District name %s" % n)