How do I create a relationship between points and territories not already found in my data set?

You probably already have a relationship in your data model between your locations and their corresponding Country, State, or Postal Code.  But what about relationships between a location and something non-standard like Census Tract, County, MSA, or a custom Sales Territory?

Note: It is strongly recommended that you use QGIS 2.2 or newer since it performs much faster than earlier versions for the following operations. A link to download QGIS can be found on our Helpful Links page.

Example

Example

In this example, we will find the corresponding Sales Region for each Customer in our data model using QGIS.  Above is what the final product will look like.

Add point layer

Add point layer

Open QGIS, and add a point layer (Layer -> Add Delimited Text Layer) that represents the data elements you want to relate to the territory.  Typically this will be a list of customers/locations in a .csv file, but it can be any type of point layer.  In this example, we use a file called “Customer.csv”.

NOTE: Ensure that your CRS format is correct according to the standard in your country. In the US, this is commonly "EPSG:4326 - WGS 84".

Add vector layer

Add a polygon layer that represents the territory to which you want to relate the points.  Typically this will be a shapefile/KML file of your territories.  Shapefiles for frequently used territories (like Zip, County, Census Tract, and MSA) can be found on the QlikMaps download site, but you can also use your own custom territory files.  In this example, we use a shapefile called “Regions” that contains the boundary definitions for our custom Sales Regions.

NOTE: Ensure that your CRS format is correct according to the standard in your country. In the US, this is commonly "EPSG:4326 - WGS 84".

NOTE: The CRS format for your vector layer should match the CRS format for your point layer (in general, it is good practice to use the same CRS for all layers when working in QGIS).

Create Spatial Index

Create Spatial Index

NOTE: Before you do any geocoding, you should always create a spatial index for each layer you are going to work with. Do this by right-clicking on each layer, going to Properties -> General -> Create spatial index. This will greatly increase the speed of your geocoding processing.

Join attributes

Join attributes

Go to Vector -> Data Management Tools -> Join attributes by Location

Select your Points layer as the “Target vector layer” and your Polygon layer as your “Join Vector Layer.”  Even though you won’t need it later, you must specify an output shapefile that will contain the joined features.  Click “OK".

When processing is complete, select “Yes” when prompted “Would you like to add the new layer to the TOC?”

Right-click on the new layer and select “Save As…”

Under the “Format” drop-down box, select “Comma Separated Value” and specify a file name.