Skip to content

Commit

Permalink
Working with the API to fech the image, models
Browse files Browse the repository at this point in the history
changed, specially image model
  • Loading branch information
frasanz committed Sep 21, 2024
1 parent 48f066c commit a995da2
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 10 deletions.
20 changes: 17 additions & 3 deletions frontend/templates/task2.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,27 @@ <h3>Lost at night</h3>
<script>

$(document).ready(function () {

let iconCounter = 1; // Counter for numbering icons
let iconList = []; // List to store icon objects
let markerList = {}; // List to store marker objects
let iconMap = {}; // List to store the iconGroup objects
let isTurn = 'image'; // Variable to track the current turn
let group; // Variable to store the Fabric group object
let image_name; // Variable to store the image name
// Initialize Leaflet map
$.ajax({
url: 'http://127.0.0.1:8000/api/v1/geoattempt-pending/',
type: 'GET',
dataType: 'json',
success: function (response) {
image_name = response.image_name;
console.log(response);
console.log(image_name);
}
});
console.log(image_name);
// Now, wait 1 second before log image_name
const map = L.map('map').setView([0, 0], 2);
const osmLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
Expand Down Expand Up @@ -312,7 +326,9 @@ <h3>Lost at night</h3>
stopContextMenu: true, // Disable the default context menu
selection: false // Disable object selection
});
const imageUrl = "{% static 'images/ISS030-E-274867.JPG' %}";
const static_url = "{% static 'images/' %}";
const imageUrl = static_url + image_name + '.JPG'; // Image URL
console.log(imageUrl);
const canvasWidth = $('#column-right').width(); // Canvas width
const canvasHeight = $('#column-right').height(); // Canvas height
canvas.setWidth(canvasWidth); // Set the canvas width
Expand Down Expand Up @@ -603,8 +619,6 @@ <h3>Lost at night</h3>
isRightClickDragging = false; // Stop the right-click drag rotation
}
});


});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Generated by Django 4.2.11 on 2024-09-21 06:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('georeferencing', '0009_alter_geoattempt_hash'),
]

operations = [
migrations.AddField(
model_name='image',
name='camera',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name='image',
name='cameraTilt',
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name='image',
name='created',
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AddField(
model_name='image',
name='focalLength',
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name='image',
name='link',
field=models.URLField(blank=True, null=True),
),
migrations.AddField(
model_name='image',
name='photoCenterByMachineLearning',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name='image',
name='photoCenterPoint',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name='image',
name='spaceCraftAltitude',
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name='image',
name='spacecraftNadirPoint',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name='image',
name='taken',
field=models.DateTimeField(blank=True, null=True),
),
]
17 changes: 17 additions & 0 deletions georeferencing/migrations/0011_remove_image_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.11 on 2024-09-21 06:26

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('georeferencing', '0010_image_camera_image_cameratilt_image_created_and_more'),
]

operations = [
migrations.RemoveField(
model_name='image',
name='path',
),
]
17 changes: 17 additions & 0 deletions georeferencing/migrations/0012_remove_geoattempt_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.11 on 2024-09-21 06:43

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('georeferencing', '0011_remove_image_path'),
]

