Using Django as a map source for openlayer UI - python

I am thinking of creating a web application that shows a map of a city (from openstreetmaps data). I would like to create a layer on top which represents markers. I foresee that I will have a database of numerous markers, which will be shown on the map as layer. I have come across openstreetmap, openlayers, geodjango etc but am unable to figure out how to make all these fit together to solve my issue. I am comfortable using Django and Python. Can someone help me understand the following:
How to host OSM data on my own server using Django and acting as a Mapserver (or map source) for openlayers?
How to ask openlayer to talk to this server to render the map or overlays?
I'm sorry if some part of my question does not make sense; it is because my understanding how these components is quite hazy at the moment.

Displaying markers at coordinates is the easy part. The harder part is hosting your own base map. Here is one way I think you could do it:
Obtain the OpenStreetMap data for the area you are interested in.
Develop a stylesheet for your map, or use an existing one. Mapnik is an option.
Use Tilecache to serve cached image tiles of the map at various scale levels. This would have to run in addition to your django app.
Another option would be to use Tiledrawer to set up an Amazon EC2 server serving your base map without having to manually configure everything.
Stack Overflow is only letting me post two links, so you will have to search for the websites of Tilecache and Mapnik, but they are easy to find.
References:
https://gis.stackexchange.com/questions/10162/how-to-set-up-an-osm-server-with-tilecache-and-mapnik

Related

Is there any way to share images between two streamlit webapps?

I want to link 2 web pages made using streamlit and hosted using Heroku. One of them removes the image background and the other does an image classification task. (They could not be made into one due to slug size limits of Heroku). At present, the user has to manually download the segmented image from one webpage and upload it to the second webpage.
The 2 can be shown together using an HTML iframe tag but I am not able to figure out how to transfer the segmented image from one webpage to other.
Any suggestion or help will be appreciated
Also please prefer solutions using python and its frameworks as the whole project is in python and learning javascript, HTTP, etc will take some time.
(but if it's not possible using python, answers using other methods will also be welcome)
One of my seniors advised me to explore other hosting options. (I had seen an online tutorial using Heroku , and did not know much about others). It turns out that streamlit cloud provides a much larger slug size and allows you to host it for free if you open source your project(I had no issue doing so), so I have combined the two parts and am now hosting using streamlit cloud.

How to create a static skeleton of a map using folium with over layers(markers) changing every hour which is hosted over a website using flask?

I am sorry if the question is confusing or doesn't make sense, this is my first project and I'll try to explain it to the best of my capabilities.
At first, I thought I would just be hosting a single map that I created using folium and inherited the template of the map into the website which is created with flask, therefore I didn't do any hardcoding in the main app.py file, however, it seemed really basic. So now using machine learning algorithms, I want to display different things over the map which makes some predictions for every hour of the day.
THE PROBLEM: It will take longer than expected to generate a new map every hour of the day (plus storing a new map so many times will be expensive in terms of storage).
MY SOLUTION: Have a skeleton map because the area that I will be making predictions on is localized, so have that area as the basic map and change the upper layers that will have the predictions displayed (basically heat map) every hour.
Is this a correct approach? Please recommend a right path to implement this. I am open to trying new things as long as it gets the job done. Would really appreciate any help regarding this. Thanks in advance
Folium does not support WebSockets if anything add new javascript to fetch data dynamically, but the best way would be to fetch data instead of rendering html everytime, it would help with the speed issue as well. Also, look into leaflets that would help too.
If you want to generate your map faster, you can use directly the Javascript library Leaflet to create the map (it is the library that is used to render the map with Folium). You need to send the data of your predictions from your backend in Flask to your front-end in Javascript with Leaflet in your HTML template (Jinja2).

Django / Geodjango / Raster / geotiff: Problems with practice task

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.

Mapping service and API

I am building an application that will need to use a mapping service to locate a set of addresses, and include said map with its reporting features. Meaning that it would be beneficial if there was an easy way to convert the map into something printable.
I haven't started designing the application yet, but I will probably write it in Python. I am aware of Google static maps, and it looks promising, especially the method of assigning waypoints (it is exactly what I need), but the map is limited to 640x640, so I was wondering if there are other options that would work well.
Thank you for your input.
You could try and create your own 640x640 tiles, then do some post-cleaning up before stitching them together. Or, generate a kml file of the addresses and use another mapping service?
I know this post is a bit old, but the MapQuest Static Maps Web Service might be worth a look for anyone else who has a similar need. The maximum dimensions of a static map request are 2048X2048, so a bit bigger than 640X640. If you have any questions, check out the forums on the MapQuest Developer Network.

Charts in django Web Applications

I want to Embed a chart in a Web Application developed using django.
I have come across Google charts API, ReportLab, PyChart, MatPlotLib and ChartDirector
I want to do it in the server side rather than send the AJAX request to Google chart APIs, as I also want to embed the chart into the PDF.
Which is the best option to use, and what are the relative merits and demerits of one over the other.
Another choice is CairoPlot.
We picked matplotlib over the others for some serious graphing inside one of our django apps, primarily because it was the only one that gave us exactly the kind of control we needed.
Performance generating PNG's was fine for us but... it was a highly specialized app with less than 10 logins a day.
Well, I'm involved in an open source project, Djime, that uses OpenFlashChart 2.
As you can see from our code, generating the JSON-data that OFC uses is a bit complex, but the output is very nice and user friendly, since you can add tooltips, etc. to the different elements.
Open Flash Chart 2
http://teethgrinder.co.uk/open-flash-chart-2/
python library http://btbytes.github.com/pyofc2/
kybi
One package I've wanted to try is graphite. It's a graphing server / platform built with Django. It's specialized for "numeric time-series data" though, like stock prices or bandwidth utilization. If that fits your need I would check it out. Here are some screenshots:
http://graphite.wikidot.com/screen-shots
I like client side charts because you can get full page plotting.
A good options seems to be Jquery Flot : http://code.google.com/p/flot/ which can load JSON data.
However, you won't get pdf support.
Perhaps you might want to have a look here: Django Plotting app.
The HowTo describes how to embed matplotlib plots into the admin interface and create a PDF view.
I have used FusionCharts Free with Django.
Its flash based, open source, multi-licensed and it's well documented. It's ActionScript 1, but AS version wasn't really a criteria for me, though it could be for others.

Categories

Resources