本文整理汇总了Python中spatial.tests.factories.SpatialUnitFactory.create_from_kwargs方法的典型用法代码示例。如果您正苦于以下问题:Python SpatialUnitFactory.create_from_kwargs方法的具体用法?Python SpatialUnitFactory.create_from_kwargs怎么用?Python SpatialUnitFactory.create_from_kwargs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spatial.tests.factories.SpatialUnitFactory
的用法示例。
在下文中一共展示了SpatialUnitFactory.create_from_kwargs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_huge_project
# 需要导入模块: from spatial.tests.factories import SpatialUnitFactory [as 别名]
# 或者: from spatial.tests.factories.SpatialUnitFactory import create_from_kwargs [as 别名]
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)