forked from City-of-Helsinki/kerrokantasi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from City-of-Turku/develop
Release v1.6
- Loading branch information
Showing
8 changed files
with
204 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 2.2.12 on 2021-02-15 11:38 | ||
|
||
import django.contrib.gis.db.models.fields | ||
import django.core.files.storage | ||
from django.db import migrations, models | ||
from django.contrib.gis.geos import GEOSGeometry, GeometryCollection | ||
import json | ||
|
||
|
||
def get_geometry_from_geojson(geojson): | ||
gc = GeometryCollection() | ||
if geojson is None: | ||
return None | ||
|
||
geometry_data = geojson.get('geometry', None) or geojson | ||
geometry = GEOSGeometry(json.dumps(geometry_data)) | ||
gc.append(geometry) | ||
|
||
return gc | ||
|
||
|
||
def hearings_geometry_migration(apps, schema_editor): | ||
Hearing = apps.get_model('democracy', 'Hearing') | ||
for hearing in Hearing.objects.filter(geojson__isnull=False): | ||
hearing.geometry = get_geometry_from_geojson(hearing.geojson) | ||
hearing.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('democracy', '0053_auto_20200813_1112'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(hearings_geometry_migration), | ||
migrations.AlterField( | ||
model_name='hearing', | ||
name='geometry', | ||
field=django.contrib.gis.db.models.fields.GeometryCollectionField(blank=True, null=True, srid=4326, verbose_name='area geometry'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
|
||
import json | ||
|
||
from django.contrib.gis.geos import GEOSGeometry | ||
from django.contrib.gis.geos import GEOSGeometry, GeometryCollection | ||
|
||
|
||
def get_geometry_from_geojson(geojson): | ||
gc = GeometryCollection() | ||
if geojson is None: | ||
return None | ||
geometry_data = geojson.get('geometry', None) or geojson | ||
geometry = GEOSGeometry(json.dumps(geometry_data)) | ||
return geometry | ||
|
||
if geometry_data.get('features'): | ||
for feature in geometry_data.get('features'): | ||
feature_geometry = feature.get('geometry') | ||
feature_GEOS = GEOSGeometry(json.dumps(feature_geometry)) | ||
gc.append(feature_GEOS) | ||
else: | ||
geometry = GEOSGeometry(json.dumps(geometry_data)) | ||
gc.append(geometry) | ||
return gc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.