<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>lostmapper.com</title><description>Wandering in the world of cartography and geographic information systems, all the while sharing what I learn with you!</description><link>https://lostmapper.com/</link><item><title>Getting Started with PostGIS in QGIS on macOS</title><link>https://lostmapper.com/articles/2023-12-20-getting-started-postgis-qgis-macos/</link><guid isPermaLink="true">https://lostmapper.com/articles/2023-12-20-getting-started-postgis-qgis-macos/</guid><pubDate>Wed, 20 Dec 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;What is PostGIS?&lt;/h2&gt;
&lt;p&gt;PostGIS is an extension for the popular relational database PostgreSQL. It adds support for storing, indexing and querying geographic data.&lt;/p&gt;
&lt;p&gt;There are a number of reasons why you might want to use PostGIS but the primary advantage of using a database over files is the fact that multiple people can access, query and update information in a database at the same time.&lt;/p&gt;
&lt;h2&gt;Downloading and Installing Postgres.app&lt;/h2&gt;
&lt;p&gt;To get up and running fast we’re going to use an app called Postgres.app which includes PostGIS. You can download it from &lt;a href=&quot;https://postgresapp.com/&quot;&gt;https://postgresapp.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;While this app provides a great way to start learning PostGIS, it’s likely not what you should use for an enterprise level application.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Head to &lt;a href=&quot;https://postgresapp.com/&quot;&gt;https://postgresapp.com&lt;/a&gt; and download the latest release&lt;/li&gt;
&lt;li&gt;Open the Disk Image and drag the &lt;strong&gt;Postgres&lt;/strong&gt; application to your Applications folder&lt;/li&gt;
&lt;li&gt;Start up the application from your &lt;strong&gt;Applications&lt;/strong&gt; folder or &lt;strong&gt;Spotlight&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Confirm that you want to open it&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;Initialize&lt;/strong&gt; button to create a PostgreSQL 16 instance&lt;/li&gt;
&lt;li&gt;This will create a server with 3 databases:&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;your username&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;postgres&lt;/li&gt;
&lt;li&gt;template1&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Enabling the PostGIS Extension&lt;/h2&gt;
&lt;p&gt;Before we can do anything we first need to enable the PostGIS extension in our database.&lt;/p&gt;
&lt;p&gt;Double-click the database named after your username and it will bring up a &lt;code&gt;psql&lt;/code&gt; session in a terminal window. &lt;code&gt;psql&lt;/code&gt; is a command-line tool for interacting with a Postgres database.&lt;/p&gt;
&lt;p&gt;Enter the following commands to enable the PostGIS Extension on the database named with your username. In my case it’s named &lt;code&gt;brian&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;CREATE SCHEMA postgis;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;CREATE EXTENSION postgis SCHEMA postgis;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;CREATE EXTENSION postgis_raster SCHEMA postgis;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;ALTER DATABASE brian SET search_path=public,postgis;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;exit&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Schemas are namespaces that help you organize the tables, views and other things you create in your database. We created a schema named &lt;code&gt;postgis&lt;/code&gt; so that all the information associated with the PostGIS extensions won’t pollute or collide with other schemas we create. The extensions will still be available to all other schemas in the database.&lt;/p&gt;
&lt;h2&gt;Connecting to PostGIS from QGIS&lt;/h2&gt;
&lt;p&gt;Now that we have a database running with the PostGIS extension installed we can connect to it from QGIS:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Start up QGIS&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Browser&lt;/strong&gt; right-click on &lt;strong&gt;PostgreSQL&lt;/strong&gt; and click &lt;strong&gt;New Connection&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Enter the following:&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Name: Postgres.app-&lt;em&gt;username&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Host: localhost&lt;/li&gt;
&lt;li&gt;Port: 5432&lt;/li&gt;
&lt;li&gt;Database: &lt;em&gt;username&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ol&gt;
&lt;li&gt;Under &lt;strong&gt;Authentication&lt;/strong&gt; click &lt;strong&gt;Basic&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;User name: &lt;em&gt;username&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;Test Connection&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Creating Schemas&lt;/h2&gt;
&lt;p&gt;As I mentioned previously, schemas are a convenient way to organize the tables, views and other database objects you create. Let’s create a dedicated schema called &lt;code&gt;tutorial&lt;/code&gt; for the work we’ll be doing today:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the &lt;strong&gt;Browser&lt;/strong&gt;, under &lt;strong&gt;PostgreSQL&lt;/strong&gt;, right-click on your new connection and choose &lt;strong&gt;New Schema…&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Enter tutorial for the &lt;strong&gt;Name&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Creating Tables&lt;/h2&gt;
&lt;p&gt;Now that we have a dedicated schema, let’s create a table to hold some point data:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Right-click on the tutorial schema and choose &lt;strong&gt;New Table…&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Schema&lt;/strong&gt; should already be set to tutorial&lt;/li&gt;
&lt;li&gt;Change the table &lt;strong&gt;Name&lt;/strong&gt; to points&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add Field&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Change the field’s &lt;strong&gt;Name&lt;/strong&gt; to name&lt;/li&gt;
&lt;li&gt;Change the field’s &lt;strong&gt;Type&lt;/strong&gt; to Text, limited variable length (varchar)&lt;/li&gt;
&lt;li&gt;Change the field’s &lt;strong&gt;Length&lt;/strong&gt; to 64&lt;/li&gt;
&lt;li&gt;Set the &lt;strong&gt;Geometry Type&lt;/strong&gt; to point&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Double-click the new &lt;code&gt;points&lt;/code&gt; table in your &lt;code&gt;tutorial&lt;/code&gt; schema to add it as a layer to your map&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Adding Data to a Table&lt;/h2&gt;
&lt;p&gt;Once we have our points table as a layer in our project we can add data like we would with a GeoPackage or Shapefile:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select the &lt;code&gt;points&lt;/code&gt; layer&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;Toggle Editing&lt;/strong&gt; button to enable editing&lt;/li&gt;
&lt;li&gt;Click the&lt;strong&gt;Add Point Feature&lt;/strong&gt; button to start adding points&lt;/li&gt;
&lt;li&gt;Click on the map view to add a point&lt;/li&gt;
&lt;li&gt;Leave the &lt;strong&gt;ID&lt;/strong&gt; value as is — it’s automatically set to a function that grabs the next available ID for the table&lt;/li&gt;
&lt;li&gt;Set a &lt;strong&gt;Name&lt;/strong&gt; for the point&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;Save Layer Edits&lt;/strong&gt; button&lt;/li&gt;
&lt;li&gt;Right-click the points layer choose &lt;strong&gt;Open Attribute Table&lt;/strong&gt; to see your points&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Importing Layers into PostGIS via QGIS&lt;/h2&gt;
&lt;p&gt;Another thing we can do with PostGIS is import data from other formats, such as Shapefiles. Lets import that US States and Territories from weather.gov:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Download and unzip the US States Shapefile: &lt;a href=&quot;https://www.weather.gov/source/gis/Shapefiles/County/s_08mr23.zip&quot;&gt;https://www.weather.gov/source/gis/Shapefiles/County/s_08mr23.zip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Database&lt;/strong&gt; menu choose &lt;strong&gt;DB Manager…&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;PostGIS&lt;/strong&gt; choose the tutorial schema&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Import Layer/File…&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Click the &lt;strong&gt;…&lt;/strong&gt; next to the &lt;strong&gt;Input&lt;/strong&gt; field and navigate to where you unzipped the file &lt;code&gt;s_08mr23.shp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Make sure &lt;strong&gt;Schema&lt;/strong&gt; is set to tutorial&lt;/li&gt;
&lt;li&gt;Change the &lt;strong&gt;Table&lt;/strong&gt; name to us_states_and_territories&lt;/li&gt;
&lt;li&gt;Check &lt;strong&gt;Primary Key&lt;/strong&gt; and ensure it’s set to id&lt;/li&gt;
&lt;li&gt;Check &lt;strong&gt;Geometry Column&lt;/strong&gt; and ensure it’s set to geom&lt;/li&gt;
&lt;li&gt;Check &lt;strong&gt;Convert field names to lowercase&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Check &lt;strong&gt;Create spatial index&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Double-click the &lt;code&gt;us_states_and_territories&lt;/code&gt; table under the tutorial schema in the &lt;strong&gt;Browser&lt;/strong&gt; to add it as a layer to your map&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;You’ve now have a PostGIS database running on your machine and you know how to create your own schemas, create your own tables and import data using QGIS.&lt;/p&gt;
&lt;p&gt;There are a couple of books you might want to check out — one I’ve been working through and the other I haven’t picked up yet:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.manning.com/books/postgis-in-action-third-edition&quot;&gt;PostGIS in Action&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://locatepress.com/book/spatial-sql&quot;&gt;Spatial SQL&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you’re interested in learning more please follow me on &lt;a href=&quot;https://www.youtube.com/@lostmapper&quot;&gt;YouTube&lt;/a&gt;. If you have any questions or suggestions, feel free to reach out to me on &lt;a href=&quot;https://mapstodon.space/@lostmapper&quot;&gt;Mastodon&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title>Setting Up Python 3 for GIS on macOS</title><link>https://lostmapper.com/articles/2023-11-20-setting-up-python3-for-gis-on-macos/</link><guid isPermaLink="true">https://lostmapper.com/articles/2023-11-20-setting-up-python3-for-gis-on-macos/</guid><pubDate>Mon, 20 Nov 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;From my explorations over the years it seems that Python is a particularly important language in the world of GIS. I thought it would be best to get comfortable with how to manage Python installations and the various external packages a project might use.&lt;/p&gt;
&lt;h2&gt;Install Python with asdf&lt;/h2&gt;
&lt;p&gt;I use several different programming languages in my day-to-day and after using various tools over the years have settled on using &lt;a href=&quot;https://asdf-vm.com/&quot;&gt;asdf&lt;/a&gt; to install and manage those languages.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;asdf&lt;/code&gt; makes it easy to install multiple versions of a language and switch between them as your projects require. They provide extensive documentation on &lt;a href=&quot;https://asdf-vm.com/guide/getting-started.html&quot;&gt;Installing asdf&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Once &lt;code&gt;asdf&lt;/code&gt; is installed we can add its Python plugin, install the latest version of Python, and set that version as our global default:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$ asdf plugin add python&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$ asdf install python latest&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$ asdf global python latest&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$ which python&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;/Users/brian/.asdf/shims/python&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$ python --version&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Python 3.11.5&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Create a Project Directory&lt;/h2&gt;
&lt;p&gt;Now that Python is installed we can create a directory for our project:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$ mkdir lostmapper&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$ cd lostmapper&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$ asdf local python 3.11.5&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we are making a directory for our project and switching into it. The last line creates a &lt;code&gt;.tools-version&lt;/code&gt; file that lets &lt;code&gt;asdf&lt;/code&gt; know what version of Python we want to use whenever we’re working in that directory.&lt;/p&gt;
&lt;h2&gt;Create and Activate a Virtual Environment&lt;/h2&gt;
&lt;p&gt;When you’re working many different programming projects they are likely to use both the same and different external packages. In some cases, they may even use the same package but a different version of that package. This can get confusing for both people and computers!&lt;/p&gt;
&lt;p&gt;To avoid conflicts between the packages in any two projects it is best to give each project its own space to exist in. In Python, these are known as Virtual Environments and are managed using Python’s &lt;a href=&quot;https://docs.python.org/3/library/venv.html&quot;&gt;venv module&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To create and activate a virtual environment, use the following commands:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$ python -m venv .venv&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;$ source .venv/bin/activate&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first line creates a virtual environment in the subdirectory &lt;code&gt;.venv&lt;/code&gt;. The second line activates that virtual environment. After that, any packages we add will only be installed within that virtual environment.&lt;/p&gt;
&lt;h3&gt;Don’t Check In Your Virtual Environment Directory&lt;/h3&gt;
&lt;p&gt;If you’re using a version control system like &lt;a href=&quot;https://git-scm.com/&quot;&gt;Git&lt;/a&gt; you’ll want to add the .venv directory to your project’s .gitignore file so that you’re not checking all those packages in.&lt;/p&gt;
&lt;h2&gt;Visualize Python Versions and Virtual Environments (Optional)&lt;/h2&gt;
&lt;p&gt;I use a tool called &lt;a href=&quot;https://starship.rs/&quot;&gt;Starship&lt;/a&gt; that gives me a succinct and informational prompt in my terminal. It lets me know:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What directory I’m currently in&lt;/li&gt;
&lt;li&gt;Which branch I’m on when using version control systems like &lt;a href=&quot;https://git-scm.com/&quot;&gt;Git&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;What languages and versions of languages are being used&lt;/li&gt;
&lt;li&gt;What virtual environment I’m currently in, if any&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, at this point, my prompt looks like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;lostmapper.com on main via 🐍 v3.11.5 (.venv)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And yes, different languages have their own little emoji!&lt;/p&gt;
&lt;h2&gt;Add Packages Using pip&lt;/h2&gt;
&lt;p&gt;Now that we have a virtual environment set up we can start adding packages. To do that we’ll use &lt;a href=&quot;https://pip.pypa.io/&quot;&gt;pip&lt;/a&gt; — package installer for Python.&lt;/p&gt;
&lt;p&gt;If we want to add the mkdocs package to our project, we would do the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$ python -m pip install mkdocs&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If we look in &lt;code&gt;.venv/lib/python3.11/site-packages&lt;/code&gt; we can see that mkdocs has been installed along with all the packages it depends on.&lt;/p&gt;
&lt;h2&gt;Freeze and Share Required Packages&lt;/h2&gt;
&lt;p&gt;Now that we’ve added some packages it’s a good idea to track what we’ve installed along with which specific version we’re using. This is helpful if we’re ever developing on another computer or collaborating with other people.&lt;/p&gt;
&lt;p&gt;To generate a list of packages, run the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$ python -m pip freeze &amp;gt; requirements.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This creates a &lt;code&gt;requirements.txt&lt;/code&gt; file in our project that we or others can use to install the same packages we’re using. The file could be named anything but &lt;code&gt;requirements.txt&lt;/code&gt; seems to be the agreed-upon standard for Python projects.&lt;/p&gt;
&lt;p&gt;Here’s what ours looks like now:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;click==8.1.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;ghp-import==2.1.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Jinja2==3.1.2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;Markdown==3.4.4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;MarkupSafe==2.1.3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;mergedeep==1.3.4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;mkdocs==1.5.2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;packaging==23.1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;pathspec==0.11.2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;platformdirs==3.10.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;python-dateutil==2.8.2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;PyYAML==6.0.1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;pyyaml_env_tag==0.1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;six==1.16.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span&gt;watchdog==3.0.0&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course, depending on when you do this the version numbers may differ.&lt;/p&gt;
&lt;h3&gt;Installing Packages On Another Computer&lt;/h3&gt;
&lt;p&gt;To install all the same packages on another computer, run the following command after creating and activating your virtual environment:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span&gt;&lt;span&gt;$ python -m pip install -r requirements.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;We’ve learned how to install Python using &lt;code&gt;asdf&lt;/code&gt;, create virtual environments using &lt;code&gt;venv&lt;/code&gt;, and add and track packages using &lt;code&gt;pip&lt;/code&gt;. This should help us feel a little less lost when working on Python projects moving forward.&lt;/p&gt;
&lt;p&gt;As one might guess, these are not the only tools available for managing Python versions and packages but for the most part, we’re leaning on what’s built in with Python — modules that should always be available once Python is installed.&lt;/p&gt;
&lt;p&gt;If you’re interested in learning more please follow me on &lt;a href=&quot;https://www.youtube.com/@lostmapper&quot;&gt;YouTube&lt;/a&gt;. If you have any questions or suggestions, feel free to reach out to me on &lt;a href=&quot;https://mapstodon.space/@lostmapper&quot;&gt;Mastodon&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title>Getting Started with QGIS</title><link>https://lostmapper.com/articles/2023-10-24-qgis-getting-started/</link><guid isPermaLink="true">https://lostmapper.com/articles/2023-10-24-qgis-getting-started/</guid><pubDate>Tue, 24 Oct 2023 00:00:00 GMT</pubDate><content:encoded>&lt;h2&gt;What is QGIS?&lt;/h2&gt;
&lt;p&gt;QGIS is a free and open source Geographic Information System that runs on Windows, Mac and Linux. You can download it for free from &lt;a href=&quot;https://qgis.org/en/site/&quot;&gt;https://qgis.org/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this Getting Started guide I will show you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How to create and save QGIS Projects&lt;/li&gt;
&lt;li&gt;How to add a reference layer using OpenStreetMap&lt;/li&gt;
&lt;li&gt;How to move and zoom around your map&lt;/li&gt;
&lt;li&gt;How to create Spatial Bookmarks so you can quickly get to where you want to be&lt;/li&gt;
&lt;li&gt;How to create a Print Layout of your map and export a PDF of it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For this article I will be using QGIS 3.32.3-Lima on macOS Sonoma.&lt;/p&gt;
&lt;h2&gt;Creating and Saving a QGIS Project&lt;/h2&gt;
&lt;p&gt;Most everything you do in QGIS is going to be done in the context of a Project, so it’s important that we get comfortable with creating and saving them.&lt;/p&gt;
&lt;h3&gt;Create a Directory for your Mapping Projects&lt;/h3&gt;
&lt;p&gt;I suggest keeping all your mapping projects together in a dedicated folder (or directory) on your machine. Depending on the size of your projects and data you may or may not want this folder to be in your iCloud Drive.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Determine where you want to store your projects&lt;/li&gt;
&lt;li&gt;Create a folder named gisor mapping&lt;/li&gt;
&lt;li&gt;Inside of that folder create a project folder — in this case we’ll call it &lt;code&gt;interesting-places&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Creating and Saving a Project&lt;/h3&gt;
&lt;p&gt;Now that we have a folder for our project, let’s create one in QGIS. There are a few ways we can do this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Click the Project menu and select New&lt;/li&gt;
&lt;li&gt;Click the New Project button in the Project Toolbar&lt;/li&gt;
&lt;li&gt;Hold down Command and press N&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Next we should give the project a formal title:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;From the &lt;strong&gt;Project&lt;/strong&gt; menu choose &lt;strong&gt;Properties…&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Or press &lt;strong&gt;Shift Command P&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Make sure the &lt;strong&gt;General&lt;/strong&gt; tab is selected on the left&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Project title&lt;/strong&gt; text box enter Interesting Places&lt;/li&gt;
&lt;li&gt;Click OK&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We should now see that our QGIS window title has change from Untitled Project to Interesting Places.&lt;/p&gt;
&lt;p&gt;Now that our project has a title we can save it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Click on the &lt;strong&gt;Project&lt;/strong&gt; menu and choose &lt;strong&gt;Save&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Or press &lt;strong&gt;Command S&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Navigate to the interesting-places folder you created above&lt;/li&gt;
&lt;li&gt;Change the name in &lt;strong&gt;Save As&lt;/strong&gt; if you’d like&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Adding an OpenStreetMap Layer&lt;/h2&gt;
&lt;p&gt;You may have noticed that the main “document” area of QGIS is currently blank and gives us no idea where we are mapping. Fortunately we can use &lt;a href=&quot;http://openstreetmap.org&quot;&gt;OpenStreetMap&lt;/a&gt; to provide a nice base map to quickly visualize things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;Browser&lt;/strong&gt; panel on the left open up &lt;strong&gt;XYZ Tiles&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Right-click on the &lt;strong&gt;OpenStreetMap&lt;/strong&gt; entry and choose &lt;strong&gt;Add Layer to Project&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;You can also just double-click the &lt;strong&gt;OpenStreetMap&lt;/strong&gt; entry to add it to your project&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Panning and Zooming around a Map&lt;/h2&gt;
&lt;p&gt;When you start QGIS the default tool that’s enabled is the &lt;strong&gt;Pan Map&lt;/strong&gt; tool — the hand icon in the &lt;strong&gt;Map Navigation Toolbar&lt;/strong&gt;. You can click and drag to pan around the map but it’s not too helpful when we’re this zoomed out.&lt;/p&gt;
&lt;p&gt;Let’s get a closer look at things by zooming in:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Switch to the &lt;strong&gt;Zoom In&lt;/strong&gt; tool (the magnifying glass with the plus sign inside it)&lt;/li&gt;
&lt;li&gt;Click and drag a rectangle around the area that you are interested in&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Using the Locator Bar&lt;/h2&gt;
&lt;p&gt;Another way we can quickly find what we are looking for is by using the &lt;strong&gt;Locator Bar&lt;/strong&gt; in the lower left of the QGIS window:&lt;/p&gt;
&lt;p&gt;For example, if we wanted to find Easter Island we could use the &lt;a href=&quot;https://nominatim.org&quot;&gt;Nominatim Geocoder&lt;/a&gt; option to find it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Click on the &lt;strong&gt;Locator Bar&lt;/strong&gt; (or press Command K)&lt;/li&gt;
&lt;li&gt;Type the great than symbol &amp;gt; followed by a space and the words easter island&lt;/li&gt;
&lt;li&gt;Use the &lt;strong&gt;arrow keys&lt;/strong&gt; to navigate the entries&lt;/li&gt;
&lt;li&gt;Press &lt;strong&gt;Return&lt;/strong&gt; to select the highlighted entry&lt;/li&gt;
&lt;li&gt;You can also just double-click on the entry you are interested in&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can then use the &lt;strong&gt;Zoom In&lt;/strong&gt; tool to further refine the area you are looking for:&lt;/p&gt;
&lt;h2&gt;Creating Spatial Bookmarks&lt;/h2&gt;
&lt;p&gt;As we work maps we will likely be panning and zooming in and out. It would be convenient to be able to return to this initial view of the island after we’ve completed some detail work.&lt;/p&gt;
&lt;p&gt;To do that we can create what’s known as a &lt;strong&gt;Spatial Bookmark&lt;/strong&gt;. These bookmarks can be stored at a &lt;strong&gt;Project&lt;/strong&gt; level or a &lt;strong&gt;User&lt;/strong&gt; level. User level Spatial Bookmarks are good for locations you might need to refer to across several projects. In this case we’ll create a Project level Spatial Bookmark. Once again, there are a few ways to accomplish this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In the &lt;strong&gt;Browser&lt;/strong&gt; panel open up &lt;strong&gt;Spatial Bookmarks&lt;/strong&gt;, right-click on &lt;strong&gt;Project Bookmarks&lt;/strong&gt; and choose &lt;strong&gt;New Spatial Bookmark…&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Or, on the &lt;strong&gt;View&lt;/strong&gt; menu select new &lt;strong&gt;Spatial Bookmark…&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Or, press &lt;strong&gt;Command B&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Whichever method you choose you will be greeted with a **Bookmark Editor **dialog. For this bookmark we’ll set the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Name:&lt;/strong&gt; Easter Island&lt;/li&gt;
&lt;li&gt;**Saved in: **Project Bookmarks&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Leave everything else as is and click &lt;strong&gt;Save&lt;/strong&gt;. You should now see your new bookmark show up in the &lt;strong&gt;Browser&lt;/strong&gt; under &lt;strong&gt;Project Bookmarks&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;If we pan and zoom around the map and ever want to get back to this initial view, all we need to do is double-click the &lt;strong&gt;Easter Island&lt;/strong&gt; bookmark.&lt;/p&gt;
&lt;p&gt;This bookmark will also come in handy when creating a Print Layout, which is what we’ll do next.&lt;/p&gt;
&lt;h2&gt;Creating a Print Layout&lt;/h2&gt;
&lt;p&gt;Up until now we’ve been working in what’s called the &lt;strong&gt;Map View&lt;/strong&gt;. This view is a bit of a mixture between managing geographic data and styling geographic data.&lt;/p&gt;
&lt;p&gt;When we want to create a printable view of our map we need to create a &lt;strong&gt;Print Layout&lt;/strong&gt;. A &lt;strong&gt;Print Layout&lt;/strong&gt; will allow us to add things like titles, legends, north arrows, attributions, area maps and things of that nature. It will also let us save the resulting layout as a PDF and other image formats.&lt;/p&gt;
&lt;h3&gt;Adding a Print Layout&lt;/h3&gt;
&lt;p&gt;To create a new print layout:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Click on the &lt;strong&gt;Project&lt;/strong&gt; menu and choose &lt;strong&gt;New Print Layout…&lt;/strong&gt; (or press &lt;strong&gt;Command P&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Create Print Layout&lt;/strong&gt; dialog provide a title for your layout. We’ll call ours Landspace&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Setting the Page Size&lt;/h3&gt;
&lt;p&gt;Before we add any elements to our print layout we need to set the &lt;strong&gt;Page Size&lt;/strong&gt;. This is easiest to do when there’s nothing else on the map yet:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Right-click on the blank layout and choose &lt;strong&gt;Page Properties…&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;On the right side in the &lt;strong&gt;Item Properties&lt;/strong&gt; tab we can set the &lt;strong&gt;Size&lt;/strong&gt; and &lt;strong&gt;Orientation&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For my layout I’ll be setting the &lt;strong&gt;Size&lt;/strong&gt; to Letter and the &lt;strong&gt;Orientation&lt;/strong&gt; to Landscape&lt;/p&gt;
&lt;h3&gt;Adding a Map Title&lt;/h3&gt;
&lt;p&gt;Let’s add a title to our map so folks know what we’re showing:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In the Toolbox on the left click &lt;strong&gt;Add Label&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Click and drag a rectangle out at the top of the page&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Item Properties&lt;/strong&gt; on the right to set the &lt;strong&gt;Text&lt;/strong&gt;, &lt;strong&gt;Font&lt;/strong&gt;, &lt;strong&gt;Horizontal Alignment&lt;/strong&gt; and whatever other settings pique your interest&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Adding the Map&lt;/h3&gt;
&lt;p&gt;Of course our map isn’t much use with the actual location on it, so let’s add it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Click on the &lt;strong&gt;Add Map&lt;/strong&gt; tool in the &lt;strong&gt;Toolbox&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Click and drag a large rectangle out for the map&lt;/li&gt;
&lt;li&gt;If the correct area is not showing you can use the &lt;strong&gt;Bookmarks&lt;/strong&gt; button in the Item Properties panel to select the &lt;strong&gt;Spatial Bookmark&lt;/strong&gt; we made previously — another place it comes in handy!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It might seem silly to have to add the actual map to the layout but there are cases where you might want to have multiple maps in a layout, such as having a detailed view with an inset overview of the overall location.&lt;/p&gt;
&lt;h3&gt;Saving a PDF&lt;/h3&gt;
&lt;p&gt;The last step is to export our map as a PDF. Would you be surprised to learn there’s a couple of ways to do this?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;From the &lt;strong&gt;Layout&lt;/strong&gt; menu choose &lt;strong&gt;Export as PDF… &lt;strong&gt;or from the&lt;/strong&gt; Layout Toolbar&lt;/strong&gt; choose &lt;strong&gt;Export as PDF…&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Select the location and name you want to save the PDF as&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;PDF Export Options&lt;/strong&gt; you can leave everything as is and click &lt;strong&gt;Save&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The only thing left to do is open up your PDF and check it out.&lt;/p&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;This is only scratching the surface of what is possible with QGIS but what you’ve learned today will be the basis of many mapping projects in QGIS.&lt;/p&gt;
&lt;p&gt;If you’re interested in learning more please follow me on &lt;a href=&quot;https://www.youtube.com/@lostmapper&quot;&gt;YouTube&lt;/a&gt;. If you have any questions or suggestions, feel free to reach out to me on &lt;a href=&quot;https://mapstodon.space/@lostmapper&quot;&gt;Mastodon&lt;/a&gt;.&lt;/p&gt;</content:encoded></item></channel></rss>