Skip to content

Instantly share code, notes, and snippets.

View rbanick's full-sized avatar

Robert Banick rbanick

  • Arbol
  • Ciudad de México, México
View GitHub Profile
@rbanick
rbanick / QGIS_Advanced_Atlas_Techniques.md
Last active March 5, 2024 09:06
QGIS Advanced Atlas Techniques

Background

QGIS's Atlas feature and ArcGIS's Data Driven Pages allow you to create a series of maps, one per geography, based off a single map style. Titles, labels, and styles within the maps can be created based on the attributes of key layers and/or the scale of the map, imparting some customization and flexibility to an otherwise automated process. Atlas geographies can be points, polygons, and scales can be adjusted.

But what if you want to create multiple maps for a single geography, or multiple maps for multiple geographies? How can you vary not just the extent but the contents of what's shown?

This walkthrough will detail two complementary methods for filtering the display of datasets across multiple geographies using QGIS's Atlas Tool. This is a deep dive into a few specific Atlas techniques that I thought were poorly documented elsewhere and useful, not an exhaustive guide to the Atlas Tool. I have no idea if any or all of these techniques can be replicated using ArcGIS's Data Driven Pages.

@rbanick
rbanick / comparison_query.sql
Created August 30, 2016 10:53
comparing OSM to survey data
CREATE TABLE comparison AS
select aug29_clean.cluster,
count(*) as total,
sum(case when aug29_clean.b_materials=exposure_matching.b_materials then 1 else 0 end) as building_materials,
sum(case when aug29_clean.b_levels=exposure_matching.b_levels then 1 else 0 end) as building_levels,
sum(case when aug29_clean.b_category=exposure_matching.b_category then 1 else 0 end) as building_type,
sum(case when aug29_clean.b_foundation=exposure_matching.b_foundation then 1 else 0 end) as building_foundation,
sum(case when aug29_clean.b_age=exposure_matching.b_age then 1 else 0 end) as building_age,
sum(case when aug29_clean.r_shape=exposure_matching.r_shape then 1 else 0 end) as roof_shape,
sum(case when aug29_clean.r_materials=exposure_matching.r_material then 1 else 0 end) as roof_materials
@rbanick
rbanick / omk_manual_data_extract.sh
Last active August 24, 2016 10:22
extracting data manually from OMK server
# easy way
https://github.com/AmericanRedCross/OpenMapKitServer/blob/master/docs/api.md
and then
http://everygoodusernameistaken.tumblr.com/post/52805666711/exporting-openstreetmap-roads-to-shapefile
# longer way
## tar the folder
-- You update the SRID for your table first. Then you reverse that update within a SQL query so you can transform the actual coordinates to their new EPSG.
-- Otherwise you'll have Lat/Long coordinates for a metric projection or vice-versa.
SELECT Updategeometry_columnetrySRID('table','geometry_column',new_EPSG);
ALTER TABLE table
ALTER COLUMN geometry_column TYPE geometry(geometry_type,new_EPSG) USING ST_Transform(ST_SetSRID(geometry_column,old_EPSG),new_EPSG);
SELECT ST_AsText(geometry_column) FROM table;
@rbanick
rbanick / find_and_match_omk.py
Created March 11, 2016 12:41
Matching OSM files to corresponding OpenMapKit surveys
import os
import fnmatch
import json
import shutil
source_folder = 'your/survey/folder/directory'
osm_files = '/your/osm/files/folder'
fixed_folders = '/where/to/put/rescued/survey/folders'
def out(f, arr, name):
@rbanick
rbanick / field_mapping_process.md
Last active December 7, 2015 09:52
Field Mapping Process, Sri Lanka

Field Mapping Order of Operations

Attanagalu Oya Project, Sri Lanka

  1. Select your area to cover and prepare a base map of that area in QGIS (to capture admin boundaries not in OSM).
  2. Prepare field papers for this area.
  3. Do one day pass through the area with field papers and GPS, mapping only roads, landuses, major points of interest and other features that will help orient map users.
  4. Input this data into OSM.
  5. After the data has been synchronized and reflected in the OSM map, prepare new Field Papers, OMK maps and OMK data after the data has been processed and the OSM map updated (this may take several hours).
@rbanick
rbanick / qgis_atlas_techniques.markdown
Last active February 2, 2024 16:33
QGIS Atlas Techniques

QGIS Atlas Techniques

Basics

Creating an Atlas Layer

  1. Create a shapefile that includes ONLY the features you want to create an atlas of (e.g. only the districts you want maps of)
  2. Open a new print composer. Give it a name you can remember, like 'Atlas'
  3. Go to the 'Atlas Generation' tab and check the box next to "Generate Atlas".
@rbanick
rbanick / 0_reuse_code.js
Last active August 29, 2015 14:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@rbanick
rbanick / generic_sql_gis_aggregation.sql
Last active August 29, 2015 14:24
Generic SQL aggregation
## create summary table
CREATE TABLE temp_table AS
(select
count(id) AS features_per_ADMIN,
avg(master_table.thing_to_average) AS avg_thing_to_average,
sum(master_table.thing_to_sum) AS sum_thing_to_sum,
count(master_table.thing_to_count) AS count_thing_to_count,
COUNT(DISTINCT master_table.thing_to_count_distinct) AS cntd_thing_to_count_distinct,
## ...add as many summary fields as you want here
@rbanick
rbanick / intersects.sql
Last active August 29, 2015 14:23
Creating intersects in PostGIS -- chitawan example
#### getting intersects of roads from a district. To eliminate bordering things using ST_Contains
DROP TABLE chitawan_roads_intersect;
CREATE TABLE chitawan_roads_intersect
WITH (OIDS)
AS
SELECT osm_roads_4326.*
FROM osm_roads_4326, districts
WHERE