-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatic calculation of a polygon area (#1534)
* Adding geometry_details field to SpatialUnit Model, add receiver signal to calculate geometry details, m2,ft2,ha,ac * Update changes for test and lint * Working on fixing tests * Adding Tests for both spatial model and xforms model. Also made sure that areas are only calculated for polygons * Added area_metric_units, area_imperial_units to the spatial/view/default context for display in location_details * Added the total area in ha to the project stats * Removing model calculation, only calculting in m2.. Will replace for view conversion * Adding test for location_details context view * Fixing linting issues * Added proper filter function for area conversion, added tests and UI for both project dashboard and location details * Added to geometry_details area to the export data, shp, excel with tests * Removing unwanted print statment * PR changes, removed model migration, model test, change location for postgis query and project sum, updated tests and linting * PR Changes, added SpatialUnit property for area to eliminate redundant code, made code style changes and added updated test based on new property * Adding area as a float to the spatial unit * Removed unnecessary comments * Removed unnessesary code and fixed migration for efficiency * Clean
- Loading branch information
Showing
15 changed files
with
125 additions
and
15 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
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
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,37 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.7 on 2017-05-31 21:21 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
from django.contrib.gis.db.models.functions import Area, Transform | ||
|
||
|
||
def calculate_area_field(apps, schema_editor): | ||
SpatialUnit = apps.get_model('spatial', 'SpatialUnit') | ||
SpatialUnit.objects.exclude(geometry=None).extra( | ||
where=["geometrytype(geometry) LIKE 'POLYGON'"]).update( | ||
area=Area(Transform('geometry', 3857))) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('spatial', '0003_custom_location_types'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='historicalspatialunit', | ||
name='area', | ||
field=models.FloatField(null=True), | ||
), | ||
migrations.AddField( | ||
model_name='spatialunit', | ||
name='area', | ||
field=models.FloatField(null=True), | ||
), | ||
migrations.RunPython( | ||
calculate_area_field, | ||
reverse_code=migrations.RunPython.noop | ||
), | ||
] |
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
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