On Sat, 10 Aug 2019 at 05:29, Israel Brewster <ijbrews...@alaska.edu> wrote: > > So using QGIS to convert my .shp files to .svg, and then loading the result > in a QGraphicsSVGItem works like a charm - thanks! The only drawback I’m > seeing is zooming performance. It *looks* good, but is a tad sluggish. When > using QGIS, I noticed that it was compiled against Qt as well, but when they > zoom, the actual image redraw is delayed until the zoom is complete. That is, > when zooming in, things get pixelated until you pause, whereupon they are > re-drawn correctly. The end result is that things look worse when zooming, > but zoom performance is lag-free. Is this behavior easily obtainable, such as > through a setting on the QGraphicsSVGItem or perhaps the QGraphicsView, or is > QGIS doing something completely different, such that I would have to do a lot > of re-implementation to accomplish said effect?
What QGIS is actually doing here is rendering the vector to a QImage in a background thread, and then when this rendering is complete the QImage is cached and used painted inside an item in the scene. Zooming triggers an update of the cached QImage from the vector content in the background, so you see the pixelated version temporarily until the new image is ready. This means the main GUI thread/scene is always responsive and isn't impacted by complex vector content. Unfortunately, it's not anything which can be achieved easily through the existing Qt API -- you'll need to setup the background thread and cached image updates yourself. The relevant code parts get a little tricky, because they rely on QGIS' map renderer, but look around: https://github.com/qgis/QGIS/blob/master/src/gui/qgsmapcanvas.cpp#L518 https://github.com/qgis/QGIS/blob/master/src/gui/qgsmapcanvas.cpp#L595 https://github.com/qgis/QGIS/blob/master/src/gui/qgsmapcanvasmap.cpp#L33 https://github.com/qgis/QGIS/blob/master/src/gui/qgsmapcanvasmap.cpp#L61 > When zooming out, areas that were outside the window remain empty until you > pause, at which point they are drawn. In recent versions we do things a little different, and: 1. render the visible portion of the vector to the cached image and show on the item as quickly as possible 2. trigger a separate background job when this is done, to render portions of the vector just outside the visible extent Again, this keeps the main view update as fast as possible, while giving nicer results when zooming out (less chance of missing image portions which were originally out of view). Hope this helps! Nyall > > --- > Israel Brewster > Software Engineer > Alaska Volcano Observatory > Geophysical Institute - UAF > 2156 Koyukuk Drive > Fairbanks AK 99775-7320 > Work: 907-474-5172 > cell: 907-328-9145 > > On Aug 8, 2019, at 8:19 AM, Francis Herne <m...@flherne.uk> wrote: > > You should definitely look at QGIS: > https://qgis.org/en/site/index.html > > It's open-source and has an excellent map-rendering implementation including > shapefile support. > > -Francis H > > ________________________________ > From: Israel Brewster <ijbrews...@alaska.edu> > Sent: 8 August 2019 16:55:49 BST > To: Brad Pepers <bpep...@me.com> > Cc: Interest <interest@qt-project.org> > Subject: Re: [Interest] Zooming with QGraphicsView/QGraphicsItem > > I do have .shp files for the coastlines - perhaps I could convert those to > something I could use? If I can get vector data, how would I go about > utilizing it? > > I played around a bit with loading different image files, but so far the > performance has been unacceptable - the entire app locks up for several > seconds when displaying the higher resolution images. I think Vector would be > a better way to go, if I can figure out how. Thanks! > --- > Israel Brewster > Software Engineer > Alaska Volcano Observatory > Geophysical Institute - UAF > 2156 Koyukuk Drive > Fairbanks AK 99775-7320 > Work: 907-474-5172 > cell: 907-328-9145 > > On Aug 7, 2019, at 10:12 PM, Brad Pepers <bpep...@me.com> wrote: > > In the end the answer is to get the coast as vector data instead of a raster. > The raster is going to be at a fixed map scale and any scale above or below > is going to extrapolate or interpolate the results eventually ending in poor > results because there just isn’t the information needed or too much > information is being lost. Having different resolutions should help and you > can keep multiple levels and switch between them at appropriate times (LOD). > Those are your best bets if you can’t get the actual vector data! > > -- > Brad > > > On Aug 7, 2019, at 12:01 PM, Israel Brewster <ijbrews...@alaska.edu> wrote: > > I have a QGraphicsScene/QGraphicsView that I am using to display a map (and > some data). The map is in the mercator projection, with the x and y > coordinates of the scene corresponding to map coordinates, so the background > images are rather large. Images are loaded into a QGraphicsObject which is > then added to the scene. The object types are defined by a third-party > library, so I don’t have the option of using different objects, such as > QGraphicsPixmapObject or something. > > This works fine when I’m zoomed in to the map. Coastlines are nice and sharp, > with no issues: > <Screen Shot 2019-08-07 at 9.50.10 AM.png> > > However, when I zoom out, the coastline becomes quite pixelated, and > difficult to see in places: > <Screen Shot 2019-08-07 at 9.50.28 AM.png> > > How can I fix this? My first thought was to change the size of the background > image so it could scale better, but that didn’t seem to help. In retrospect, > this makes sense: at the end of the day, the background image has to be the > correct size for the mercator projection, so while I can certainly change the > pixel density, the overall size, and thus how much scaling is needed to > display a given area, is fixed. > > --- > Israel Brewster > Software Engineer > Alaska Volcano Observatory > Geophysical Institute - UAF > 2156 Koyukuk Drive > Fairbanks AK 99775-7320 > Work: 907-474-5172 > cell: 907-328-9145 > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > https://lists.qt-project.org/listinfo/interest > > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > https://lists.qt-project.org/listinfo/interest > > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > https://lists.qt-project.org/listinfo/interest _______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest