Welcome, Guest. Please login or register.
Did you miss your activation email?
November 22, 2017, 08:56:06 pm
HomePredMockPollEVCalcAFEWIKIHelpLogin Register
News: Please delete your old personal messages.

  Show Posts
Pages: [1] 2 3 4 5 6 ... 448
1  Presidential Elections - Analysis and Discussion / 2016 U.S. Presidential Election Results / Re: Primary Election Map by Congressional District on: November 21, 2017, 08:52:19 am
I'm working on making something right now.  I don't know how to upload images to this site though.

If you have enough posts, you can click on Gallery and upload your images there. Then, click on the image and cut and paste the bbcode url to post it.
2  Presidential Elections - Analysis and Discussion / 2016 U.S. Presidential Election Results / Re: Delaware Precinct-Level Results on: November 21, 2017, 08:49:16 am
Just noticed something about Ryne's precinct map. The boroughs of Alaska are outlined... he has data for the boroughs/counties of Alaska. I can't find that anywhere online. Why hasn't someone compiled that to make a 2016 results map for Alaska by borough/census area?

Alaska doesnít break down their early/absentee/questioned votes by anything but Alaska House District, and Alaska House districts cross borough/census area lines. Thus, any 2016 results map youíd see is either of the election day vote only (which tends to skew more R than the early vote) or an unscientific estimation of the early/absentee/questioned votes. Ryneís map is of the precinct vote, so itís the election day vote only. Technically, even a few precincts cross borough lines.

In any event, others and I have done estimates of the 2016 and prior year results by Alaska County Equivalent is here. Thereís a link to prior-year estimates, too.
3  General Politics / Political Geography & Demographics / Re: Newberry Atlas of Historical County Boundaries Shapefiles in QGIS? on: November 07, 2017, 12:43:44 pm
Thanks for the help, the Monopoly reference really helped! I would like to put together a county map for every census, at least that's the goal right now.

You can do that by changing the START_N and END_N to the relevant census date for each decade. It wasnít always April 1. Iíd save the new layers as a vector file each time, instead of in memory, then.

I think the START_N and END_N dates are in YYYYMMDD format, but you should check the Readme file that came with the Newberry package.  

You can thank jimrtex for the monopoly reference.

4  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 07, 2017, 01:29:35 am
(6) Save the layer to disk. Give it a name like Alaska_Counties. Be sure to browse to the directory where you are going to save the file and be sure the format is ESRI Shapefile

You probably should explain how to do this - Right Click on the layer name and Select "Save As" or Layer-->Save As.

I don't see any button on the toolbars to save a layer, but I tend to keep toolbars off unless I need them. I'd rather have the maximum map on the screen to work with.
5  General Politics / Political Geography & Demographics / Re: Newberry Atlas of Historical County Boundaries Shapefiles in QGIS? on: November 06, 2017, 11:59:22 pm
With a little bit of auto-coloring, you can make your map and legend look like this, instead:



The next installment on the QGIS How To will be how to auto-color and change styles.
6  General Politics / Political Geography & Demographics / Re: Newberry Atlas of Historical County Boundaries Shapefiles in QGIS? on: November 06, 2017, 11:08:25 pm
Neat database, by the way. Using the method described above, I made this map showing the state and county boundaries as of September 3, 1783:



Edited to add: I guess Vermont technically wasn't a state then, though. It was the Republic of Vermont. And Maine was part of Massachusetts.
7  General Politics / Political Geography & Demographics / Re: Newberry Atlas of Historical County Boundaries Shapefiles in QGIS? on: November 06, 2017, 08:29:11 pm
What are you trying to do?

If you're trying to get a map as of a certain date, do the following:

Hit the Connecticut Avenue Monopoly card icon, AKA Open Attribute Table.

On that dialog, hit the icon that looks like a funnel, a.k.a. Select features using form (or hit CTRL-F).

To make a map of counties as of January 1, 1776, scroll down to START_N. Type in 17760101. In the drop-down menu immediately to the right, select "Less Than or equal to". Enter the same date (17760101) in END_N and select "Greater Than or equal to".

Hit Select Features.

I don't have my editing toolbar enabled right now, so what I'd do is hit "Edit" on the top menu, then "Copy Features" (Or hit CTRL-C), then "Paste Features--> As a temporary scratch layer" and give it a name, "1776 NC Counties" or whatever. You can save it as a vector layer now, too, if you want something permanent. If your edit features toolbar is active, there's probably a shortcut. I don't know it off the top of my head.

You should now have a map of the counties as of 1776 in the new layer. You might need to deselect the NC Historical Counties layer to see it (uncheck the box next to it).
8  About this Site / The Atlas / Re: Color Code for Turnout? on: November 05, 2017, 11:05:40 pm
Thanks, although with population having 12 different colors, I'm not exactly sure what numbers to use for it. Do you just lob off the bottom two colors and use the other ten?

I'm not sure. The map generator has different numbers for population, too.

I suppose you can always use all 12 and just update your legend to reflect what the colors represent.
9  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 05, 2017, 10:41:35 pm
QGIS Style Files:
(1) Atlas 7Color Scale
(2) Water
(3) Boundary Yellow
A tutorial explaining how you generated these would be useful.

Thatís in the works.

Quote
Quote
(2) If you've saved your project from the last lesson, open it. Otherwise:
(2a) Open cb_2016_us_county_5m.shp
(2b) Open gpr_000b11a_e.shp
(2c) In the layer panel, rename cb_2016_us_county_5m "County"
(2d) Rename gpr_000b11a_e "Canada".
(2e) Change the projection to Alaska_Albers_Equal_Area_Conic
(2f) Select the Zoom tool from the toolbar and draw a box around Alaska. You needn't include all of the Aleutians.
If you don't know how to do any of these steps or need the shapefiles, read the prior lessons.
I never rename source shapefiles. The census files at least are easy to understand what they are. You haven't actually changed the file by renaming the layer, but it might give the impression that you are.


You have to rename the layers if you use the QGIS print composer. Otherwise, the legend will have the Census Bureauís name instead of something describing what the color/lines depict. Plus, since Censusí names are very long, not changing them makes the legend a lot wider than it need be.

Iíll mention you havenít actually changed the filename, just the name in the Legend Panel when I revise things again.  Iíll also take your suggestions for rewriting the first part into account and put in a GOTO description.

I think weíre just going to disagree on whether to include multiple races in the same spreadsheet. My spreadsheets generally include multiple races and even multiple years. Itís much easier to compute things like swings and PVIs that way. Yes, we can do that in QGIS by creating a new column, but I find it easier to do math in Excel instead of QGIS.

One thing I havenít tried to figure out yet is what happens if you try to import and join an Excel spreadsheet with multiple sheets. Does it import all the sheets or just the first? Iíll have to test that and get back.

Quote
I have a Data tab, but still don't see Remove Duplicates.

That's bizarre. I don't think I modified the Excel ribbon at all. The data tab in both my Excel 2007 and Excel 2016 have a Remove Duplicates button. Try right clicking on the Ribbon, selecting Customize the Ribbon and looking for the "Data Tools" group under Commands Not in the Ribbon. Remove Duplicates is in that group.

If its not there, perhaps it's in the Analysis ToolPak add-in, which I have enabled?
10  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 04, 2017, 10:52:53 pm
What are WINCODES? It would help me know what you are trying to make your xlsx file look like, and what you are ultimately try to produce. It would help to know what your shapefiles contain since we are trying to match them.

