Separation of concerns is important for making code maintainable. Anybody aware of already built frameworks that implement perhaps an MVC approach for image rendering with for example PIL (or pillow)
It is probably not too hard to come up with such a framework, but any existing best practices would help navigate the waters of repeating mistakes, etc.
Edit: To be clear, my request is regarding creating a new image by combining and overlaying other images. Perhaps the analogy can be a framework like django which uses models to generate html pages ... similarly this framework or architecture would allow for generating dynamic png's from a dynamic dataset.
Here's a resource that provides many examples of server-side image resizing.
https://github.com/adamdbradley/foresight.js/wiki/Server-Resizing-Images
I'm not sure if any of them would meet the needs of your project as is, but I'm sure there's some take aways from their implementations that you can apply to your own project.
Related
I got a practice task, which I can not get any further.
The task is the following:
Project Description The goal of the projects is to create a map view
similar to the Google Maps, where the user can see some imagery data
captured by drones.
User should be able to move around the map freely, as well as zoom in
and zoom out to take a closer look at the captured imagery data.
It is strongly desired that the served imagery data will support
transparency while minimizing the file size and bandwidth usage. This
does not have to be implemented, but solution ideas are welcomed.
The raw imagery data will be provided as GeoTIFF files. Imagery
visible on the map can be added by placing a file inside a directory
that is read by the server. Project Delivery Method
Project should be delivered as a Git repository with documentation
required to setup and run the project.
Requirements
1. Server implementation in Python 3.5+
2. Project must be able to run on Ubuntu Server 16.04
3. Optimal disk space usage for imagery data displayed to the user (as the app may be processing terabytes of satellite imagery data)
4. Relatively conservative bandwidth usage
Notes:
1. The project will be deployed on a machine that is already running other Python software. Dependency conflicts must be avoided.
(virtualenv, Docker)
2. The UI can be a simple HTML page with embedded libraries and inline scripts.
In addition, it was specified in an e-mail:
"The test task is not code but just the approach and rough app
architecture
```I'm attaching a tank spec. Like I've mentioned. I'm more interested
in problem-solving and your ideas. I expect a working prototype tough.
Use any libraries you wish to use. Create an elegant, easy to
understand the solution. You can use as much time as you want. Would be
great if you could deliver the code by git.... ```"
So far I have done:
Ubuntu as VM
Venv
Postgres and PostGIS installed (Django writes error-free in a database)
Django project and app created
Documentation up to this point
I have now integrated the geotiff via console and that seems to work too:
from django.contrib.gis.gdal import GDALRaster
raster = GDALRaster('base/static/base/geotiff/xto-site3-rgb.tif')
raster.name
Out[4]: 'base/static/base/geotiff/xto-site3-rgb.tif'
raster.width, raster.height
Out[5]: (23001, 9668)
In the models.py is so far:
from django.contrib.gis.db import models
class RasterBase(models.Model):
raster = models.RasterField()
name = models.TextField()
How does it work that I install the grid so that I can portray this in an html similar to google maps? If I understand correctly, I must now write the geotiff in the database, and read on from there, right?
Unfortunately, I find in the network largely only outdated stuff, or often examples, which is assumed by shapefiles. Should I convert the grid to a shapefile and continue like that?
So far, I only make small things in Django, like my own blog and a few statistics, but this with Geodjango is a bit fierce because I have to give it up, as it were tomorrow. Latest Tuesday morning.
I would be very grateful if someone could give me some tips. All in all, that's pretty important to me, and it would be a shame if I messed up half of the task (or the last third) of the task.
Django is version 2.0
The GeoTIFF ~900mb
Thanks for all. :-)
Late to the party, but maybe some people are searching for a solution here.
When you want to display geodata on a map, you can use a WebGIS framework like Openlayers or Leaflet. They provide all the functionality to move the map and zoom in / out.
I would not recommend to store large raster data in a database. You can serve it directly from a file server via a TileLayer or use a XYZ tiling structure to minimize the bandwidth usage.
Openlayers has a lot of examples on how to server GeoTiff files.
I am trying to build a web application that requires intensive mathematical calculations. Can I use Django to populate python charts and pandas dataframe?
You can use any framework to do so. If you worked with Python before I can recommend using Django since you have the same (clear Python) syntax along your project. This is good because you keep the same logic everywhere but should not be your major concern when it comes to choosing the right framework for your needs. So for example if you are a top Ruby-On-Rails developer I would not suggest to learn Django just because of Pandas.
In general: A lot of packages/libraries are written in other languages but you will still be able to use them in Django/Python. So for example the famous "Elasticsearch" Searchbackend has its roots in JAVA but is still used in a lot of Django apps.
But it also goes the other way around "Celery" is written in Python but can be used in Node.js or PHP. There are hundreds of examples but I think you get the Point.
I hope that I brought some light into the darkness. If you have questions please leave them in the comments.
I'm building an app in Python which I would like to make available on the web. On the server side I will have a networkx graph of nodes and links, each of which will have their own pictoral representation. I'm looking for a way to represent this graph on my webpage, and looking for something that will be interactive and aesthetically pleasing. The interactivity required is that I need the user to be able to interact with the graph in an intuitive way, adding nodes and links, getting info about existing nodes, etc. It would conceptually be somewhat similar to mohiomap in web interface.
I've looked into django and flask, but I don't understand if this could be accomplished using these libraries. It seems like fairly graphic oriented content, more like a game than anything. I was looking at pygame and thought that using pyjsdl this might be more appropriate. My question is, is the above something that could be achieved with python. What would be the preferred language/library? I've looked at django and flask, but am wondering if pyglet or pygame may be actually more appropriate for this task. I mainly want to avoid going to deep into anything before I understand conceptually what constructs best fit the described purpose!
I realise this question is currently vague, please advise how I can make it more specific and I will update.
Web browser can execute only JavaScript so you will have to learn JavaScript and use JavaScript libraries in browser plus Django/Flask on server.
PyGame/Pyglet will be useless.
There are tools to conver Python to JavaScript but it may not be so usefull like pure JavaScript or existing libraries in JavaScript.
BTW: see JSNetworkX
I have been going through Flask and it seems that now I have a decent understanding to go ahead and build a web application. However I want to know how would I approach the problem. For eg:
I decide to build a blogging application. The first thing I do is write down all the things that come to my mind, from user registrations to posting data on the blog to publishing it on the site
But after that I just get into coding. I know that is not the right approach. I have heard of UML diagrams, workflow diagrams and stuff. It would be great if someone could just outline the steps they would follow for building a large application and then I could go ahead and learn more about them.For eg,it could be something like the below:-
Collect requirements
Draw UML diagrams
Draw workflow diagrams
start coding
Please suggest an exhaustive list so that I can make my approach much more systematic.
Thanks
That all sounds like a lot of work. Try web2py. You get a lot of stuff, such as user registrations and updating data for a blog, for free. Then just write the code. web2py is not as freeform as flask, there is a "one right way to do things". But for beginners, that can be helpful until you have enough experience to go it on your own.
What are my choices for frameworks for doing Python web development and having a nice language for writing templates for CSS/HTML? A key goal for me is not to have to run a server or install many extra dependencies -- I'd like something that works just by using CGI and hopefully does not force me to do any fancy reconfiguration of Apache etc.
My goal is to write pages that look pretty very easily using templates for generating nice looking HTML with CSS, as opposed to painfully writing out HTML using print statements, and have it be modular. I don't need fancy database support and I am not planning to complex forms for user input that I need to process.
The ideal framework will also have a set of templates written in it that I can use for my website.
I essentially just want to make pages programmatically from Python that look good using CSS/HTML without much work.
How can I do this? Something like Django for example would be overkill, since what I am doing is very simple. (Django is great, don't get me wrong, but my purposes are way too simple).
More specifics about my app:
I want to make a gallery of photos and also display Python code next to each photo. So I'd like to have a way to easily get syntax highlighting etc. in HTML for Python code. Just like Wordpress has many nice templates for blogs, I'd like a combination of web framework and templating language that has a gallery examples of components I can reuse, so that I don't have to write my own CSS/HTML for making menus/headers/other components of a page look good.
thanks.
Well, you're probably not going to find a framework with templates like that included, simply because that's out of most frameworks' scopes. The page structure, variables, and the like of any given Web application are going to be considerably different from each other, so good generic templates are hard to write. The reason people have so many templates and themes for Wordpress (which, though its authors sometimes promote it as a framework, is just an application) is because there are limits on what you can do with it. Frameworks don't have as many such limits. You are probably going to have to find the templates somewhere else and adapt them to the template language you want to use.
On the subject of template languages, as far as a good, modular template language is concerned, Jinja2 is hard to beat. It's fast, easy to write in, and powerful. I have taken quite a few templates from other Web sites and added the Jinja2 markup relatively effortlessly. Flask is a nice, light framework that works well with it, and it can deploy to CGI. And as for syntax highlighting, I'm going to have to go with Ignacio and recommend Pygments. All of these libraries are well-documented, so you should be able to figure them out easily.
Unfortunately, as much as I would like to have a gallery of reusable theme components, those are not easy to find. You're going to have to scrounge around the Web and hack stuff together yourself.
There's some docs, some tools, and some more tools. Plus, flup can turn any WSGI framework into a CGI app. And there's Pygments for syntax highlighting.