Исправление определения extent из tiff
This commit is contained in:
parent
74577f207f
commit
ccb6b4169c
@ -116,7 +116,7 @@ class OrtoListApiView(View):
|
||||
|
||||
class LayersApiView(View):
|
||||
def get(self, request: HttpRequest) -> JsonResponse:
|
||||
orthos = Ortho.objects.filter(active=True)
|
||||
orthos = Ortho.objects.filter(active=True).order_by("-id")
|
||||
|
||||
dynamic_layers: List[dict] = []
|
||||
static_layers: List[dict] = []
|
||||
|
||||
@ -60,45 +60,48 @@ class OrthoCreateView(CreateView):
|
||||
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["title"] = _("Добавление нового ортофотоплана")
|
||||
context = SettingsContextMixin.update_context_data(context)
|
||||
return context
|
||||
return SettingsContextMixin.update_context_data(context)
|
||||
|
||||
def form_valid(self, form: OrthoForm) -> HttpResponse:
|
||||
name = form.cleaned_data["name"]
|
||||
temp_file = form.files["image"]
|
||||
path = temp_file.temporary_file_path()
|
||||
rst = GDALRaster(path, write=True)
|
||||
uploaded_file = form.files["image"]
|
||||
|
||||
# Сохраняем файл во временное хранилище
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix=".tif") as tmp:
|
||||
for chunk in uploaded_file.chunks():
|
||||
tmp.write(chunk)
|
||||
tmp_path = tmp.name
|
||||
|
||||
rst = GDALRaster(tmp_path, write=False)
|
||||
extent = self.get_extent(rst)
|
||||
ortho_obj = Ortho(
|
||||
logger.info(extent)
|
||||
|
||||
ortho_uuid = str(uuid.uuid4())
|
||||
save_path = os.path.join(orthos_path, ortho_uuid)
|
||||
os.makedirs(save_path, exist_ok=True)
|
||||
|
||||
ortho = Ortho(
|
||||
name=name,
|
||||
min_lon=extent[0],
|
||||
min_lat=extent[1],
|
||||
max_lon=extent[2],
|
||||
max_lat=extent[3],
|
||||
tiles_path=f"{settings.MEDIA_URL}orthos/{ortho_uuid}/{{z}}/{{x}}/{{y}}.png",
|
||||
)
|
||||
ortho_uuid = str(uuid.uuid4())
|
||||
save_path = os.path.join(orthos_path, ortho_uuid)
|
||||
if not os.path.exists(save_path):
|
||||
os.makedirs(save_path)
|
||||
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix=".tif") as tmp:
|
||||
for chunk in temp_file.chunks():
|
||||
tmp.write(chunk)
|
||||
tmp_path = tmp.name
|
||||
ortho.save()
|
||||
|
||||
# Асинхронная генерация тайлов
|
||||
process = multiprocessing.Process(
|
||||
target=generate_tiles, args=(tmp_path, save_path)
|
||||
)
|
||||
process.start()
|
||||
ortho_obj.tiles_path = (
|
||||
f"{settings.MEDIA_URL}orthos/{ortho_uuid}/{{z}}/{{x}}/{{y}}.png"
|
||||
)
|
||||
ortho_obj.save()
|
||||
return redirect("management:street_pos:ortho-list")
|
||||
|
||||
return redirect(self.success_url)
|
||||
|
||||
def get_extent(self, rst: GDALRaster) -> tuple[float, float, float, float]:
|
||||
rst_extent = rst.extent # (min_x, min_y, max_x, max_y)
|
||||
|
||||
if rst.srid == 4326:
|
||||
return rst.extent
|
||||
source_srs = osr.SpatialReference()
|
||||
if rst.srs:
|
||||
source_srs.ImportFromWkt(rst.srs.wkt)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user