Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE geolocation em formato geoJson #93

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions geolocations_service/service/brumadinho/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 2.1.3 on 2019-01-29 02:11
# Generated by Django 2.1.3 on 2019-01-31 23:29

import django.contrib.gis.db.models.fields
from django.db import migrations, models
import django.db.models.deletion

Expand All @@ -12,20 +13,37 @@ class Migration(migrations.Migration):
]

operations = [
migrations.CreateModel(
name='FoundPeople',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('full_name', models.CharField(blank=True, help_text='Full name of the found people.', max_length=150)),
('gender', models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female')], default=None, help_text='Gender of the found people.', max_length=2, null=True)),
('status_condition', models.CharField(blank=True, choices=[('Alive', 'Alive'), ('Dead', 'Dead')], default=None, help_text='Status condition of the found people.', max_length=5, null=True)),
],
),
migrations.CreateModel(
name='Geolocation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('latitude', models.FloatField()),
('longitude', models.FloatField()),
('coordinates', django.contrib.gis.db.models.fields.PointField(srid=4326)),
],
),
migrations.CreateModel(
name='VisitedLocation',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reference', models.CharField(max_length=100)),
('location', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='brumadinho.Geolocation')),
('reference', models.CharField(help_text='Reference and information.', max_length=100)),
('visitation_date', models.DateTimeField(blank=True, help_text='Datetime of the location analysis.', null=True)),
('encounter_number', models.IntegerField(help_text='Number of people found in this location.')),
('radius', models.FloatField(default=1, help_text='Radial área range of search.')),
('observations', models.CharField(blank=True, help_text='Observations', max_length=2000, null=True)),
('location', models.ForeignKey(help_text='Geoposition of the visited area.', on_delete=django.db.models.deletion.PROTECT, to='brumadinho.Geolocation')),
],
),
migrations.AddField(
model_name='foundpeople',
name='location',
field=models.ForeignKey(blank=True, help_text='Found location.', null=True, on_delete=django.db.models.deletion.PROTECT, to='brumadinho.Geolocation'),
),
]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.1.3 on 2019-02-01 02:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('brumadinho', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='geolocation',
name='latitude',
field=models.FloatField(default=0.0),
preserve_default=False,
),
migrations.AddField(
model_name='geolocation',
name='longitude',
field=models.FloatField(default=0.0),
preserve_default=False,
),
]

This file was deleted.

This file was deleted.

13 changes: 2 additions & 11 deletions geolocations_service/service/brumadinho/models.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
from django.db import models

from django.contrib.gis.db import models as gis_models

class Geolocation(models.Model):

class Meta:
unique_together = ['latitude', 'longitude']

coordinates = gis_models.PointField(null=True, blank=True)
latitude = models.FloatField()
longitude = models.FloatField()

def __str__(self):
return str("lat: {} long: {}".format(
self.latitude,
self.longitude
))


class VisitedLocation(models.Model):

reference = models.CharField(
Expand Down
22 changes: 20 additions & 2 deletions geolocations_service/service/brumadinho/serializers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
# from django.contrib.auth.models import Group
from brumadinho.models import Geolocation, VisitedLocation, FoundPeople
from rest_framework import serializers
from rest_framework_gis import serializers as gis_serializer
# from django.core.serializers import serialize
from django.contrib.gis.geos import Point


class GeolocationSerializer(serializers.ModelSerializer):
class GeolocationSerializer(gis_serializer.GeoFeatureModelSerializer):

# TODO corrigir para que coordinates NÃO SEJA exibido como valor de input na tela
# nem seja possível de ser recebido na requisição.

class Meta:
model = Geolocation
fields = "__all__"
fields = ("latitude", "longitude")
geo_field = "coordinates"
read_only_field = "coordinates"
write_only_fields = ("latitude", "longitude")

def create(self, data):

data['coordinates'] = Point(
data.get('longitude'),
data.get('latitude')
)
Geolocation.objects.create(**data)
return data

class VisitedLocationSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
2 changes: 2 additions & 0 deletions geolocations_service/service/service/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
django==2.1.5
djangorestframework==3.9.0
python-decouple==3.1
djangorestframework-gis==0.14
psycopg2==2.7.7
13 changes: 10 additions & 3 deletions geolocations_service/service/service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'rest_framework',
'brumadinho'
'rest_framework_gis',
'brumadinho',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -67,8 +69,13 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.contrib.gis.db.backends.postgis',
# 'ENGINE': 'django.db.backends.postgresql',
'NAME': config('DB_NAME'),
'USER': config('DB_USER'),
'PASSWORD': config('DB_PASSWORD'),
'HOST': config('DB_HOST'),
'PORT': config('DB_PORT'),
}
}

Expand Down