geodesign / django-raster

Django-raster allows you to create tiled map services (TMS) and raster map algebra end points for web maps. It is Python-based, and requires GeoDjango with a PostGIS backend.
BSD 3-Clause "New" or "Revised" License
96 stars 39 forks source link

how to use view #38

Closed xxqhh closed 4 years ago

xxqhh commented 4 years ago

Hi I want to use WMS.But i don't how to import them.Can you give me some example?Thank you.

yellowcap commented 4 years ago

Not sure what you mean, could you be more precise with your question?

xxqhh commented 4 years ago

like this problem:https://github.com/geodesign/django-raster/issues/30 I have try this, But i can't visual display

yellowcap commented 4 years ago

Its hard to guess what could be going wrong. Did you successfully parse a raster? Where RasterTile objects created?

xxqhh commented 4 years ago

I find i can't create rasterfile, [2019-09-10 17:49:05,438: ERROR/MainProcess] Task raster.tasks.create_tiles[c43eb70b-ef66-434b-a575-2d2583c3d0d1] raised unexpected: PermissionError(13, 'Another program is using this file and the process cannot access it.') I don't know how to solve it.

yellowcap commented 4 years ago

This could be related to the media storage settings. When you create a new RasterLayer, you probably uploaded a raster file. Maybe your django application does not have read access to the raster that you uploaded? https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-MEDIA_ROOT

xxqhh commented 4 years ago

Sorry, I don't know how to set it up.

MEDIA_URL = "/media/" MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

yellowcap commented 4 years ago

The MEDIA_ROOT is where your uploaded raster will be stored. So the web application needs write permissions for that folder. Depending on how you run your Django, that might not be in the BASE_DIR. Generally, its not a good idea to put it in BASE_DIR. You want it to be a permanent location. So create a folder somewhere for it, in development it could be something like (~/Documents/my_django_app_media_files/). Make sure that your django app has read and write permissions on that folder. In production, you will need to ensure that the media file location is a stable permanent location, otherwise you loose the files when your django server reboots.

Se also https://docs.djangoproject.com/en/2.2/topics/files/

xxqhh commented 4 years ago

Raster layer metadatas, Raster layers can create, but Raster tiles can't,I changed the location of the storage, but it didn't work.

yellowcap commented 4 years ago

Well, your error indicates that it is a file access permission issue. Are you using celery? Could you share the traceback of your error?

xxqhh commented 4 years ago

yes image

yellowcap commented 4 years ago

This indicates that the tiles are actually being created, but that the last cleanup step there is a problem with permissions of the temporary directory that the parser creates. So the error arises after the raster is parsed successfully, the rmdir is a cleanup step.

Could you confirm that the RasterTiles are created (have a look at the raster/rasteritile admin and see if there are objects).

Its hard for me to understand why the create_tiles can not remove this temporary directory. It might have to do with windows or with the user permissions on your celery instance.

xxqhh commented 4 years ago

image I create RasterTiles, But it has no object.

xxqhh commented 4 years ago

image

yellowcap commented 4 years ago

The two errors you shared are not the same! One fails on line 50 the other on line 40. Make sure your celery worker has read and write access in the D:\\data\\ directory. The problem you have does not seem to be a django-raster bug but rather a setup configuration problem with permissions.

xxqhh commented 4 years ago

Can you help me look at the code?This is my first time using celery.I don't what i should do

yellowcap commented 4 years ago

It looks like you are using anaconda. That means that your django and celery apps are running through this environment. I am not familiar with anaconda, but you might be able to select a MEDIA_ROOT that is within anaconda's permissions? Your problems might be related to that.

xxqhh commented 4 years ago

dest_zip = zipfile.ZipFile(dest.name, 'w', allowZip64=True) image I think there's a problem here, but I don't know how to fix it.

xxqhh commented 4 years ago

import zipfile dest_zip = zipfile.ZipFile(r'C:\Users\Lenovo\AppData\Local\Temp\tmpso_qiewj\tmpwvnred35.zip', 'w', allowZip64=True) error import zipfile

dest_zip = zipfile.ZipFile(r'D:\rsgis.zip', 'w', allowZip64=True) ok i don't know why

yellowcap commented 4 years ago

One is on disk C:\ and another one is on disk D:\, it looks like the tempfiles are placed in another folder that might not be accessible by celery or django.

xxqhh commented 4 years ago

I seem to have found the problem. It's related to the system I use. tempfile.NamedTemporaryFile([mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[, dir=None[, delete=True]]]]]]) This function operates exactly as TemporaryFile() does, except that the file is guaranteed to have a visible name in the file system (on Unix, the directory entry is not unlinked). That name can be retrieved from the name attribute of the returned file-like object. Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later). If delete is true (the default), the file is deleted as soon as it is closed. The returned object is always a file-like object whose file attribute is the underlying true file object. This file-like object can be used in a with statement, just like a normal file. New in version 2.3. New in version 2.6: The delete parameter. https://docs.python.org/2/library/tempfile.html

xxqhh commented 4 years ago

Hi,I have new problem,I don't know how to solve,hope you can reply me.Thank you image

yellowcap commented 4 years ago

Based on your feedback I made some improvements in file handling, see https://github.com/geodesign/django-raster/commit/1dcc3e19499b18a5de95e247e22a8677a7088d75. Could you check if your problems persist if you install the current master branch?

xxqhh commented 4 years ago

Yes, it solved my previous problems.but it have new problem.And then what system did you use to write this project? Thank you. image

yellowcap commented 4 years ago

This looks like a very related issue. The warping of a raster fails probably because the underlying tempfile is not allowing it to open again. I made another update here https://github.com/geodesign/django-raster/commit/3f5dd55fa1f0abc9e909abd92fc3ffea47613bc6. Could you check if that solves your second problem?

xxqhh commented 4 years ago

https://github.com/geodesign/django-raster/commit/1dcc3e19499b18a5de95e247e22a8677a7088d75 It doesn't seem to solve the problem.

yellowcap commented 4 years ago

Can you try https://github.com/geodesign/django-raster/commit/3f5dd55fa1f0abc9e909abd92fc3ffea47613bc6 ?

xxqhh commented 4 years ago

There seems to be some problem. if i use os.remove(dest_file_name),it will error

yellowcap commented 4 years ago

What is the traceback?

xxqhh commented 4 years ago

image

xxqhh commented 4 years ago

I know how to modify it, but i think it not well image image 'destructor = capi.close_ds' can't run. If I do this, temporary files cannot be deleted.

yellowcap commented 4 years ago

I don't understand how you can have a permissions error in that case. Does the file not exist anymore?

yellowcap commented 4 years ago

@xxqhh Is this solved?

xxqhh commented 4 years ago

There are still some problems, but I don't know what went wrong.

xxqhh commented 4 years ago

Like this image image PermissionError: [Errno 13] Another program is using this file and the process cannot access it.: 'D:/datatest\tmp47rya8d7\ndvi.tiff_copy.GTiff'

xxqhh commented 4 years ago

I don't know if it's because of this problem.I can't parse the second band. image image

yellowcap commented 4 years ago

Your questions are very specific to your set up. Its hard to help you like this. Hope you figured out a solution!