Displaying vector files in QT using GDAL/OGR - qt

I am writing an application to load vector maps/shape files using gdal/ogr and display them onto a gui designed using Qt. I am new to dealing with vector files, I am not able to decide how to render them on GUI. Few approaches that come to my mind are:
- To convert vector files to raster and display them as raster..
- To draw each shape in vector file one by one (i dont know how to do this, I dont even know whether it would be even possible this using GDAL/OGR, or how complex this would be because in my case vector files can be very complex)
The decision how to render vector files is very important for me, because after displaying vector files i need to support some advanced features like projection change, interactive selection, Geo-referencing etc.
Can any one who has worked on vector/gis stuff, tell me how this is usually done and what Qt widget is used for displaying such data.

Displaying vectors is a tricky task since it requires rendering of geometries.
I would consider Quantum GIS (QGIS). It's actually also based on QT but comes with a sophisticated rendering engine. A custom QGIS application can even be run standalone.

I solved the problem of drawing vector files by writing rendering functions for each type of shape files. Qt's QPainter was really handy for drawing shapes like Polygon, Multipolygon, Line, Multiline and then displaying the output as QImage.

Related

How to create a SlotOfQImage in QT Rust?

I'm trying to define a custom QT Slot/Signal for passing a QImage.
I'm using qt_widgets crate which has many predefined slot types like SlotOfQIcon. However it doesn't have one for QImage. I've looked at the source code which is generated with this tool: https://github.com/rust-qt/ritual.
Is it possible to do this in regular Rust project without running complex multistage build involving code generation?
List of implemented slots for reference:
https://docs.rs/qt_widgets/0.3.0/x86_64-pc-windows-msvc/qt_widgets/
I've tried to copy paste generated code for other widgets and modify it, but it doesn't look like a right approach. I don't want to regenerate the whole library just for this case. Are there any simpler options?

Using Cytoscape.js for network visualization in Shiny

