Skip to content

Commit

Permalink
modifying media folders to store georerefenced and original photos
Browse files Browse the repository at this point in the history
  • Loading branch information
frasanz committed Sep 26, 2024
1 parent 1d35f85 commit deb52f8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions frontend/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ $(document).ready(function () {

success: function (response) {
georeferencingModal.hide();
let noCacheUrl = './georeferenced/' + image_name + geoattempt_hash + '/{z}/{x}/{y}.png' + '?nocache=' + new Date().getTime();
let noCacheUrl = '/media/georeferenced/' + image_name + geoattempt_hash + '/{z}/{x}/{y}.png' + '?nocache=' + new Date().getTime();
if (lyr)
map.removeLayer(lyr);

Expand Down Expand Up @@ -264,7 +264,7 @@ $(document).ready(function () {
}
});
});
const static_url = "/static/images/"; // Static URL
const static_url = "/media/original/"; // Static URL
const imageUrl = static_url + image_name + '.JPG'; // Image URL
console.log(response);
const canvasWidth = $('#column-photo').width(); // Canvas width
Expand Down
3 changes: 2 additions & 1 deletion frontend/templates/gettask.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lost At Night | Task</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
{% include '_google_analytics.html' %}
{% bootstrap_css %}
<!-- Include jQuery from a CDN -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
Expand Down Expand Up @@ -107,4 +108,4 @@ <h5 class="modal-title" id="exampleModalLabel">Georeferencing!</h5>
<div>
</body>

</html>
</html>
3 changes: 2 additions & 1 deletion frontend/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lost At Night</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
{% include '_google_analytics.html' %}
{% bootstrap_css %}
<!-- Include jQuery from a CDN -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
Expand Down Expand Up @@ -38,4 +39,4 @@ <h3>WELCOME TO LOST AT NIGHT</h3>
</a>
</div>
</body>
</html>
</html>
20 changes: 10 additions & 10 deletions georeferencing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@ def patch(self, request, pk=None):
print('Starting the testing process')

# Ensure the georeferenced directory exists
if not os.path.exists('georeferenced'):
os.makedirs('georeferenced')
if not os.path.exists('media/georeferenced'):
os.makedirs('media/georeferenced')

# First command: gdal_translate
command = 'gdal_translate -of GTiff'
for item in request.data['control_points']:
command += ' -gcp ' + str(item['actualPx']) + ' ' + str(item['actualPy'])
command += ' ' + str(item['lon']) + ' ' + str(item['lat'])
command += ' georeferencing/static/images/' + geoattemp.image.name + '.JPG '
command += ' georeferenced/' + geoattemp.image.name + geoattemp.hash + '.tif'
command += ' media/original/' + geoattemp.image.name + '.JPG '
command += ' media/georeferenced/' + geoattemp.image.name + geoattemp.hash + '.tif'
print(command)
try:
subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
Expand All @@ -204,8 +204,8 @@ def patch(self, request, pk=None):
# Second command: gdalwarp
# Check the # of points before enable tps (-order n to pylynomial)
command = 'gdalwarp --config NUM_THREADS 4 -multi -r bilinear -tps -t_srs EPSG:4326'
command += ' georeferenced/' + geoattemp.image.name + geoattemp.hash + '.tif'
command += ' georeferenced/' + geoattemp.image.name + geoattemp.hash + '.tif'
command += ' media/georeferenced/' + geoattemp.image.name + geoattemp.hash + '.tif'
command += ' media/georeferenced/' + geoattemp.image.name + geoattemp.hash + '.tif'
print(command)

try:
Expand All @@ -214,18 +214,18 @@ def patch(self, request, pk=None):
return Response({"error": f"gdalwarp failed: {e.stderr}"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

# Third command: Remove previous tiles
command = 'rm -r georeferenced/' + geoattemp.image.name + geoattemp.hash
command = 'rm -r media/georeferenced/' + geoattemp.image.name + geoattemp.hash
print(command)
if os.path.exists('georeferenced/' + geoattemp.image.name + geoattemp.hash):
if os.path.exists('media/georeferenced/' + geoattemp.image.name + geoattemp.hash):
try:
subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
return Response({"error": f"Failed to remove previous tiles: {e.stderr}"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

# Fourth command:
command = 'gdal2tiles.py -z 7-12 -r bilinear -s EPSG:4326'
command += ' georeferenced/' + geoattemp.image.name + geoattemp.hash + '.tif'
command += ' georeferenced/' + geoattemp.image.name + geoattemp.hash
command += ' media/georeferenced/' + geoattemp.image.name + geoattemp.hash + '.tif'
command += ' media/georeferenced/' + geoattemp.image.name + geoattemp.hash
print(command)

try:
Expand Down

0 comments on commit deb52f8

Please sign in to comment.