prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Import of Bezirksregionen stopped working
  `$ manage.py import_geodata --gdal-legacy`
  
  Leads to a `KeyError`, probably the data format has changed.
  
  
  </issue>
  <code>
  [start of meinberlin/apps/maps/management/commands/import_geodata.py]
  1 import json
  2 import os
  3 import subprocess
  4 import sys
  5 
  6 from django.core.management.base import BaseCommand
  7 
  8 from meinberlin.apps.maps import models as map_models
  9 
  10 
  11 class Command(BaseCommand):
  12     help = 'Create map presets for berlin GEO-Data'
  13 
  14     def add_arguments(self, parser):
  15         parser.add_argument(
  16             '--gdal-legacy',
  17             action='store_true',
  18             dest='gdal_legacy',
  19             default=False,
  20             help='GDAL version <= 1.10',
  21         )
  22 
  23     def handle(self, *args, **options):
  24         self.is_gdal_legacy = options['gdal_legacy']
  25         self._import_districts()
  26         self._import_regions()
  27 
  28     def _import_districts(self):
  29         category = self._preset_category('Berlin')
  30         tmpfile = '/tmp/bezirke.json'
  31         url = 'http://fbinter.stadt-berlin.de/fb/' \
  32               'wfs/geometry/senstadt/re_bezirke/'
  33         self._download_geodata(tmpfile, url, 'fis:re_bezirke')
  34         data = json.load(open(tmpfile, 'r'))
  35         for feature in data['features']:
  36             district = feature['properties']['spatial_alias']
  37             if not map_models.MapPreset.objects.filter(name=district).exists():
  38                 self._create_map_preset(district, feature, category)
  39         os.remove(tmpfile)
  40 
  41     def _import_regions(self):
  42         url = 'http://fbinter.stadt-berlin.de/fb/' \
  43               'wfs/geometry/senstadt/re_bezirksregion'
  44         tmpfile = '/tmp/bezirksregions.json'
  45         self._download_geodata(tmpfile, url,
  46                                'fis:re_bezirksregion')
  47         data = json.load(open(tmpfile, 'r'))
  48         for feature in data['features']:
  49             district = feature['properties']['BEZIRK']
  50             region = feature['properties']['BZR_NAME']
  51             category = self._preset_category(district)
  52             if not map_models.MapPreset.objects.filter(name=region).exists():
  53                 self._create_map_preset(region, feature, category)
  54         os.remove(tmpfile)
  55 
  56     def _preset_category(self, name):
  57         category, _ = \
  58             map_models.MapPresetCategory.objects.get_or_create(name=name)
  59         return category
  60 
  61     def _create_map_preset(self, name, feature, category):
  62         polygon = {
  63             'type': 'FeatureCollection',
  64             'features': [feature]
  65         }
  66         map_preset = map_models.MapPreset(
  67             name=name,
  68             polygon=polygon,
  69             category=category
  70         )
  71         map_preset.save()
  72 
  73     def _download_geodata(self, filename: str, url: str, layer: str):
  74         try:
  75             os.remove(filename)
  76         except:
  77             pass
  78 
  79         src = 'WFS:{}{}'.format(
  80             url,
  81             '?TYPENAMES=GML2' if self.is_gdal_legacy else ''
  82         )
  83         try:
  84             print('Trying to download file from {}'.format(url))
  85             subprocess.check_call([
  86                 'ogr2ogr', '-s_srs', 'EPSG:25833', '-t_srs', 'WGS84',
  87                 '-f', 'geoJSON', filename, src, layer
  88             ])
  89         except FileNotFoundError as e:
  90             print('Make sure ogr2ogr is installed and in user PATH.')
  91             sys.exit(e)
  92
  [end of meinberlin/apps/maps/management/commands/import_geodata.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/meinberlin/apps/maps/management/commands/import_geodata.py b/meinberlin/apps/maps/management/commands/import_geodata.py
  --- a/meinberlin/apps/maps/management/commands/import_geodata.py
  +++ b/meinberlin/apps/maps/management/commands/import_geodata.py
  @@ -40,13 +40,13 @@
   
       def _import_regions(self):
           url = 'http://fbinter.stadt-berlin.de/fb/' \
  -              'wfs/geometry/senstadt/re_bezirksregion'
  +              'wfs/geometry/senstadt/re_bezirksregion/'
           tmpfile = '/tmp/bezirksregions.json'
           self._download_geodata(tmpfile, url,
                                  'fis:re_bezirksregion')
           data = json.load(open(tmpfile, 'r'))
           for feature in data['features']:
  -            district = feature['properties']['BEZIRK']
  +            district = feature['properties']['BEZNAME']
               region = feature['properties']['BZR_NAME']
               category = self._preset_category(district)
               if not map_models.MapPreset.objects.filter(name=region).exists():
  @@ -78,7 +78,7 @@
   
           src = 'WFS:{}{}'.format(
               url,
  -            '?TYPENAMES=GML2' if self.is_gdal_legacy else ''
  +            '?VERSION=1.1.0' if self.is_gdal_legacy else ''
           )
           try:
               print('Trying to download file from {}'.format(url))
  
verification_info: {"golden_diff": "diff --git a/meinberlin/apps/maps/management/commands/import_geodata.py b/meinberlin/apps/maps/management/commands/import_geodata.py\n--- a/meinberlin/apps/maps/management/commands/import_geodata.py\n+++ b/meinberlin/apps/maps/management/commands/import_geodata.py\n@@ -40,13 +40,13 @@\n \n     def _import_regions(self):\n         url = 'http://fbinter.stadt-berlin.de/fb/' \\\n-              'wfs/geometry/senstadt/re_bezirksregion'\n+              'wfs/geometry/senstadt/re_bezirksregion/'\n         tmpfile = '/tmp/bezirksregions.json'\n         self._download_geodata(tmpfile, url,\n                                'fis:re_bezirksregion')\n         data = json.load(open(tmpfile, 'r'))\n         for feature in data['features']:\n-            district = feature['properties']['BEZIRK']\n+            district = feature['properties']['BEZNAME']\n             region = feature['properties']['BZR_NAME']\n             category = self._preset_category(district)\n             if not map_models.MapPreset.objects.filter(name=region).exists():\n@@ -78,7 +78,7 @@\n \n         src = 'WFS:{}{}'.format(\n             url,\n-            '?TYPENAMES=GML2' if self.is_gdal_legacy else ''\n+            '?VERSION=1.1.0' if self.is_gdal_legacy else ''\n         )\n         try:\n             print('Trying to download file from {}'.format(url))\n", "issue": "Import of Bezirksregionen stopped working\n`$ manage.py import_geodata --gdal-legacy`\r\n\r\nLeads to a `KeyError`, probably the data format has changed.\r\n\n", "before_files": [{"content": "import json\nimport os\nimport subprocess\nimport sys\n\nfrom django.core.management.base import BaseCommand\n\nfrom meinberlin.apps.maps import models as map_models\n\n\nclass Command(BaseCommand):\n    help = 'Create map presets for berlin GEO-Data'\n\n    def add_arguments(self, parser):\n        parser.add_argument(\n            '--gdal-legacy',\n            action='store_true',\n            dest='gdal_legacy',\n            default=False,\n            help='GDAL version <= 1.10',\n        )\n\n    def handle(self, *args, **options):\n        self.is_gdal_legacy = options['gdal_legacy']\n        self._import_districts()\n        self._import_regions()\n\n    def _import_districts(self):\n        category = self._preset_category('Berlin')\n        tmpfile = '/tmp/bezirke.json'\n        url = 'http://fbinter.stadt-berlin.de/fb/' \\\n              'wfs/geometry/senstadt/re_bezirke/'\n        self._download_geodata(tmpfile, url, 'fis:re_bezirke')\n        data = json.load(open(tmpfile, 'r'))\n        for feature in data['features']:\n            district = feature['properties']['spatial_alias']\n            if not map_models.MapPreset.objects.filter(name=district).exists():\n                self._create_map_preset(district, feature, category)\n        os.remove(tmpfile)\n\n    def _import_regions(self):\n        url = 'http://fbinter.stadt-berlin.de/fb/' \\\n              'wfs/geometry/senstadt/re_bezirksregion'\n        tmpfile = '/tmp/bezirksregions.json'\n        self._download_geodata(tmpfile, url,\n                               'fis:re_bezirksregion')\n        data = json.load(open(tmpfile, 'r'))\n        for feature in data['features']:\n            district = feature['properties']['BEZIRK']\n            region = feature['properties']['BZR_NAME']\n            category = self._preset_category(district)\n            if not map_models.MapPreset.objects.filter(name=region).exists():\n                self._create_map_preset(region, feature, category)\n        os.remove(tmpfile)\n\n    def _preset_category(self, name):\n        category, _ = \\\n            map_models.MapPresetCategory.objects.get_or_create(name=name)\n        return category\n\n    def _create_map_preset(self, name, feature, category):\n        polygon = {\n            'type': 'FeatureCollection',\n            'features': [feature]\n        }\n        map_preset = map_models.MapPreset(\n            name=name,\n            polygon=polygon,\n            category=category\n        )\n        map_preset.save()\n\n    def _download_geodata(self, filename: str, url: str, layer: str):\n        try:\n            os.remove(filename)\n        except:\n            pass\n\n        src = 'WFS:{}{}'.format(\n            url,\n            '?TYPENAMES=GML2' if self.is_gdal_legacy else ''\n        )\n        try:\n            print('Trying to download file from {}'.format(url))\n            subprocess.check_call([\n                'ogr2ogr', '-s_srs', 'EPSG:25833', '-t_srs', 'WGS84',\n                '-f', 'geoJSON', filename, src, layer\n            ])\n        except FileNotFoundError as e:\n            print('Make sure ogr2ogr is installed and in user PATH.')\n            sys.exit(e)\n", "path": "meinberlin/apps/maps/management/commands/import_geodata.py"}]}