I am working on a web project for network visualization. I am writing my code in R using Shiny. And I want to display my graph using Cytoscape.js
I've searched the web for some kind of source code doing this. But I couldn't find anything. The webpage of Cytoscape.js is not enough for me cause I am not expert in js and can't use the examples.
Briefly, I have Adjacency matrix of my graph and want to use it with cytoscpae.js. Do you know any source code or a tutorial of the steps I should go through?
Cytoscape.js supports JSON for input, so as long as your R/Shiny code can produce that, you should be able to use Cytoscape.js. Here's the format described: http://cytoscape.github.io/cytoscape.js/#notation/elements-json
It looks like Shiny has a predefined set of widgets it supports, so there are a few options here:
(1) Shiny adds support for Cytoscape.js (e.g. https://github.com/cytoscape/r-cytoscape.js),
(2) A Cytoscape.js plugin is written for Shiny.
(3) You use JS for at least part of your app.
(1) and (2) will take more time than (3), so depending on your requirements, you may have to bite the bullet and use normal JS. When using a framework like R/Shiny without your own JS, you'll always be locked into whatever's supported and miss whatever's not -- so you lose on flexibility.
For very flexible and general interaction between R and Cytoscape.js, see the RCyjs project (docs)

Display a .dot file inside a Qt application

I am new to Qt and C++... Now, I am writing an application in Qt, in which I have to display an already generated .dot file inside my application. I tried the render function but did not work for me.. Can anyone out there help me in this regard..
Thanks
Had the same problem using Python. I came up with this solution:
svg_string = dot_graph.create_svg(prog='dot')
svgWidget = QtSvg.QSvgWidget()
svgWidget.load(QtCore.QByteArray(svg_string))
Guess you can do something similar in C++
Plotting directly a dot file requires to be able to display the nodes in the correct positions, and link them properly. This is done by very complicated engines and is not included in the dot file, which is simply a description of the graph. Maybe there are C++/Qt libraries that take dot files as an input, but I don't know them.
According to this topic (Graphviz: How to go from .dot to a graph?), you can easily transform a dot file into a png or svg file. If you want to display the rendered graph into your application, the easiest thing to do is to generate that png picture (from the shell or from your code) and to manipulate it from your program.
Take a look to QGraph. You will need much more work to make your graphs interactive.
Anyway, if you are new to Qt, even the simple display it's a steep introduction to graphics.
I have my own implementation, but I'm sorry it's not yet ready for publishing - I will do in a SWI-Prolog context...

Library or advise on plotting box nodes interactively

I'm building an application that parses text files that contain information about specific nodes with incoming ports and outgoing ports that are interconnected. Doing some research there are some libraries but none of them support the exact characteristics needed.
this is what I'm trying to build and any language will do: Python, Perl, .net, etc.
One of the libraries I have found is GoDiagaram Node Classes
http://www.nwoods.com/components/dotnet/features-nodes.htm
The idea is to have boxes like so, interconnected and I should be able to click on one of them and link it to a new sub-diagram with more boxes contained in the one clicked.
Is there a counter part of these kind of charts that is opensource? and do these diagrams have a specific kind of name?
I don't know any specific details, since I never looked into this too closely, but here are some potential directions:
The data structure used for representing something like this is usually a graph (probably a directed graph). You could also try searching for graphical (or visual) programming languages. I seem to remember Pure Data as one that was relevant, but I never looked at it in detail.
Blender and VirtualDub both have a mode that's similar to this (the node editor and audio filters, respectively) and I believe both are open source, although I think neither has the option of having the nodes contain other nodes internally.
You could just use LabVIEW, which gives you the ability to create and edit LV code programmatically (search for "VI scripting"), but the code for that might not be very pretty and it's certainly not open source.

saving a movieClip to disk as swf in air, then reading it again

i have seen almost all relevant threads on almost whole internet. and i m still confused..
i m working on a drawing app ( flex / air ),
1- where user loads image file,(bitmapdata > bitmap > movieclip base layer)
2- add layer ( new sprite > movieclip "second object in display list")
3- draw on this sprite ( graphics.draw circle / etc, lot of other details etc)
4- usr can add more layers etc, name layers etc ... all sprites are of same size as bitmap
Q1. now i wanted to save this main movieClip (part of UIComponent ) as swf file. so user can read again and continue work. almost like i do with photoshop.
comment: i know it sounds too generic, to ask such detailed thing. so please be patient..
i have been fiddling around with byteArray. and Air File Object, flash.net.fileReference etc...
Q2. (main question), i don't want to convert drawn sprites to bitmapdata and then do bytearray. ( in my mind) it will convert everything to pixels, which i don't want.
Q3. is there some auto magical line which will do everything..(save drawn vectors / shapes) in sprites as is?? (less chances). if i can read swf as movieClip, i can check sprites for layers and everything else... problem is writing this to disk as swf file.
please share your thoughts and feel free to guide,in all possible directions..
thanks in advance for your valuable time..
In an ideal world you would just write
YourByteArray.writeObject(YourCanvasSprite);
That doesn't work however since serialize only works with data that is readable and writeable (and public). So you need to make it possible to recreate the graphic. You might be able to simplify that by using IGraphics (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/IGraphicsData.html) as these should be possible to serialize. So if you subclass Sprite and store "drawing commands" and the parameters, and let the object have a restore function, it should be possible to save it to a byteArray. It's far from a one-liner though, but probably a little bit easier than making and reading SVG.
i'm thinking the cleanest solution to this problem would be to use SVG (maybe EPS). i'm unfamiliar with any library that will convert drawn vector objects into SVG, but since SVG is simply an XML file you could study the SVG architecture and create your own: W3C - Scalable Vector Graphics (SVG) 1.1 (Second Edition). the following open source project may help you write one and can also be used to read SVG into Flash: New Flex and Flash SVGWeb Components
a less clean, and perhaps more complicated way to solve this problem could be to write your own SWFs, as you mentioned. in order to do so you would have to generate .swf file at runtime, which you could accomplish by using NativeProcess to pass arguments (namely an ActionScript file containing your drawing information, child layers with names, etc.) to MXMLC from the Flex SDK.
i find both answers useful. and with time,i have realized that in both cases it might be more work than i can handle. meanwhile, i was testing other pixels bases approaches as well. so i finally took decision of going through pixel way. user can save layers as png files with transparency.
if some person (other readers) come to this post, i wanted to conclude quickly, i have found really valuable drawing library named "graffiti" for as3. it almost does 80% of things, which i was hoping to do. so i am using that and tweaking it for my needs. huge thanks and respect to all great ppl who replied from their valuable time..

Resources