免责声明:我对python的了解有限。我在gis.stackexchange中提出了这个问题,但被选中“不清楚你在问什么”,可能是因为这是一个编程问题,而不是gis?
我使用了来自此source的随机生成用户python脚本,而该命令创建了一个postgis表,它不创建随机生成的用户配置文件(该表为空)。在postgis表中创建随机用户配置文件时缺少什么?
from django.core.management.base import BaseCommand
from django.contrib.gis.geos import Point
import random
import uuid
import numpy as np
from mymap_app.models import LoveFinderUser
class Command(BaseCommand):
help = 'generate 1M users for Addis_Ababa with random sex, age, radius, location'
def handle(self, *args, **options):
Addis_Ababa__lat__min = 8.834544
Addis_Ababa__lat__max = 9.099231
Addis_Ababa__lng__min = 38.640241
Addis_Ababa__lng__max = 38.907086
for i in xrange(10**5):
new_random_lat = random.uniform(Addis_Ababa__lat__min, Addis_Ababa__lat__max)
new_random_lng = random.uniform(Addis_Ababa__lng__min, Addis_Ababa__lng__max)
user_age = random.randrange(18, 55)
user_delta_plus = random.choice([1, 2, 3, 5, 8, 13])
user_delta_minus = random.choice([1, 2, 3, 5, 8, 13])
user_sex = random.choice(['F', 'M'])
user_prefered_sex=random.choice(['F', 'M'])
new_user=LoveFinderUser.objects.create(
nickname=str(uuid.uuid4()),
age=user_age,
sex=user_sex,
prefered_sex=user_prefered_sex,
prefered_age_min=(user_age-user_delta_minus),
prefered_age_max=(user_age+user_delta_plus),
last_location=Point(float(new_random_lng), float(new_random_lat)),
prefered_radius=random.choice([5, 10, 15, 20, 25, 30])
)
new_user.save()
答案 0 :(得分:0)
感谢@HåkenLid。我使用了项目目录中的命令:(myvenv_python3)C:\ Users \ Kaleab \ Desktop \ myproject> django-admin generate_1M_LL_users并且它工作,我也必须将xrange更改为范围。