def add_huge_project(self): project = Project.objects.get(slug='london-2') content_type = ContentType.objects.get(app_label='spatial', model='spatialunit') attr_type = AttributeType.objects.get(name="text") sch = Schema.objects.create(content_type=content_type, selectors=(project.organization.pk, project.pk)) Attribute.objects.create(schema=sch, name='name', long_name='Name', required=False, index=1, attr_type=attr_type) spatial_units = [] for i in range(0, 4000): row = i // 63 col = i - (row * 63) north_west = [11.67 + (col * 0.025), 50.88 + (row * 0.025)] south_east = [ 11.67 + ((col + 1) * 0.025), 50.88 + ((row + 1) * 0.025) ] geometry = { 'type': 'Polygon', 'coordinates': [[ north_west, [north_west[0], south_east[1]], south_east, [south_east[0], north_west[1]], north_west ]] } name = 'Spatial Unit #{}'.format(i) type = random.choice([c[0] for c in TYPE_CHOICES]) spatial_units.append({ 'geometry': GEOSGeometry(json.dumps(geometry)), 'type': type, 'project': project, 'attributes': { 'name': name } }) SpatialUnitFactory.create_from_kwargs(spatial_units)
def add_huge_project(self, max_num_records=4000): project = models.Project.objects.get(slug='london-2') content_type = ContentType.objects.get(app_label='spatial', model='spatialunit') attr_type = AttributeType.objects.get(name="text") sch = Schema.objects.create(content_type=content_type, selectors=(project.organization.pk, project.pk)) Attribute.objects.create(schema=sch, name='name', long_name='Name', required=False, index=1, attr_type=attr_type) spatial_units = [] choices = [c[0] for c in TYPE_CHOICES] with open(os.path.join(os.path.dirname(__file__), "londondata.txt"), "r") as ins: for geometry in ins: if not geometry.rstrip() or geometry.startswith('#'): continue num_records = len(spatial_units) if not num_records < max_num_records: break name = 'Spatial Unit #{}'.format(num_records) type = random.choice(choices) spatial_units.append({ 'geometry': GEOSGeometry(geometry), 'type': type, 'project': project, 'attributes': { 'name': name } }) SpatialUnitFactory.create_from_kwargs(spatial_units)
def add_huge_project(self, max_num_records=4000): project = models.Project.objects.get(slug='london-2') content_type = ContentType.objects.get( app_label='spatial', model='spatialunit') attr_type = AttributeType.objects.get(name="text") sch = Schema.objects.create( content_type=content_type, selectors=(project.organization.pk, project.pk)) Attribute.objects.create( schema=sch, name='name', long_name='Name', required=False, index=1, attr_type=attr_type ) spatial_units = [] choices = [c[0] for c in TYPE_CHOICES] with open(os.path.join(os.path.dirname(__file__), "londondata.txt"), "r") as ins: for geometry in ins: if not geometry.rstrip() or geometry.startswith('#'): continue num_records = len(spatial_units) if not num_records < max_num_records: break name = 'Spatial Unit #{}'.format(num_records) type = random.choice(choices) spatial_units.append({ 'geometry': GEOSGeometry(geometry), 'type': type, 'project': project, 'attributes': {'name': name} }) SpatialUnitFactory.create_from_kwargs(spatial_units)