operations = [
migrations.RemoveField(
model_name='geoattempt',
name='path',
),
]
12 changes: 10 additions & 2 deletions georeferencing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class GeoAttempt(models.Model):
)
created = models.DateTimeField(auto_now_add=True)
image = models.ForeignKey('Image', on_delete=models.CASCADE)
path = models.FilePathField(path='/tmp/') # Improve this for security reasonsdefault
hash = models.CharField(
max_length=100,
blank=True,
Expand All @@ -50,6 +49,15 @@ def __str__(self):

class Image(models.Model):
name = models.CharField(max_length=100)
path = models.CharField(max_length=100)
taken = models.DateTimeField(blank=True, null=True)
created = models.DateTimeField(auto_now_add=True, blank = True, null = True)
camera = models.CharField(max_length=100, blank = True, null = True)
focalLength = models.IntegerField(blank = True, null = True)
cameraTilt = models.IntegerField(blank = True, null = True)
spacecraftNadirPoint = models.CharField(max_length=100, blank = True, null = True)
photoCenterPoint = models.CharField(max_length=100, blank = True, null = True)
photoCenterByMachineLearning = models.CharField(max_length=100, blank = True, null = True)
spaceCraftAltitude = models.IntegerField( blank = True, null = True)
link = models.URLField( blank = True, null = True)
def __str__(self):
return self.name
7 changes: 6 additions & 1 deletion georeferencing/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ class Meta:
read_only_fields = ['created']

class GeoAttemptSerializer(serializers.ModelSerializer):
image_name = serializers.SerializerMethodField()

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

def get_image_name(self, obj):
return obj.image.name

class MiniGeoAttemptSerializer(serializers.ModelSerializer):
class Meta:
model = GeoAttempt
Expand Down
10 changes: 9 additions & 1 deletion georeferencing/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from django.urls import path
from .views import ControlpointView, ControlpointIndividualView, ImageView, ImageIndividualView, GeoAttemptView, GeoAttemptIndividualView
from .views import (
ControlpointView,
ControlpointIndividualView,
ImageView,
ImageIndividualView,
GeoAttemptView,
GeoAttemptIndividualView,
PendingGeoAttemptView)
urlpatterns = [
# Define your app's URL patterns here
path('controlpoint/', ControlpointView.as_view(), name='controlpoints'),
path('controlpoint-individual/<int:pk>/', ControlpointIndividualView.as_view(), name='controlpoints-individual'),
path('geoattempt/', GeoAttemptView.as_view(), name='geoattempt'),
path('geoattempt-individual/<int:pk>/', GeoAttemptIndividualView.as_view(), name='geoattempt-individual'),
path('geoattempt-pending/', PendingGeoAttemptView.as_view(), name='geoattempt-pending'),
path('image/', ImageView.as_view(), name='images'),
path('image-individual/<int:pk>/', ImageIndividualView.as_view(), name='images-individual'),
]
32 changes: 29 additions & 3 deletions georeferencing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .serializers import ControlpointSerializer, GeoAttemptSerializer, ImageSerializer, MiniGeoAttemptSerializer
from .models import Controlpoint, GeoAttempt, Image
import os
import random


# Create your views here.
Expand Down Expand Up @@ -116,6 +117,33 @@ def post(self, request):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class PendingGeoAttemptView(APIView):
"""
API view to retrieve a random GeoAttempt with a status of "PENDING".
Methods:
- get: Get a random "PENDING" GeoAttempt.
"""

@swagger_auto_schema(
tags=['02. GeoAttempts'],
operation_summary="Get a random 'PENDING' geo attempt")
def get(self, request):
# Filter GeoAttempts by "PENDING" status
pending_geoattempts = GeoAttempt.objects.filter(status="PENDING")

if not pending_geoattempts.exists():
return Response({"error": "No pending geo attempts found."}, status=status.HTTP_404_NOT_FOUND)

# Select a random GeoAttempt
geoattempt = random.choice(pending_geoattempts)

# Serialize the GeoAttempt
serializer = GeoAttemptSerializer(geoattempt)

# Return the serialized data
return Response(serializer.data)



class GeoAttemptIndividualView(APIView):
"""
Expand Down Expand Up @@ -150,10 +178,8 @@ def patch(self, request, pk=None):
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.path + ' ' + geoattemp.path
command += ' ' + geoattemp.image + ' ' + geoattemp
print(command)



return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":6,"created":"2024-09-21T06:45:01.325499Z","image":4,"status":"PENDING","hash":"8063e11898fafd419166c010bad7ef60"}
1 change: 1 addition & 0 deletions index.html.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":5,"created":"2024-09-21T06:44:56.703143Z","image":3,"status":"PENDING","hash":"fce45a801acfb25b9b5236927eb39f07"}

0 comments on commit a995da2

Please sign in to comment.