Particularly for exemplary purposes, I would focus on a single race. If you want to compare different results, you can always do multiple joins. I would have kept the Absentee, Questionable, and Early Voting separate by legislative district. Since Alaska does not attribute these votes back to election precinct, and they represent about 1/3 of votes, I would do an analysis of how these results varied by legislative district (e.g. share of in person votes, whether different types of votes were politically different. It might be possible to adjust the precinct in person votes. At minimum, you could aggregate results by legislative district.

I'll add a sentence describing WINCODES. It's already explained more in part two - In order to match the relevant QGIS winner color, we need to add an integer to the percentage of all those who won a precinct except Republicans (since the R color is in the 0-1 range). For example, a D winner has to have 2 added to their percentage if they win a precinct to generate a red color in QGIS using the 7 Color scheme.

I checked the shapefile before determining whether I had to truncate the precinct code. A link to the relevant shapefile is in Part 3 of the discussion. Unfortunately, the full precinct names from the Alaska Precinct shapefile are in terrible shape - some are capitalized, some have extraneous spaces, etc. I couldn't do a join on that column (NAME) without getting NULLs.

I wasn't planning on using the data to sum up the results by House District. You're right - that can be another lesson. I suppose we can do the remove duplicates first and then create a Precinct column in Sheet1 instead of doing it on the Data sheet. I'll rewrite the write-up to do that.

I like to have all of one year's data in the same spreadsheet without doing multiple joins. One of the purposes of the exercise was to show how to change variables and generate a new map in the print composer in Part 4.

Quote
Quote
--Snip--

(3) The Text Import Wizard should open up.
(3a) Select the circle next to Delimited. Hit Next.
(3b) On the next screen, click the box next to Comma. Unclick any other boxes that might be checked. Hit next.
(3c) On the final screen, General format is okay for this exercise. Hit Finish.

Your data should now be imported into Excel.
If you save the precinct results as a .csv file, you can open them directly in Excel. Note that "circle" is called a "radio button"

OK
Quote
Quote
--Snip--
(5) We might need to separate the precinct number from precinct name to match the data in the Alaska precinct shapefile. Luckily, all precinct IDs are 6 characters.
(5a) In cell G1, Type =LEFT(A1,6)
(5b) Copy that formula to the bottom of the data.

I'll let you in on a little Excel shortcut on how to more quickly do this in a spreadsheet with over 50,000 lines: Hit CTRL-C to copy cell G1. Go to column A or the neighboring column F and press CTRL-Down Arrow to get to the bottom of the entries in that column with text. Be a little careful: there could be empty records, so you might need to do that more than once. Once at the true bottom, use the Right Arrow to scroll back to the cell on that line in blank Column G. The first box on the Function toolbar should now say G56184. In that box, type "G2:" before the G56184 and hit enter. That should create a box from G2 to G56184. Hit CTRL-V.
Possibly premature to extract ID's, since this is where we merged all of the absentee, questionable, and early votes into a pseudo precinct called "Distri". If we kept them separate, we could create precinct IDs like 40-ABST, 40-QUES, 40-EARL which could then be aggregated into totals for the legislative district. It doesn't matter if not all data can be joined. Note, there are ways to check when there are shapefiles, but with no data to join with them.

If I had done it your way, I would type: "=LEFT(", then click on cell A1, and then typed ",6)" at the point where you select A1, press function key F4 and you can cycle through various absolute and relative expressions. $A1 might be a little bit better if you were going to also fill in columns to the right.

I would then do a GOTO  (G1:G56184) and pressed CTRL-D to fill down. CTRL-R fills right and you can fill up or left from the Fill command.

You could also do a CTRL-End to get to the end of your worksheet, click on G56184 (i.e. last row) and then SHIFT-CTRL-UPARROW to select the entire column followed by CTRL-D.
What's a GOTO?

That is how I generated the formula - moused over to A1, then hit 6. I wasn't planning on adding any additional columns, so I didn't see the need to cycle through the relative values (in fact, I didn't even know <F4> did that - I usually just manually type the dollar signs.

CTRL-End, Shift-Ctrl-Up Arrow, CTRL-D seems to work.
Quote
--Snip--
(6d) On the top ribbon, Select Data-->Remove Duplicates. Hit OK. Duplicates have been removed.
(6e) Insert a new row 1. This can be done by clicking on the row number (1), then RIGHT clicking and selecting Insert.
(6f) Type "Precinct ID" in cell A1.
I couldn't find Select Data-->Remove Duplicates.  Instead I clicked on the light bulb and typed "Remove Duplicates" and a menu popped up.[/quote]

I knew I should have put a few pictures in this discussion. I also miscapitalized "Select". I'm using the newest version of Excel. It has a Data tab on the top ribbon. If you click on that, there's a Remove Duplicates icon.  I'll add a picture to explain.

Quote
Quote
Next, we'll calculate the number of votes each candidate in the 2014 Senate, House, and Governor's race received in a format that can be more easily joined with the shapefiles:

(7a) Type the following headers in Cells B1-O1

Begich, Mark    Fish, Mark S.    Gianoutsos, Ted    Sullivan, Dan    Write-in 70    Dunbar, Forrest    McDermott, Jim C.    Young, Don    Write-in 50    Clift/Lee    Myers/Rensel    Parnell/Sullivan    Walker/Mallott    Write-in

I got these by cutting and Pasting Special TRANSPOSE (Right Click T or hit theThe Clipboard with round arrow) the the names of the Senate, House and Gubernatorial Candidates from the prior spreadsheet. You can, too. Exact names make it easier to do the =sumif function described below.

(7b) Type the following formula into Cell B2:
=SUMIFS(Data!$F$1:$F$56184,Data!$C$1:$C$56184,B$1,Data!$G$1:$G$56184,$A2,Data!$B$1:$B$56184,Data!$B$3)

Formula explanation:
-Data! Column F is the number of votes that need to be summed. That goes first in a =SUMIFS function, but last in a simple =SUMIF function.
-Data! Column C is the Candidate Name. It gets compared to the candidate name in the header row of this sheet.
-Data! Column G is the Precinct Number. If gets compared to the Precinct Number in Column A of this sheet.
-Data! Column B is the office name. It gets compared to the office name the first time it appears on Data! B for that race. We're going to have to change the last variable when we cut and paste it for the House and Governor's Race. I'd go with two header rows to include this variable, but that might mess up the join in QGIS. And typing the name isn't necessary.

(7c) Copy this formula to Cells C2-G2.
(7d) Change "Data!$B$3" to "Data!$B$12" in G2.
(7e) Copy Cell G2 to Cells H2-K2.
(7f) Change "Data!$B$12" to "Data!$B$20".
(7g) Copy Cell K2 to Cells L2-O2.
(7f) Copy cells B2-O2 to row 443.

After a few seconds, the data should update. At this time, it's probably prudent to make sure the precinct results matched the actual results.
I would have entered in B2

=SUMIFS(Data!$F$1:$F$56184,Data!$C$1:$C$56184,Sheet1!B$1,Data!$G$1:$G$56184,Sheet1!$A2)

And then used CTRL-R and CTRL-D to copy across and down. I had not understood why you also select on the Office because of the weird way they did write-ins. When I went back to correct for the write-ins I added the Office criteria for only the write-ins.

You like CTRL-R and CTRL-D. I prefer CRTL-C and CTRL-V. I suppose CTRL-R/CTRL-D saves a keystroke. I'll add alternative keystroke instructions.

Quote
Quote
(8a) Type "Total" in Cell A445.
(8b) Type =SUM(B2:B443) in Cell B445.
(8c) Copy the formula in B445 to Cells C445-O445.
(8d) Check the totals against the official total election results on Alaska's website. That's available here.

This step matters. When I did this the first time, I noticed the write-in totals were off for some races without adding the race name variable to the =SUMIFS function.
This is critical. You'll never quite figure out the format that was used (Alaska included results for Senate District 5, rather than Senate District S). Not only did I not have the write-ins, I didn't understand that the "Distri" results were not district totals and repeated.

I've never found a simple way to do partial transposes. You might write a script, but by the time you got it working, you could have used a more brute force method. If every state used the same format, it might work to develop a more automated way.

Amother approach would be sort by Office, Candidate, and Precinct. You could then just copy the column for each candidate. If I did this, I would double check that the precinct order was the same for each column.

Quote
Assuming everything checks out correctly, we're ready to compute Wincodes. Before you do that:

(9a) In Cell A1, Select All (Hit CTRL-A).
(9b) Copy that data.
(9c) Open a new blank spreadsheet.
(9d) Paste VALUES in Cell A1 of the new blank spreadsheet.
(9e) Save this spreadsheet as "AK2014 Tutorial" in Excel format.

This is very important step. We want the data in this format, as if the state had provided it this way. You might want to start this tutorial showing the desired end result. The rest is not necessarily showing how to do it, but to suggest a way short of timing in all the results by hand, which would discourage the attempt. Someone reading the tutorial could then skip to the next message.
OK
11  About this Site / The Atlas / Re: Color Code for Turnout? on: November 04, 2017, 04:47:12 pm


I think the turnout key is the same as population.

Edit: See also the County Map Generator for the extended key that I used as the basis for my QGIS 7ColorCode style. It gives you the HTML notation for each color.
12  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 04, 2017, 04:12:47 pm
Calculating Wincodes Part 5 - Making an Inset Map in the Print Composer

The precinct map of Alaska is nice and all, but it really emphasizes rural areas at the expense of populated cities, like Anchorage. We can use the print manager to draw an Anchorage inset map. It's easier than you think.

(1) Open the Alaska print composer (if you're continuing the lesson immediately after completing Part 4, just select the print composer in Windows, otherwise open your project in QGIS and select Project-->Print Composers-->Alaska.

(2) In the print composer, select Composer-->Duplicate Composer from the drop down menu. You can also click on the icon that looks like a white piece of paper on top of a grey one with an orange star. (It's probably the 2nd icon to the right after the save diskette.) See the image below if you can't find it:



(3) Give your new composer a name: Alaska with ANC Inset.

A new print composer should pop up.

(4) Go to your main QGIS screen, select the plus magnifier icon, and draw a box around Anchorage. If you don't know where Anchorage is, it's in South Central Alaska. Your zoom should look something like this:



(5a) Open up the print composer. Create a new map by hitting the new map icon. (If you don't remember which that is, it's marked as 5 in the image under step 2.)
(5b) Draw a rough square somewhere where there's free space on the map. I drew mine in the crook between Kodiak Island and the map scale.

A new map, Map1 should pop up. Map0 and Map1 are confusing names, so:
(6a) Double click on Map0 in the Item pane. Change the name to Alaska.
(6b) Double click on Map1 in the Item pane. Change the name to ANC Inset.

Now, we're ready to make the inset:
(7a) Select the Item properties tab underneath the Item pane for ANC Inset if it isn't already.
(7b) Under extents, hit the Set map to canvas extent button

The inset is probably not as zoomed in on Anchorage as it could be:

(7c) Play around with the coordinates under extents until Anchorage fills the inset. I used the following coordinates:
X Min: 200000
Y Min: 1200000
X Max: 300000
Y Max: 1290000

(7d) Move the inset to make sure it's not obscuring Kodiak Island or other parts of the map, including the scale. Make sure it is aligned with the bottom of the page (a red line should come up when it is).

(7e) If you need to make the inset smaller or larger, click on the upper left corner and move diagonally.

(7f)  Open the Position and size menu on the Items tab. Click the bottom center square next to Reference Point.

Next, we'll add a title to the inset:

(8a) Click on the add text icon. It's the piece of paper with a T.
(8b) Draw a rectangle above your inset.
(8c) Type "Anchorage" or "Anchorage Inset" in the box under Main properties.
(8d) Change the font as you deem fit. I used MS Shell Dig 2, Bold, 12 pt.
(8e) Open the Position and size menu on the Items tab. Click the bottom center square next to Reference Point.


(9) Add a scale bar, if you want, by clicking on the Anchorage Inset map, then the scale icon, drawing a rectangle, and following the instructions in the basic print composer tutorial. It's probably unnecessary.

No new legend is necessary, as Anchorage is included on the main map, and the color scale for precincts in the Anchorage inset are already included.

(10) Export your new map as an image by hitting the Export image icon.

That's it! You've made a map with an inset! It should look something like this:



Like the main map, the inset map can be easily updated when you change variables. Just remember to hit the Update preview button on BOTH maps - but everything should auto-update when you save as a png file, anyway.

Remember to save your project!
13  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 04, 2017, 03:27:06 pm
Damn, this is pretty awesome of you to do. I've always wanted to learn how to use QGIS.

Thanks! Also see jimrtex's excellent Hudson QGIS thread from last year to learn some more advanced editing features of QGIS.
14  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 04, 2017, 12:11:34 pm
Calculating Wincodes Part 4 - Using the QGIS Print Composer to make multiple maps

(1) Open QGIS and load the project from Step 3.

(2) Open the Print Composer you created in the Using the QGIS Print Composer Lesson. Assuming you named your last print composer Alaska, select Project-->Print Composers-->Alaska.

That will open up your print composer in a new window. The map may or may not have auto updated. To update the map:

(3) Highlight map0 in the Items Pane, select the Item Properties Tab below (if it's not open already) and hit "Update preview".

We need to change the title of the map:

(4a) Select the item that says "Relative Population Chang...." or "QGIS" in the item pane.
(4b) Under Main Properties, delete the text in the box and type "2014 U.S. Senate Results by Precinct"

The legend should have auto-updated. If not:

(5a) Select Legend in the item pane.
(5b) Under Legend Items, toggle the Auto update box on, off and on again.

(6) Print your map by hitting the mountain image icon on the top of the screen.

That's it.

Now, we can easily change the variable mapped.

(7) Open your main QGIS screen.

(8a) Select Precinct in the Layer Panel.
(8b) Right click on Precinct and select Properties.
(8c) Select Styles from the menu on the left of the popup dialog.
(8d) Click on the drop-down menu next to column. Change Senate Wincode to House Wincode.
(8e) Hit okay.

The colors on your map should change. In general, it should look more blue because Republican Don Young won more precincts in the House race than Dan Sullivan in the Senate Race.

(9) Open the Print Manager window.

(10) Highlight map0 in the Items Pane, select the Item Properties Tab below (if it's not open already) and hit "Update preview".

We need to change the title of the map:

(11a) Select the item that says "2014 U.S. Senate Results...." or "QGIS" in the item pane.
(11b) Under Main Properties, delete the text in the box and type "2014 U.S. House Results by Precinct"

The legend should have auto-updated. If not:

(12a) Select Legend in the item pane.
(12b) Under Legend Items, toggle the Auto update box on, off and on again.

(13) Print your map by hitting the mountain image icon on the top of the screen.

Try to do the same for the Governor's race on your own. The relevant variable is Gov Wincode. Your map should be green and blue since there was no Democrat in the race.

That's it! It's pretty simple, right? As always, remember to save your project.
15  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 04, 2017, 11:42:35 am
Calculating Wincodes Part 3: Drawing a multiple layer precinct election map in QGIS.

Now that we have our 2014 Alaska election data in order, it's time to make maps with it. For this exercise, you'll need the following additional items:

Shapefiles:
(1) Alaska's Precinct Shapefile
(2) My shapefile of Alaska's Coastal Water Features, AlaskaBays.zip

These two items should be unzipped and put somewhere on your computer where you can find them. I have a separate folder for each state's GIS files, but I do a lot of mapping. Putting all your GIS files in one directory should suffice.

QGIS Style Files:
(1) Atlas 7Color Scale
(2) Water
(3) Boundary Yellow

And if you haven't completed steps 1 and 2, you'll need the following Excel File:
AK2014 Tutorial Full

Let's get started.

(1) Open QGIS.

(2) If you've saved your project from the last lesson, open it. Otherwise:
(2a) Open cb_2016_us_county_5m.shp
(2b) Open gpr_000b11a_e.shp
(2c) In the layer panel, rename cb_2016_us_county_5m "County"
Note: This doesn't change the underlying file name, just the name in the Layer Panel. The layer name is used when the print composer auto-makes a legend - though you could separately rename the shapefile name only in the print composer, if you wish.
(2d) Rename gpr_000b11a_e "Canada".
(2e) Change the projection to Alaska_Albers_Equal_Area_Conic
(2f) Select the Zoom tool from the toolbar and draw a box around Alaska. You needn't include all of the Aleutians.
If you don't know how to do any of these steps or need the shapefiles, read the prior lessons.

(3) Open 2013-SW-Precinct-Proc-Plan.shp, the Alaska precinct shapefile. Rename it "Precinct".

(4) Open AlaskaBays.zip. Rename it "Water".

Your screen should look something like this.



Let's start coloring the various layers from bottom up using styles:

(5a) Select County in the Layer Panel.
(5b) Right Click and select Properties.
(5c) Select Style from the menu on the left of the popup dialog if it isn't already selected.
(5d) Click on Style on the bottom of the dialog. Select "Load Style" and Load Boundary Yellow.qml.
(5e) Hit Okay.

Because County is on the bottom in the Layer Panel, the only change you should see is that the county labels are gone. In QGIS, layers at the top of the layer panel are the top layer on the map. In order to see the County lines:

(5f) Select and drag County to the top of the layer panel.

Your map should now look something like this:


We need to join the data to the Precinct shapefile before we can color it, so:

(6a) Add 2014AK Tutorial Full.xlsx (or whatever you called your file from Step 2 of the previous tutorial) as a Vector File. (Hit the V icon on the left of the screen. If your Excel file doesn't show up in the file browser, make sure All Files or MS Office Open XML Spreadsheet is selected in the drop-down menu next to filename.)
(6b) Select Precinct in the Layer Panel.
(6c) Right click on Precinct and select Properties.
(6d) Select Joins from the menu on the left of the popup dialog.
(6e) Hit the plus button on the bottom of the dialog to add a join.
(6f) Make sure the following are selected in the popup's pull-down menus:
Join Layer: AK2014 Tutorial Full Sheet1 None (or whatever the just-added data layer is called on your computer)
Join field: Precinct ID
Target field: District
(6g) Check the box next to Custom field name prefix and delete the text in it.
(6h) Hit OK.
(6i) Check to see that the Join worked by clicking on the Connecticut Avenue Monopoly Card icon and making sure there are numbers in all of the columns. Assuming the join was successful:
(6j) Select Precinct in the Layer Panel.
(6k) Right click on Precinct and select Properties.
(6l) Select Styles from the menu on the left of the popup dialog.
(6m) Click on Style on the bottom of the dialog. Select "Load Style" and Load 7ColorScale.qml.
(6n) Click on the drop-down menu next to column. Change WINCODE to Sen Wincode.
(6o) Hit OK.

Your map should now look something like this:



Finally, we need to change the water color, using the Water style. Try doing this on your own. If you're lost, all you need to do is the following:

(7a) Select Water in the Layer Panel.
(7b) Right click on Precinct and select Properties.
(7c) Select Styles from the menu on the left of the popup dialog.
(7d) Click on Style on the bottom of the dialog. Select "Load Style" and Load Water.qml.

Your map should look something like this:



Congratulations! You've made a precinct map of the 2014 Alaska Senate Election! Save your project (or save as under a different name, if you want to save each lesson separately).

If you want to print a simple image of your map, you can select Projectó> Save an Image which creates a png file of the map window. Otherwise, please continue to the next part of this lesson, where I will show how easy and quick it is to make multiple professional-looking maps using QGIS' print composer.
16  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 04, 2017, 01:11:29 am
Calculating Wincodes - Part 2: Calculating Wincodes in Excel

If you completed Part 1 on your own, you can use that file. Otherwise, you'll need to download the following Excel file for this part of the exercise:

AK2014 Tutorial.xlsx

The spreadsheet contains precinct-level results for the Alaska's Senate, House and Gubernatorial Race in the 2014 General Election. We need to manipulate the data to create Wincodes:

(1) Add the following titles in Cells Q1-V1:
Senate Total   House Total   Governor Total   Sen Wincode   House Wincode   Gov Wincode
(2) Type the following =SUM functions to add up the votes in each race:
(2a) Cell Q2:
=SUM(C2:G2) | Sum of Votes in Senate Race
(2b) Cell R2:
=SUM(H2:K2) | Sum of Votes in House Race
(2c) Cell S2:
=SUM(L2:P2) | Sum of Votes in Governor's Race

(3) Next, we'll calculate the Wincode for each race. A Wincode is basically the winner's percentage, increased by the integer necessary to color the precinct the proper shade. For General Elections on Atlas, Republicans are usually blue, Democrats red, Libertarians yellow and Independents or Green party candidates green. In my 7 color style (which is actually 8 colors), for example, blue is in the 0s, green is in the 1s and red is in the 2s. Thus, the general formulas are as follows:

Republican     | PCT
Ind/Green      | PCT +1
Democrat       | PCT +2
Libertarian     | PCT +3
Others           | PCT +4,5,6 or 7.
Tie                | 9
No Data         | 10
Error             | 11

Ties are generally represented by light gray, no data by dark gray, and errors by white.

Thus, you need to know which candidates are Republicans, which are Democrats, and which are others when creating your Wincode formula. Depending on how the elections officials placed the candidates in the results, they are unique to each race.

I calculate Wincodes using a nested IF function. Here, we haven't precalculated the percentage for each candidate. We can do that - but need not here. It's a simple formula - ={Cell of candidate votes}/{Cell of total votes}.

Here are the formulas for the wincodes. Type (or cut and paste) the following formulas:

(3a) In Cell T2 (Senate Wincode):
=IF(MAX(C2:G2)=LARGE(C2:G2,2),9,IF(F2=MAX(C2:G2),F2/Q2,IF(C2=MAX(C2:G2),C2/Q2+2,IF(D2=MAX(C2:G2),D2/Q2+3,IF(E2=MAX(C2:G2),E2/Q2+1,11)))))

Explanation of the formula:
- Since we're not worried about precincts not yet reporting in the final results (in which case, the first IF would be "IF(Q2=0,10" where Q2 is the total votes cast, checking for ties comes first. MAX(C2:G2)=LARGE(C2:G2,2),9 compares the largest number of votes received in the Senate race against the second highest number of votes received. If they are equal, it's a tie, and QGIS will color the geometry as light gray.
- Next, we check to see if the Republican candidate, Sullivan, received the most votes. If that's true, the wincode is just the Republican's percent, F2/Q2, which would give us a shade of blue in QGIS.
- Then, we check to see if the Democratic candidate, Begich, received the most votes. If that's true, the wincode is the Democrat's percent plus 2, C2/Q2+2, which would give us a shade of red in QGIS.
- Fourth, we check if the Libertarian candidate received the most votes. If that's true, the wincode is the Libertarian's percent plus 3, D2/Q2+3, which would give us a shade of yellow in QGIS.
- Fifth, we check if the Non-affiliated candidate received the most votes. If that's true, the wincode is that candidate's percent plus 1, E2/Q2+1, which would give us a shade of green in QGIS.
- Last, if none of these are true, the wincode is 11, which would give us a blank white precinct, telling us something's wrong - either Write-ins won or we screwed up.

(3b) In Cell U2 (House Wincode):
=IF(MAX(H2:K2)=LARGE(H2:K2,2),9,IF(J2=MAX(H2:K2),J2/R2,IF(H2=MAX(H2:K2),H2/R2+2,IF(I2=MAX(H2:K2),I2/R2+3,11))))

This formula is shorter because there were fewer candidates in the race.

(3c) So what should be the formula for the Governor's Wincode? Try to calculate this on your own. Here are the partisan affiliations of the candidates:
Clift/Lee           | Libertarian
Myers/Rensel    | Constitution
Parnell/Sullivan | Republican   
Walker/Mallott  | Main Independent

Note: There was no Democrat in the race.

The formula I used is below in white text. Highlight it if you want to know the answer, and cut and paste it to Cell V2 your spreadsheet (you might need to change the font color in Excel for that Cell to black if you cut and paste the formula):

=IF(MAX(L2:P2)=LARGE(L2:P2,2),9,IF(N2=MAX(L2:P2),N2/S2,IF(O2=MAX(L2:P2),O2/S2+1,IF(L2=MAX(L2:P2),L2/S2+3,IF(M2=MAX(L2:P2),M2/S2+4,11)))))

(4) Copy and paste cells P2-U2 to rows P3 to U443.
(5) Save your spreadsheet.

Now that you've calculated Wincodes, we're ready to move on to the next step: Drawing a multiple layer precinct election map in QGIS.
17  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 04, 2017, 12:20:07 am
Calculating Wincodes

In this tutorial we will show how to create maps of precinct-level election results. Each precinct will be colored to show the winning party, and their voting strength. For example, using the Atlas color scheme, an inner-city precinct might be shown in a deep red (signifying a big Democratic victory), while a suburban precinct won by a plurality in a three-way race might be shown as light pink or light blue.

For this tutorial we need a precinct shapefile and the election data in a tabular form in a spreadsheet. The precinct shapefile for Alaska is here.

In Part 1 of this tutorial we will prepare the election data in a spreadsheet. Since Part 1 is not about QGIS per se, you may skip to Part 2 and begin with the spreadsheet prepared in Part 1.

Calculating Wincodes - Part 1: Creating Tabular Election Data for Use With QGIS.

Our xlsx file will have one row per precinct. Columns will have the precinct name or identification, as well as the votes cast for each candidate in that precinct. We begin with the election results from the Alaska Division of Elections, focusing on the 2014 general election precinct election results. Unfortunately, the Alaska Division of Elections' results aren't in that format and require processing.

(1) Download the 2014 TEXT by Precinct results from the state of Alaska's elections result website by RIGHT clicking on the link to it on Alaska's 2014 results page (i.e. not here) and selecting Save Link As. Otherwise, this will likely open up in your browser. You can save it as a .txt or .csv file. (Yes, Alaska's format is sub-optimal, but at least Alaska offers a TXT file for those years instead of just a PDF that requires even more processing to get into something Excel readable).

(2) Open up the precinct-results.txt. To do this if Excel is not your default application to open .txt files, open up Excel, then click on File-->Open-->Browse. A dialog window should open up. Make sure to change All Excel Files in the box next to Filename to All Files or All Text Files, if that's not selected already. Otherwise, you won't find your file.

(3) The Text Import Wizard should open up.
(3a) Select the radio button (circle) next to Delimited. Hit Next.
(3b) On the next screen, click the box next to Comma. Unclick any other boxes that might be checked. Hit next.
(3c) On the final screen, General format is okay for this exercise. Hit Finish.

Your data should now be imported into Excel.

(4) Rename this sheet Data (Double Click on the tab at the bottom of the screen, delete the text there and type "Data")

Next, we'll copy the precinct numbers to a new sheet and delete duplicates so that we end up with a list of unique precincts.
(5a) Copy all of row A by clicking on the column header and copying the text however you do that (I usually hit CTRL-C).
(5b) Click on the + icon to create a new sheet.
(5c) Paste the contents of Column A into Cell A1 on new Sheet1. This can be done by hitting CTRL-V.
(5d) On the top ribbon, select Data-->Remove Duplicates. Hit OK. Duplicates have been removed. See the image below for the location of "Data" and "Remove Duplicates", next to the red circle 5.
(5e) Insert a new row 1. This can be done by clicking on the row number (1), then RIGHT clicking and selecting Insert.
(5f) Type "Precinct Name" in cell A1.



Note: In Alaska, early, absentee, and questioned votes are not attributed to the election precinct of the voter, but rather to the legislative district. These votes represented about 30% of the total vote in 2014. We will not be able to display these results on our precinct-level maps, but we will retain them for use in future analysis (or tutorials).

(6) We will need to separate the precinct number from precinct name to match the data in the Alaska precinct shapefile. Luckily, all precinct IDs are 6 characters.
(6a) In Cell B2, Type "Precinct ID"
(6b) In cell B2, Type "=LEFT(", scroll over to Cell A2, and then type ",6" - or just type =LEFT(A2,6)
(6c) Copy that formula to the bottom of the data.

There are a number of ways to do this. One way is just to hit CTRL-C, scroll down until you hit the end of the data in Column A, and hit CTRL-V. This might work well when you only have a few hundred cells to paste data into, but not so much when there are thousands or tens of thousands of cells.

One Excel shortcut is to hit CTRL-End to get to the end of your worksheet, click on B562 (i.e. last row) and then SHIFT-CTRL-UP ARROW to select the entire column followed by CTRL-D. If you know the last row number, you can also do a GO TO (type CTRL-G, then B2:B562) and hit CTRL-D. Another way to do this is Hit CTRL-C to copy cell B2. Go to neighboring Column A and Press CTRL-Down Arrow enough times to get to the bottom of the entries in that column with text. Once at the true bottom, use the Right Arrow to scroll back to the cell on that line in blank Column B. The first box on the Function toolbar should now say B562. In that box (below the red circle 6 on the image above), type "B2:" before the B562 and hit enter. That should create a box from B2 to B562. Hit CTRL-V.

Next, we'll calculate the number of votes each candidate in the 2014 Senate, House, and Governor's race received in a format that can be more easily joined with the shapefiles:

(7a) Type the following headers in Cells C1-P1

Begich, Mark    Fish, Mark S.    Gianoutsos, Ted    Sullivan, Dan    Write-in 70    Dunbar, Forrest    McDermott, Jim C.    Young, Don    Write-in 50    Clift/Lee    Myers/Rensel    Parnell/Sullivan    Walker/Mallott    Write-in

I got these by cutting and Pasting Special TRANSPOSE (Right Click T or hit the Clipboard with round arrow) the the names of the Senate, House and Gubernatorial Candidates from the prior spreadsheet. You can, too. Exact names make it easier to do the =sumifs function described below.

(7b) Type the following formula into Cell C2:
=SUMIFS(Data!$F$1:$F$56184,Data!$C$1:$C$56184,C$1,Data!$A$1:$A$56184,$A2,Data!$B$1:$B$56184,Data!$B$3)

Formula explanation:
-Data! Column F is the number of votes that need to be summed. That goes first in a =SUMIFS function, but last in a simple =SUMIF function.
-Data! Column C is the Candidate Name. It gets compared to the candidate name in the header row of this sheet.
-Data! Column A is the Precinct Name. If gets compared to the Precinct Name in Column A of this sheet.
-Data! Column B is the office name. It gets compared to the office name the first time it appears on Data! B for that race. We're going to have to change the last variable when we cut and paste it for the House and Governor's Race. I'd go with two header rows to include this variable, but that might mess up the join in QGIS. And typing the name isn't necessary.

(7c) Copy this formula to Cells D2-H2. (Hit CTRL-R in D2-H2 or CTRL-C in Cell C2, followed by CTRL-V in D2-H2)
(7d) Change "Data!$B$3" to "Data!$B$12" in H2.
(7e) Copy Cell H2 to Cells I2-L2.
(7f) Change "Data!$B$12" to "Data!$B$20" in L2.
(7g) Copy Cell L2 to Cells M2-P2.
(7f) Copy cells B2-O2 to row 562.

After a few seconds, the data should update. At this time, it's probably prudent to make sure the precinct results matched the actual results.

(8a) Type "Total" in Cell A564.
(8b) Type =SUM(B2:B564) in Cell C564.
(8c) Copy the formula in C564 to Cells C564-P564.
(8d) Check the totals against the official total election results on Alaska's website. That's available here.

This step matters. When I attempted this the first time, I noticed the write-in totals were off for some races without adding the race name variable to the =SUMIFS function.

Assuming everything checks out correctly, we're ready to compute Wincodes. Before you do that:

(9a) In Cell A1, Select All (Hit CTRL-A).
(9b) Copy that data.
(9c) Open a new blank spreadsheet.
(9d) Paste VALUES in Cell A1 of the new blank spreadsheet.
(9e) Save this spreadsheet as "AK2014 Tutorial" in Excel format.

Or just click on the link to my AK2014 Tutorial.xlsx in the next post.
18  About this Site / The Atlas / Re: Did I deserve to get a modified post for this? on: November 03, 2017, 02:43:30 pm
If thatís all you said, no. Any judgeís penchant to sleep on the bench is fair game. Justice is supposed to be blind, not asleep.

Itís not like you attacked Justice Ginsbergís physical appearance or something like that.
19  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 03, 2017, 10:05:25 am
After you added labels, I would do the simple way to create a map: Project > Save an Image which creates a png file of the map window. That is what I always use (my use of QGIS is more as an interactive analysis tool).

I tried to use the Print Composer for Hudson, and could never get the Bing Street Maps to line up with the Census Shapefiles. If you use the Census Shapefiles for street features, each street fragment (a block line) is a feature. So you end up with a lot of labeled streets. I merged street features, but it was a tedious process.

Iíll put that in.

My main problem with printing directly from QGIS is that itís easy to unintentionally move the map in the map window, or change the zoom level, etc. This makes it more difficult to make gifs, where you need the same view of all pictures or the map will jump around. Yes, you can always just write down the extents and zoom level so that you can manually reset, save the project as a different name and reload when you unintentionally move the map or show the use previous view magnifying glass to get back to the old view (if you can remember which it was, anyway), but why bother when the Print Composer doesnít change extents unless you force it to?

Itís also good that you can easily add a background and legend using the print composer. Otherwise, Iíd have to do that manually for every map using Snagit or Paint, anyway, so I actually save time when I make multiple maps by using the print composer. The legend funnel feature is also excellent, as it gets rid of colors in the scale that are not used that portion of the map, making the legend shorter.

But again, YMMV.

Quote
One thing you might show, particularly for the Contiguous US, is how to turn the county boundaries off. That is an awful lot of black which overwhelms the colors. If you do that, then you might want to bring a States layer in, and show how to display layers that cover the same area.

Yeah, we should probably add that in another tutorial. Lines can get annoying.

Is there a simplified state map somewhere on Censusí website, like there is for counties? I generally only have the tigerline files on my computer.

Quote
I generally use the show all labels, but I generally only use county names when working interactively. If I am having trouble reading labels, I can just zoom in some more. I have used the expression left("NAME",2) to display the first two characters of a county name. But that is mainly when working in an area where all the counties look the same.

I did some googling, and someone was explaining how to label earthquakes based on their magnitude, which was an attribute. The largest earthquakes (> 6.5 magnitude) had their location; those > 4.5 had their magnitude shown, and smaller ones just had a symbol. There apparently is a way to indicate both what to display (content), and how to display it (style)

You can also define another pair of fields that have the offsets. So you may be able to move some labels so that Ketchikan Gateway Borough and Fairbanks North Star can be displayed.

An expression like this can be used.

if (left( NAME,1)='H', "NAME" ,"")

This frivolous example labels counties whose name begins with "H".

If you were displaying the contiguous US, you probably would not label all 3000+ counties, or even include the percentage change. That is why you are using a color theme. But you might want to display the fastest gaining counties, or the largest populations, etc. So you could simply calculate a variable that indicates which counties should be labeled.

if ("IMPORTANT" = 1, "NAME", "")

I probably didnít want to include the percentage change in my map, either - but I wanted to show how to make a multiple-line label (which even I didnít know how to do until I reread your Hudson GIS tutorial). The multiple-line label is probably what is causing Fairbanks and Ketchikan to disappear when we have the label collision avoidance on. Bristol Bay is going to always be off unless you use a method to assign it or Lake and Peninsula Borough separately. Itís too small and too close to the centroid of Lake & Peninsula Borough.

Iíll add a tutorial on rules-based labeling eventually.
20  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 03, 2017, 12:11:35 am
Using the QGIS Print Composer

We're ready to export an image of this map using the print composer. Before we do that, we should probably add a shapefile of Canada. Otherwise, when we color the background, Alaska will look like an island.

Luckily, Statistics Canada's shapefile website has an available provincial shapefile here. Download this file and unzip it.

(1) Add gpr_000b11a_e.shp to your map by dragging the shapefile to the map screen, clicking on the V icon on the left of the screen, or hitting CTRL-Shift-V. Note: if you last opened the .xmlx file, you might have to change File Type back to ESRI Shapefiles to find it.

The names of these two shapefiles are confusing. You can rename them in the layer panel by right clicking and selecting Rename from the drop-down menu. This will also help later when we add a legend to the map.

(2a) Rename gpr_000b11a_e "Canada".
(2b) Rename cb_2016_us_county_5m "County".
Note: This doesn't change the underlying file name, just the name in the Layer Panel. The layer name is used when the print composer auto-makes a legend - though you could separately rename the shapefile name only in the print composer, if you wish.

What color do we want to make Canada? That's totally up to you - and you can easily change it:
(3a) Right click on Canada in the layer panel, and select "Properties" from the drop-down menu.
(3b) Click Style.
(3c) Click on Simple Fill.

You should see a menu with 7 options:



-Fill allows you to change the background color. Clicking on the arrow brings up a simple dialog with a color wheel and simple and recent colors. Clicking on the bar brings up a more complex dialog that allows you to input an HTML code for your color choice.

(3d) Choose whatever color you want. I usually use a dark grey for foreign countries, HTML notation #616161.  The opacity slider allows you to make the layer more or less transparent. It isn't necessary to adjust it here.

-Outline allows you to choose the outline color - here - provincial and country borders.

(3e) Click on the bar or arrow and choose a color. I usually use red, HTML notation #ca0020. If you don't want to show provincial borders, use the same color you used for fill.

-Fill style allows you to decide how to fill a polygon. Solid is probably fine here.

-Outline style gives you options for the outline - solid line, dash, etc. Solid line is probably fine here.

-I'm not sure exactly what Join Style does. Skip.

-Outline width allows you to set the width of your outline. I tend to make state and country borders wider than county borders.

(3f) To do that, hit the up arrow until Outline Width is 0.66000 millimeters.

-Offset allows you to offset your symbols by a specified length. That's not necessary for a solid fill (but might be for points). Skip.

(3g) Hit Okay.

Canada's colo(u)rs should have changed to your specifications.

Save your project.

We're now finally ready to use the print composer.

(4a) Select Project-->Print Composer or type CTRL-P.

A dialog will pop up asking for a unique name. Name it Alaska. The print composer will pop up. It looks like this:



I'm not going to explain what all of the icons do - just the ones typically used to make a map. They are labeled B-F, in order of what I usually do to make my maps:

(4b-1) Click on the icon that looks like a scrolling piece of paper. This adds a map to the canvas. Draw a rectangle as large as the canvas.

You should now see Map 0 in the Items Panel, and tabs for Composition, Item properties, and Command history below that.

(4b-2) Click on the Item properties tab, if it's not already selected.
(4b-3) Under Extents, click on "Set to map canvas extent"

This will make your print composer map look like what the main QGIS screen looks like. The map is still probably not optimal - too much white space. You can manually fix this by playing around with the X min, Y min, X max and Y max values under Extents. You can play around with them until you like your map.

(4b-4) Enter the following values:
X min: -1500000
Y min: 300000
X max: 1750000
Y max: 2500000

Next, we should set the blank space to the color of water. To do that:
(4b-5) Scroll down and check the background box.
(4b-6) Expand the background section and click on background color.
(4b-7) Select whatever color you want. I use HTML notation #a6cee3 for water
(4b-8) Hit OK.

The water should now be colored blue.

Note that the map is now smaller than the canvas. To rectify this:

(4b-9) Click on the Composition tab.
(4b-10) Under "Resize page to content", hit the Resize page button.

While we're here, we might as well lower the export resolution. 100 dpi is usually sufficient. Anything larger might be too large to be uploaded to the Atlas Gallery.

(4b-11) Type 100 in the Export resolution box.

We're now ready to add a legend to the map:

(4c-1) Click on the icon with Yellow, Red, Green squares on the left side of the screen.
(4c-2) Draw a box on the upper right hand side of the map. A legend should be auto-created.
(4c-3) Select Legend in the Item Pane.
(4c-4) Select Item properties.

Legends can be tailored to only include items on the map screen.

(4c-5) Open the Legend items menu if it isn't already.
(4c-6) Hit the funnel icon underneath the list of shapefiles.
(4c-7) Click on the "Only show items inside current atlas feature" box.

If you've done this correctly, the legend should be truncated to about 7 items, and if you update the map extents in the print composer or change the variable in QGIS, the legend should automatically change to reflect what's shown on the map.

(4c-8) Scroll down to Position and size. Expand the menu, if necessary.
(4c-9) Click on the upper right box next to "Reference point".
(4c-10) Move your cursor back to the map. Click on and drag the Legend to the upper right hand corner of the map. You should see red guidelines on the canvas when you get there.

Next, we can add a scale bar (optional):

(4d-1) Click on the black and white bar icon on the left side of the print composer.
(4d-2) Create a box on the lower right hand corner of the map.
(4d-3) Select <scale bar> in the Item Pane
(4d-4) Select Item properties below (if necessary)
(4d-5) This is America. We don't need no stinking metric system. Under units, change "Meters" to "Feet".
(4d-6) Under Segments, make the bar as long or short as you want. Using the down arrow, change left to 0.
(4d-7) Decide whether you like a short or tall bar. I like short bars, so I lower the height to 1.00 mm.
(4d-8) Under Position and size, check the lower right hand box next to Reference point.
(4d-9) On the map, drag the scale bar to the lower right hand corner. You can manipulate the box by making it larger or smaller to move it closer to the bottom of the map.

Finally, we can add a text description of the map anywhere on the canvas:

(4e-1) Click on the icon of a T in a rectangle on the left hand side of the screen.
(4e-2) Draw a rectangle in the upper left hand corner of the screen.
(4e-3) Highlight QGIS in the Item Pane.
(4e-4) Select Item properties below (if necessary)
(4e-5) Type the title of this map in the box under Main properties: Relative Population Change in Alaska County Equivalents, 2010-16
(4e-6) Click the Font Button
(4e-7) Change the font, type and size however you want. I've used MS Shell Dig, Bold, 24 pt type.
(4e-8) Hit OK.
(4e-9) Move the text box to the upper left hand corner, and drag the edges to fit in all the text, if necessary.

Finally, we can export the map as an image:
(4f-1) Click on the icon next to the printer on the top toolbar (it looks like a piece of paper with a mountain on it).
(4f-2) Type a file name for your picture, and hit Save.
(4f-3) A dialog should pop up. Make sure the Export Resolution is set at 100 dpi and check the box to Crop to content. Hit save.
(4f-4) Open your image. It should look something like this:



Congratulations! You have successfully used the print composer to make a map! Assuming you have enough posts here, you can now upload your map to the Atlas Gallery and share it with us!

As always, remember to save your project. This is especially important now because your print composer will be saved as part of your project. That allows you to easily make multiple maps with the same projection and coordinates simply by changing the variable mapped. It's how I make my gifs.

Note: There are a couple of issues with some labels not showing up on the map. We could force all labels to be printed by checking the appropriate box in the label dialog. I'm still not 100% sure how to manually apply label locations to avoid potential collisions, though. Perhaps jimrtex does.

Next from me: Calculating WINCODEs.
21  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 02, 2017, 10:03:42 pm
Adding Labels to Your Map

Now that you know how to color, pan and zoom your map, you're ready add county labels. Since these would largely be unreadable on a map of the Continental United States, let's use your newly-acquired Projection, Pan and Zoom skills to focus on Alaska.

(1) Zoom to full map extents by hitting the magnifying glass with three blue arrows.

Notice how Alaska is weirdly tilted on this map? Before making a map of Alaska, we need to change the projection to something more Alaska-specific.

(2) Click on the globe icon in the bottom right-hand corner of the screen. That will launch the project properties dialog.
(3) Type "Alaska Albers" in the box.
(4) Select "Alaska_Albers_Equal_Area_Conic" from the list.
(5) Hit okay.

Now, Alaska looks more like most maps of Alaska.

Here's an image detailing these three steps:


(6) Hit the Zoom In magnifying glass, and draw a box around Alaska. Don't worry if you don't get all of the Aleutian Islands in - most are uninhabited anyway. Pan and Zoom in or out of your map until it looks something like this (assuming you've already colored your map):



Now, we're ready to add labels to the map.

(7a) Right click on cb_2016_us_county_5m in the layer panel.
(7b) Select properties from the drop-down menu.
(7c) Select "Labels" on the left side of the dialog.
(7d) Select "Show labels for this layer" from the top menu.

As you can see, the label dialog has 7 categories of options. I will briefly describe the most salient of them below. Here's a diagram, in case you're lost:



Text - This allows you to change the font, font size, color and transparency. I usually change the style to Bold, but YMMV.

(7e) Click on Style and change it from Normal to Bold from the drop-down menu.

Formatting - This allows you to wrap your text on a character, set a left, right or center alignment, and format numbers.  

(7f) Change the Alignment to Center. Click the box next to formatted numbers, and enter 2 in the Decimal Places box.

Buffer - this draws a text buffer around your text. I think this is a good idea to use with the Atlas color scheme because black text is too dark on dark colors and white text is too light to be seen on its light colors.

(7g) Check the Draw text buffer box.

Background - this allows you to draw a background behind the text. This also helps with visibility, but probably isn't necessary here, since we have a buffer. Skip.

Shadow - this allows you to draw a drop shadow behind your text. This isn't necessary here. Skip.

Placement - this allows you to dictate where your labels are placed - offset from centroid, etc. It also allows you to define the priority of this layers' labels compared to other layers.

(7h) Click on Force point inside polygon.

Rendering - this allows you to, among other things, only show labels on certain zoom levels and show all labels, including colliding labels. Skip for now.

What do we want to include in the label? If we were going to be simple about it, just NAME. But there is a way to include multiple things in your label.

(7i) Click on the curved E to the right of the label with dialog.
(7j) Type the following formula:

"NAME" || '\n' || concat(format_number("INCREASE"*100,2),'%')

'\n' places the increase text on the next line, instead of next to name. The concat function allows you to put a percentage mark after the increase. The format_number function allows you to limit the Increase percentage to 2 decimal places.

(7k) Hit OK to save the formula.
(7l) Hit OK to close the Layer Properties Dialog.

Congratulations! You've added labels to your map! Your map should now look something like this:



Again, remember to save your project.

If you want to print a simple image of your map, you can select Projectó> Save an Image which creates a png file of the map window. But if you want to add things like a legend and descriptive text or want to make multiple maps with the same map view, itís probably best to use QGISí print composer. How to do that is described in the next post.
22  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 02, 2017, 04:48:05 pm
QGIS uses a lot of Python plugins, for things like file import/export. I did not know that you could use xlsx files. I did some googling, and there was a tutorial about importing a lay from a csv file, which then mentioned that you could use an xls file, but that it would not import expressions. But I just tried it with an xlsx file and it did import the values of expressions.

Neither did I, until I posted a link to this thread on Twitter and @PrdNewEnglander read this and told me we were making things more complicated than necessary - just import the Excel spreadsheet. I did a very quick test this morning, and seemed to get it to work, properly importing the ID column as a text column. I really should try it with one of my more complicated spreadsheets to make sure, though.

Quote
I also exported the shapefile/dbf as an xlsx file. It looks OK. I'm not exactly sure I understand why you need to export the dbf file. In my applications, both the shapefile/dbf files and the census data files have the ID so that they can be joined.

The only real reason I developed my method was because I never really knew how to join sheets until your Hudson tutorial, and ran into the leading zero issue when I otherwise tried it. It does have its benefits - I often use more than one map making program/website, and donít have to do multiple joins across platforms. For example, I can just import the zipped shapefile & .dbf to Carto.com without having to use their join function, which sometimes misreads the column types and imports the GEOIDs as numbers or numbers as text. The data and data type is permanently in the .dbf file.

Iím going to try to update the first post tonight to reflect the possibility of just using the Excel file.
23  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 02, 2017, 08:58:05 am
I found out on Twitter that we needn't even do the .csv step. QGIS can export an Excel .xlsx file as a vector file. That seems to import the ID column directly, as a text file.

jimrtex - do you know of any drawbacks to this? If not, I'll further simplify the preferred method instuctions if I have time tonight.
24  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 01, 2017, 11:27:02 pm
Map Coloring Instructions:

Note: This assumes you have cb_2016_us_county_5m.shp open in QGIS. If not, see the instructions for the method you used to learn how to do that.

1) To color the map:
(1a) RIGHT CLICK on cb_2016_us_county_5m in the Layer Panel and select "Properties" from the drop down map, as you can see in the image below:



(1b) The Layer Properties Dialog will appear. Select "Style" on the Left, then Style-->Load Style on the bottom left, as you can see in the picture below:



(1c) Load 5 PCT Gradation Heat with Zero.qml from where you saved it on your computer. The color scheme should load. The default variable isn't INCREASE. Change this to INCREASE by clicking on the down arrow next to PCT_FI_C60, selecting INCREASE and hitting OK on the bottom of the dialog, as you can see in the picture below:



(2) Congratulations! Your map is now colored in various shades of red and blue! It should look like this:



Unfortunately, your map's not perfect, and you might not know how to use QGIS to zoom in or whatever. jimrtex and I am working on more tutorials to tell you how to do that.
25  About this Site / How To / Re: How to Make Maps Using Mapping Software (QGIS) on: November 01, 2017, 10:11:14 pm
The cinyc Method 2:

1) Open up the unzipped cb_2016_us_county_5m.dbf file in Open Office Calc.

2) Copy the GEOID column E from the opened .dbf file. To do this, click on E and either hit CTRL-C or Right Click and select "Copy", as you can see in the image below:


3)  Open countychange.xlsx in Excel. Create a new sheet by clicking on the plus sign at the bottom of the page. Paste the column from Open Office to Column A of that new sheet. To do this, go to Cell A1 on Sheet1 and hit CTRL-V.

4) Click on the Data sheet. Add four columns to it:

Q2 = TEXT(B2,"00000")
R2 = E2             ! Population April 2010 Base
S2 = L2            ! Population July 2016 Estimate
T2 = S2/R2 - 1   ! Relative change 2010 to 2016

5) Switch back to Sheet1. Note that the GEOIDs from the test data and GeoIDs from Census' Shapefile are in a different order. We have to rectify this. I use a =sumif formula to get the color codes in Census' order.

-Type the following formula into Cell B2 on Sheet2: =sumif(Data!$Q$2:$Q$3221,$A2,Data!R$2:R$3221)
-Copy that formula to Cells C2 and D2.
-Copy that formula into Cells B3-B3234 on Sheet2. Hit CTRL-C after selecting cells B2-D2, then LEFT CLICK and scroll down from Cells B3 to B3234 (there's a shortcut to this - let me know if you want to know it). Note: The dollar signs in the formula are crucial to making sure the same formula gets cut and pasted in each row.
-Type "POP10,N,19,0","POP16,N,19,0","INCREASE,N,19,15" into Cells B1,C1 and D1 to give the columns a name.
 
6) Now it's time to cut and paste the new Color Code Column from Sheet1 into a new row in the .dbf file of Open Office Calc.
-Left Click and hold on the "B","C" and "D" at the top of Columns B-D to select Columns B-D in Excel and then press CTRL-C (or Right Click and Select Copy).
-Switch to Open Office Calc.  Select cell J1. RIGHT CLICK, then select "Paste Special-->Unformatted Text-->OK"

7) Save the .dbf file in Open Office Calc (CTRL-S or hit the diskette on the toolbar) and Excel. Open Office will warn you that some data might not be able to be saved in dbf format, and suggest another format. Select "Keep Current Format". Excel can't save in .dbf format - that's why you need Open Office. Also, save the .xslx file in Excel.

8) Close Open Office Calc.

Now, we're ready to open QGIS:

9) Open cb_2016_us_county_5m.shp in QGIS. You can probably do this by clicking on the file, or dragging the file to the big window on QGIS. If not, open QGIS, and either hit CTRL-Shift-V or select the V symbol on the left side of the screen, or select Layer-->Add Layer-->Add Vector Layer from the drop-down menu.

Hit "Browse", and find cb_2016_us_county_5m.shp on your computer.

Your screen should now look something like this:


10) Save the project as, using the diskette icon in the upper left. Make sure you select a directory you can find. This will create a .qgs file which is your project context. Be sure to save this from time to time. If you exit QGIS (or worse it crashes), you can get back to where you were at.
--------------------------------------------------------------------------
The next reply includes instructions on how to color the counties.
Pages: [1] 2 3 4 5 6 ... 448


Login with username, password and session length

Logout

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines