Below you will find pages that utilize the taxonomy term “Qgis”
Conditionals in the QGIS raster calculator
I needed to do some conditionals in the QGIS raster calculator, but it doesn’t support that—or at least doesn’t seem to. But it does support logical operators, with a result of either 0 or 1. For instance, here’s the script I wrote:
# Subtract them ((DavisQuad2012-02-25T16_00_00Z@1 - DavisQuad2012-02-29T16_00_00Z@1)* # Multiply by 1 if neither is 255 (NoData), 0 otherwise (DavisQuad2012-02-25T16_00_00Z@1 != 255 AND DavisQuad2012-02-29T16_00_00Z@1 != 255)) # Subtract 32768 if either one was NoData, giving us -32768 for NoData. - (32768*(DavisQuad2012-02-25T16_00_00Z@1 = 255 OR DavisQuad2012-02-29T16_00_00Z@1 = 255))
Of course, you can’t actually put the comments in. But what it does is this: First, I subtract one raster from the other and multiply that by the logical operation that neither one contains NoData. That gives me the difference of the rasters, or 0 if either one contains NoData. Then I subtract 32768 multiplied by the inverse of the aforementioned logical operation, so any pixel with a NoData value in either of the original rasters is -32768 in the new one.
Conditional Labels in QGIS
I fairly commonly find myself in a situation where I would like to display one label for certain features and another for other features in the same layer. QGIS doesn’t have an official way to split labels up into categories, and until now I’d resorted to having two layers to render otherwise identical features. But, in the new, excellent expression based labeling from Nathan Woodrow, I realized one can use an SQL CASE statement. For instance, one time I need to use two types labels is when labeling roads in OpenStreetMap: I want to use the name tag, unless the feature has a ref tag defined (a name tag might be ‘Capital City Freeway’, while the ref tag would be ‘US 50’). Here’s how I solved that particular problem:
More Basemaps in QGIS
One of the more popular posts on this blog has been my piece on adding basemaps to QGIS. While the OpenLayer plugin is great, one of the things that I find dissatisfying is that it requires reprojecting your data to match the EPSG:3857 basemap. I often work in State Plane, and I’d just as soon have my data stay in that projection, which will also minimize local distortion. Well, as it turns out, one can add tiled map services as GDAL raster layers, with all the benefits that entails (e.g. reprojection). What you need to do is create an XML file like the following (which is lifted almost verbatim from the GDAL website, specifically this file):
Transit to Everywhere
Data courtesy MapQuest and OpenStreetMap CC-BY-SA, the City and County of San Francisco, and Bay Area Rapid Transit
This is an overlay of the transit and walking trip plans generated by OpenTripPlanner from Powell and Market to every other intersection in San Francisco, after Eric Fischer’s map of walking routes to every intersection in San Francisco. It brings out the transit routes but also shows well-used walking routes. The lines do not vary in width (don’t let Market Street fool you, it’s actually several lines—BART, MUNI rail in 2 directions, Muni bus, walking—very near each other). The lines fade where there are fewer routes using them, because they are rendered as black set at 10% opacity. Where there are more lines overlapping, the lines become darker, in what I believe is a log (or log-like) scale. It ended up just mostly being a map of San Francisco, with transit routes emphasized. It doesn’t show potential utilization of the transit system, because the routes are not weighted (it would probably be wise to weight the routes by the density of the block they terminate in and by their service area; i.e., estimate the number of people within the Thiessen polygon of each intersection and weight the route by that). Also, I had difficulty finding an opacity level where the usage of transit routes fades towards the end (as it clearly should) but still shows the streets that walked down by just one or two trip plans.
Accessing GTFS Data in QGIS
When you load GTFS data into PostGIS using gtfsdb, you can’t access that data in QGIS because the tables don’t have a primary key in int4 format (the primary key is in text format).
If your transit system uses numeric ids in text format, an easy fix is running this against each of your tables:
ALTER TABLE stops ADD COLUMN gid int;
UPDATE stops SET gid = stop_id::int;
ALTER TABLE stops ALTER COLUMN gid SET NOT NULL;
ALTER TABLE stops ADD CONSTRAINT stops_gid_uniq UNIQUE(gid);
What this does is creates an integer ID field, populates it with the stop_id (or shape_id, &c.) cast to an integer, then adds NOT NULL and UNIQUE constraints to the column. You can’t add the constraints beforehand, because the column is initialized to NULL values. Remember you have to run these commands against every table you want to pull into QGIS directly, and remember to change stop_id to shape_id &c.
Installing QGIS-1.7 on Fedora
The QGIS instructions for building from source are targeted at Ubuntu, but they translate fairly well to Fedora. Here’s a quick guide:
Instead of preparing apt as they say, use yum or Package Manager to install these packages:
- cmake
- bison
- flex
- grass-devel
- geos-devel
- PyQt4-devel
- gsl-devel
- qwt-devel
- gdal-devel
There may be few that I already had installed on my system and missed; if you run configure below and find missing dependencies, run yum search <whatever> in a terminal to look for it. Make sure you install any relevant -devel packages as well.
Blog to Watch: Under Dark
If you’re interested in Open Source GIS and especially QGIS, I highly suggest you give the blog “Under Dark” a read - the author seems to be very clued in the latest developments, and the blog is very active.
Basemaps in QGIS
**Update 2012-02-02 17:57 -0800:I just wrote a post about another way to do this.
I really like QGIS. It’s a powerful GIS that runs on Linux (among other operating systems) and doesn’t require incredible amounts of CPU. One criticism I had of it was that it did not provide the same ‘click-and-go’ basemap experience one can get with ArcGIS for making simple maps (i.e. Add Basemap, select Bing, DeLorme, &c. and you’re done). No more! Thanks to the qgis-openlayers plugin available on GitHub, you can now use OSM, Google Maps, Yahoo Maps and Bing Maps as base layers in your project (side note: make sure you don’t violate any copyrights by using them). I’ve had a little trouble with the projections, but I’m not that good with dynamic reprojection in QGIS yet, so I’m sure it’s my error.; Unfortunately, the layers don’t support reprojection, so your project is basically forced to use Google Mercator—which may be a showstopper but is often acceptable for quick maps (remember, QGIS can reproject your other layers). If you do want reprojection, see this post.