Basic shape file display using PyQt - python

Are there any packages that allow for the interactive display of GIS shapefiles? I'm looking to create a simple GUI that displays simple shapefiles (coastlines, etc) but can't seem to find where to start. I was originally tasked with doing this in R but I would like to try and use python and Qt.

Mapnik supports GIS shape files and has a Python interface.

I think you can use a combination of the shapefile library for reading files, and shapely for all the processing of the data.
I have used shapely for working with geo data feeds that have been loaded into a database, to work with the point and polygon data.
Per your comments, if you just want to simply display a shapefile in your PyQt app, then really all you need is to convert it to an SVG and display it directly. I have not used this conversion lib but I am sure there are more like it. Then you can just use a QSvgWidget to load and display it

Related

Matplot lib image properties in web (Django)

I'd like to output the image to the web created in matplotlib having the very same functionality like it has on desktop when you run the image.show(), for example scaling, moving along the plot more thoroughly.
I've checked out #stack and got old post only offering static images or gif or matplotlib.animate()
I aslo had a look at matplotlib widgets, but those are for desktop GUI only as far as I can see.
Please share some experience or ideas regarding how can I achieve it.
Thanks
Matplotlib is a server side library so you cannot do anything on the client side like that.
The closest you can come is to either use mpld3 (mpld3 works by converting a matplotlib graph into the html/js that a d3 js graph would need to render) or a different client side library that plots points.
The easiest way of serving pure matplotlib to the web is using a jupyter notebook.
Other than that, you may want to look at specific libraries like Plotly or bokeh.

Is it possible to use matplotlib's interactive plotting features within Django?

I know Matplotlib can be used in Django, based on the documentation. However, I'd like to be able to create interactive graphs within a webpage (i.e clickable points). In order to display a graph created in a Python script, Django spits out a png image. I haven't tested it out myself, but the fact that Django only spits out a png is worrisome. Is what I'm trying to do possible?
http://scipy-cookbook.readthedocs.io/items/Matplotlib_Django.html
http://scipy-cookbook.readthedocs.io/items/Matplotlib_Interactive_Plotting.html

Generate dynamic plots with python

I am working on generating some plots using python, but I am generating these plots using matplotlib which is saved as images. If I create an html page as a report with these plots, they are static images. I cannot zoom in or roll over on the plot to see more detailed or specific information on a time series plot.
My question is how can I make these plots dynamic? Can someone suggest the best way to get started and move forward from there?
You should use some additional libraries to achive your goal.
For example, there some good Python web frameworks wich you can use:
CherryPy - allows you to simply write web-app with Python and you can import your plot there.
Plotly Python API - it would simply generate interactive plot, but store it at Plotly platform, but they provide embeded-code option, so you can use it on your site.
I would suggest Plotly, because it is much simpler, but it depends on your needs.
You will definitely want to do it using javascript. It's by far your best option when it comes to quickly make interactive graphs that you can present to a lot of users. Any of these js libraries will do a great job.
You will then want python to provide the data. Depending on the js library you are using, you might be able to parse data from .json, .csv, etc...
If you don't need the data that makes up your plots to change (with user input, for example), then generating and saving flat files with python and having javascript parsing them from some directory might be just enough.
Otherwise, you want to take a look at a python web framework and use one as backend to serve the plots data by request (in that case .json is probably the right format).
Frameworks like Flask, CherryPy, Pyramid or even web2py might be the easier ones to start with.

Dynamic plotting using Django and matplotlib

These days I've been trying to create a webpage on which one can watch a dynamic plotting demo. I'm using Django to construct the webpage, and recently have learned that matplotlib.animation can do such kind of job. I wonder whether it's possible to use this API, matplitlib.animation, while building the webpage using Django. (I tried to do it using 'HttpResponse' but only to fail.) If there is any other way to do this, please let me know. Thanks in advance.
You need to write the animation to disk and then serve it up via some static interface. Here is an idea of how to accomplish it:
Make your webserver point /animations to /var/www/animations
Save your animations in that folder (You can save mp4 and use HTML5 but if you want to save a GIF this SO has information on what is needed. You could use a model to hold initializing parameters and a hash of those (which would make a decent filename).
Render it in your templates with a regular img tag (or video tag if you use mp4).

svg diagrams using python

I am looking for a library to generate svg diagrams in python (I fetch data from a sql database). I have found python-gd, but it has not much documentation and last update was in 2005 so I wonder if there are any other libraries that are good for this purpose.
I am mostly thinking about simple line graphs, something like this:
Try using matplotlib. You can configure it with a SVG backend.
As you're looking for simple line graphics, probably, CairoPlot will fit your needs as it can generate svg output files out of the box. Take a look at this.
This example image shows only a few of its capabilities. Using the trunk version available at launchpad you'll be able to add a legend box and add axis titles.
Besides that, using the trunk version, it's possible to generate:
DotLine charts (the ones I believe you need)
Scatter charts
Pie/Donut charts
Horizontal/Vertical Bar charts
Gantt charts
pyCairo is an option worth looking at.
PyChart "is a Python library for creating high quality Encapsulated Postscript, PDF, PNG, or SVG charts."
Here's a general purpose SVG library in Python: pySVG.
You can use Graphviz to generate diagrams in SVG format. There are Python bindings to Graphviz e.g., pydot -- Python interface to Graphviz's Dot language.
Consider svgwrite https://pypi.org/project/svgwrite, a Python package to create SVG drawings.
svgfig is worth a look:
http://code.google.com/p/svgfig/
Being not exactly related to SVG plots, but searching for the same thing I have found a good source of carefully collected useful info to answer your question:
http://wiki.python.org/moin/NumericAndScientific/Plotting
I have tried to collate a list of available charting libraries(its an ongoing work, wherein i keep updating the list) : http://blizzardzblogs.blogspot.com/2010/12/data-visualization-charts-and.html
I feel that protovis would do the job for you. Its
light weight,
generates svg (which can be exported easily) and
is javascript
So nothing more to learn :)
2018 Update:
Plotly ( https://github.com/plotly/plotly.py / https://plot.ly/d3-js-for-python-and-pandas-charts/ ) is probably the most versatile solution. It is distributed under MIT license (free to use and reuse), although it include features that might not be compatible with some CMS with more restrictive security issues since it relies on JS, although options to export the diagrams as plain SVG are also available.
Pygal ( https://github.com/Kozea/pygal / http://pygal.org ) is simpler relies only on svg standard. As such it's results are more reusable under more restrict CMS systems. It is distributed under GNU license.

Categories

Resources