Friday, May 30, 2014

GWR4: Software for Geographically Weighted Regression

Today, I will write about a free program that I think remains unknown to many people.  If you are interested in regression models, you will want to keep reading!

GWR4 was developed by the same scholars that created Geographically Weighted Regression (GWR) (Brunsdon, Fortheringham, and Charlton).  In brief, GWR runs local regression models on each geographic feature vs. ordinary least squares (OLS) regression which globally runs one model on all features.  In GWR, coefficient estimates are allowed to vary geographically and can be mapped.
  • Questions that GWR can help answer:
    • General: Do the effects of demographics race, income, education vary geographically on your outcome of interest, after statistical adjustment?
    • Specific:  Does the percent of smokers on prevalence of asthma vary geographically or stay the same? 
      • Since smoking is a major risk factor for asthma, we would expect all local coefficients to be positive--increasing the prevalence or risk of asthma.
GWR4 helps calibrate and run GWR Models. Moreover, it allows for models besides the normal/Gaussian distribution--such as Poisson (for counts and rates) and Logistic (odds).  For people interested in counts and rates, it is vital to be able to use the Poisson distribution.  Currently ArcGIS only uses OLS models.  GWR is a free program but is copyrighted.  It runs on Microsoft Windows.
"GWR 4 can be used to explore geographically varying relationships between dependent/response variables and independent/explanatory variables."
If you are still confused, click the map of Tokyo below--based on GWR4 and the sample data.  Hopefully, this will help clarify the significance of GWR models. (I ran out of time or I would have classified the layer better.  Keep in mind, odds  > 1 each unit increase in the unemployment rate is associated with higher mortality, odds < 1 each unit increase in unemployment rate is associated with lower mortality.)
Odds of the effects of the unemployment rate on mortality among the working age population.  Each of the 262 municipalities in Tokyo has an estimate of unemployment's contribution--adjusted for other variables in the model.
GWR4 has an intuitive user interface, good manual, and sample data with its associated publication. Your sessions/selections  of data, model, specifications, etc. can be saved by going to the file menu.  Be sure to check it out!

Visit here to download GWR4

GWR's Interface and Workflow: Load data->Identify Dependent and Independent Variables-->
--> Choose kernel, bandwidth, and selection criteria-->Output and Execute!

A quick note: I am taking a break from OpenLayers 3 (OL3) to wait for the final code, documentation, tutorials, and books to be completed.  However, we will return to OL3 later this year--when I also hope to have more examples.  Be sure to check out other JavaScript libraries to get maps on the web from Leaflet,  MapBox,  GoogleCartoDB, and any others I missed!  For more information on other similar projects visit the GIS StackExchange

Tuesday, May 20, 2014

An Introduction to OpenLayers 3, Part III

This week we will look at adding a Web Map Service (WMS) in OpenLayers 3 (OL3).

Adding a WMS
The code below illustrates how to add a WMS from the National Atlas.  Specifically, I pull from the data section on "people" and the layer named "fd0002_9" which is for Percent of Population that Receives Food Stamps, by County for 2002.  You can view this information on the National Atlas website or load the WMS through QGIS.  For the capabilities file and loading into a GIS, see:

Key parts of the code are emboldened in red.

   <!--Loads WMS Service from the National Atlas--People: FoodStamps, 2002//-->
   <!--Makes WMS layer transparent, so if can be overlaid on the OSM basemap//-->

 var wmsmap = new ol.layer.Tile({
source: new ol.source.TileWMS({
url: '',
params: {'LAYERS': 'fd0002_9',transparent:'true'},

A basic map is located here: A text file with the code: However, you won't be able to get any information when you click a county.

Adding Interactivity
In addition, OL3 allows information to be retrieved when a user clicks on a map.  See the more interactive example here: Attribute information will be returned in the green box.

Example of a Capabilities File for a WMS from the
It contains important information about the map layer/image.
This WMS is queryable (=1) so we can allow users to click an area and return information.  I had to change the INFO FORMAT to text/plain as outlined in the National Atlas's technical documentation.

Lastly, it is important to mention that the NationalAtlas is being merged into the USGS NationalMap later this year.  It is always possible the links for the WMS could change.

Next post: Adding a KML

Helpful OL3 API Docs

Saturday, May 10, 2014

An Introduction to OpenLayers 3, Part II

Last week, we created a basic web map by loading a basemap from OpenStreetMap using OpenLayers 3 (OL3).  If you missed last week's post, below are links to the code:
This week I will cover copying OL3's JavaScript libraries to a web hosting service. Also, note that you can run basic OpenLayers code off your computer--it simply depends on where the sources of data are located and how the code is written.

In order to get your map visible on the web, you will need a web hosting service or your own server.  After setting up an account, you will have a chance to upload files. Before that, there are a few things you need to know:
  • You will upload folders and files from the OL3 JavaScript library to the public or root directory of your web hosting service.  
  • In some cases, this is simply a matter of placing files in a folder; for some services you may have to set permission levels to public/everyone.
  • An additional step for uploading and accessing layers.
    •  In the next post, we will upload, use, and symbolize this uploaded layer.  
      • OL3 runs client-side (vs the server) so keep that in mind, so you won't want to use this method for large layers.
      • You don't need to do this step or the next one if you are accessing layers using a web map service or WMS.
      • Later I will also look at using GeoServer for more complex layers.
    • In addition, you will have to create a simple web config file to access files on your web hosting service. 
      • This can be done in a text editor, like Notepad. 
      • For example if you plan to use KML files, you will have upload a file with the following code for particular media or MIME types
      • Click to magnify the screenshot below for an example for a *.kml file.
You can find code for other MIME types by searching the web.
Save this code as web.config and upload to the root directory of your web hosting service.
After downloading and unpacking the *.zip file from OL3 (or OL2), you will see several folders and files. 
  • Consider copying all the folders and files over to see examples and understand how the code works
  • Keep in mind how you copy folders and files over, since this will affect how you write code and reference directories.
  • Lastly, the ol.js file you need is in the build folder.  In the first example that I showed (in the code above), you need to change the link to the OL3 website from "" to "build/ol.js."  The same goes for the css stylesheet.
Next time, we will look at uploading, using, and symbolizing a KML.

For serious developers, be sure to check out the OL3 wiki at: