diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-09-22 17:41:48 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-09-23 18:42:47 +0200 | 
| commit | 48c079bccd932f5b4d439c1ea1fd2db92a65f66b (patch) | |
| tree | 315f029d886fc2b6aa19bdc7ed57356fe38afe74 /ishtar_common/management/commands | |
| parent | c83730b93629b2a2a94d40faf770885776299b16 (diff) | |
| download | Ishtar-48c079bccd932f5b4d439c1ea1fd2db92a65f66b.tar.bz2 Ishtar-48c079bccd932f5b4d439c1ea1fd2db92a65f66b.zip  | |
Fix import_geofla withe new file format - update documentation for town import and installation
Diffstat (limited to 'ishtar_common/management/commands')
| -rw-r--r-- | ishtar_common/management/commands/import_geofla_csv.py | 15 | 
1 files changed, 11 insertions, 4 deletions
diff --git a/ishtar_common/management/commands/import_geofla_csv.py b/ishtar_common/management/commands/import_geofla_csv.py index 9b53c8a70..0464d3480 100644 --- a/ishtar_common/management/commands/import_geofla_csv.py +++ b/ishtar_common/management/commands/import_geofla_csv.py @@ -59,6 +59,7 @@ class Command(BaseCommand):      @transaction.atomic      def handle(self, *args, **options): +        csv.field_size_limit(sys.maxsize)          csv_file = options['csv_file']          default_year = options['year']          srid = options['srid'] @@ -67,8 +68,12 @@ class Command(BaseCommand):              sys.stdout.write('* using year {} as a default\n'.format(                  default_year))              sys.stdout.write('* Opening file {}\n'.format(csv_file)) -        nb_created, nb_changed = 0, 0 +        nb_created, nb_changed, nb_error = 0, 0, 0          with open(csv_file, 'rt') as csvfile: +            header = csvfile.readline() +            geom_colum = header.split(",")[0] +            csvfile.seek(0) +              reader = csv.DictReader(csvfile)              for idx, row in enumerate(reader):                  if not quiet: @@ -84,7 +89,7 @@ class Command(BaseCommand):                  town, created = self.get_town(num_insee, name, default_year)                  if created:                      nb_created += 1 -                geom = row['wkt_geom'].upper() +                geom = row[geom_colum].upper()                  if 'MULTI' not in geom:                      geom = geom.replace('POLYGON', 'MULTIPOLYGON(') + ')'                  values = {'limit': GEOSGeometry(geom, srid=srid)} @@ -116,15 +121,17 @@ class Command(BaseCommand):                              'POLYGON', 'MULTIPOLYGON(') + ')'                      town.limit = new_limit                      """ +                    nb_error += 1                      town, created = self.get_town(num_insee, name, default_year) -                    values['limit'] = None +                    values.pop('limit')                      for k in values:                          setattr(town, k, values[k])                      town.save()          if quiet:              return          sys.stdout.write('\n* {} town created'.format(nb_created)) -        sys.stdout.write('\n* {} town changed\n'.format(nb_changed)) +        sys.stdout.write('\n* {} town changed'.format(nb_changed)) +        sys.stdout.write('\n* {} town with geometry error\n'.format(nb_error))          sys.stdout.flush()  | 
