Skip to content

Commit

Permalink
Ready to put the first version on production,
Browse files Browse the repository at this point in the history
  • Loading branch information
frasanz committed Sep 25, 2024
1 parent 652e23b commit 298140b
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,4 @@ db.sqlite3
media/
georeferenced/
.DS_Store
.env
29 changes: 28 additions & 1 deletion frontend/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,33 @@ $(document).ready(function () {
})
}
});

$('#Submit').on('click', function () {
// Doing a post request to the backend
const data = {
"geoattempt_id": geoatempt_id,
"controlPoints": iconList,
"status": "DONE"
}
$.ajax({
url: 'http://127.0.0.1:8000/api/v1/geoattempt-individual/' + geoatempt_id + '/',
type: 'PATCH',
dataType: 'json',
headers: {
'X-CSRFToken': csrftoken,
'Content-Type': 'application/json'
},
data: JSON.stringify(data),
success: function (response) {
console.log(response);
},
error: function (response) {
infoModal.textContent = 'Error!'; // Set the modal content
$('.modal-body').html('An error ' + response.status + ' occurred:<br />' + response.responseText); // Set the modal body content
infoModal.show(); // Show the modal
}
})
});
$('#Skip').on('click', function () {
// Reload page
location.reload();
Expand Down Expand Up @@ -454,7 +481,7 @@ $(document).ready(function () {



viirs = L.tileLayer('http://lostatnight.org:8001/{z}/{x}/{y}.png', {
viirs = L.tileLayer('https://lostatnight.org/viirs_tiles/{z}/{x}/{y}.png', {
//viirs = L.tileLayer('https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/VIIRS_Black_Marble/default/2016-01-01/GoogleMapsCompatible_Level8/{z}/{x}/{y}.png', {
//viirs = L.tileLayer('https://earthengine.googleapis.com/v1/projects/ee-pmisson/maps/7f05e1c56c7139d418df9f275abae720-880cdb032adeb5dabd4855934e8d1764/tiles/{z}/{x}/{y}', {
//viirs = L.tileLayer('https://earthengine.googleapis.com/v1/projects/ee-pmisson/maps/7f05e1c56c7139d418df9f275abae720-880cdb032adeb5dabd4855934e8d1764/tiles/{z}/{x}/{y}', {
Expand Down
15 changes: 13 additions & 2 deletions gdalface/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

from pathlib import Path
from decouple import config
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down Expand Up @@ -81,10 +82,20 @@
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

#DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
#}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': 'django.db.backends.postgresql',
'NAME': config('DB_NAME'),
'USER': config('DB_USER'),
'PASSWORD': config('DB_PASSWORD'),
'HOST': config('DB_HOST', default='localhost'),
'PORT': config('DB_PORT', default='5432'),
}
}

Expand Down
18 changes: 18 additions & 0 deletions georeferencing/migrations/0013_alter_geoattempt_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-09-24 21:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('georeferencing', '0012_remove_geoattempt_path'),
]

operations = [
migrations.AlterField(
model_name='geoattempt',
name='status',
field=models.CharField(choices=[('PENDING', 'Pending'), ('DONE', 'Done')], default='PENDING', max_length=10),
),
]
18 changes: 18 additions & 0 deletions georeferencing/migrations/0014_geoattempt_skipped.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-09-24 21:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('georeferencing', '0013_alter_geoattempt_status'),
]

operations = [
migrations.AddField(
model_name='geoattempt',
name='skipped',
field=models.IntegerField(default=0),
),
]
18 changes: 18 additions & 0 deletions georeferencing/migrations/0015_geoattempt_controlpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-09-24 21:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('georeferencing', '0014_geoattempt_skipped'),
]

operations = [
migrations.AddField(
model_name='geoattempt',
name='controlPoints',
field=models.JSONField(default=dict),
),
]
18 changes: 18 additions & 0 deletions georeferencing/migrations/0016_alter_geoattempt_controlpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.11 on 2024-09-24 22:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('georeferencing', '0015_geoattempt_controlpoints'),
]

operations = [
migrations.AlterField(
model_name='geoattempt',
name='controlPoints',
field=models.JSONField(blank=True, default=dict, null=True),
),
]
7 changes: 3 additions & 4 deletions georeferencing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class GeoAttempt(models.Model):

STATUS_CHOICES = (
('PENDING', 'Pending'),
('TESTING', 'Testing'),
('DOING', 'Doing'),
('SUCCESS', 'Success'),
('FAILURE', 'Failure'),
('DONE', 'Done'),
)
created = models.DateTimeField(auto_now_add=True)
image = models.ForeignKey('Image', on_delete=models.CASCADE)
Expand All @@ -38,6 +35,8 @@ class GeoAttempt(models.Model):
max_length=10,
choices = STATUS_CHOICES,
default = 'PENDING')
skipped = models.IntegerField(default=0)
controlPoints = models.JSONField(default=dict, blank=True, null=True)

def save(self, *args, **kwargs):
if not self.hash:
Expand Down
2 changes: 1 addition & 1 deletion georeferencing/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GeoAttemptSerializer(serializers.ModelSerializer):

class Meta:
model = GeoAttempt
fields = ['id', 'created', 'image', 'image_name', 'photo_center_by_machine_learning', 'status', 'hash']
fields = ['id', 'created', 'image', 'image_name', 'photo_center_by_machine_learning', 'status', 'hash', 'skipped', 'controlPoints']
read_only_fields = ['created', 'hash']

def get_image_name(self, obj):
Expand Down
16 changes: 3 additions & 13 deletions georeferencing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,12 @@ def patch(self, request, pk=None):
return Response({"error": f"gdal2tiles failed: {e.stderr}"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)


elif serializer.data['status'] == 'DOING':
elif request.data['status'] == 'DONE':
# let's start the georeferencing process
# for the moment, launch a batch script
print('doing georeferencing')
# we make a directory for the georeferenced images
if not os.path.exists('georeferenced'):
os.makedirs('georeferenced')
# now we show the route to the dir
print(os.path.abspath('georeferenced'))

command = 'gdal_translate -of GTiff'
for controlpoint in geoattemp.controlpoint_set.all():
command += ' -gcp ' + str(controlpoint.x) + ' ' + str(controlpoint.y) + ' ' + str(controlpoint.lat) + ' ' + str(controlpoint.long)
command += ' ' + geoattemp.image + ' ' + geoattemp

serializer.save()
print(request.data['controlPoints'])
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ fontawesomefree==6.6.0
inflection==0.5.1
packaging==24.0
pillow==10.2.0
psycopg2==2.9.9
python-decouple==3.8
pytz==2024.1
PyYAML==6.0.1
soupsieve==2.6
Expand Down

0 comments on commit 298140b

Please sign in to comment.