Visualize Country Borders and IP Addresses
This guide describes how to apply the Countries and IP Addresses georeference analysis to transform data into geometries that can be visualized.
CHEATSHEET: Georeference Types
The following types of location text can be geocoded and applied to your data:
- Longitude and Latitude: Generates location points using two parameter columns, one for longitude values and one for latitude values.
- Cities: Generates location points using a single parameter column with city name values. For greater accuracy, you can specify a column to be used for the admin. region names, or alternatively, specify a column for country names. For both admin. regions and country names, you can enter custom values by typing in the name (if the data is within a single region or country. For example, manually type in and select `United States`).
- Countries: Requires a single parameter column with country names to generate location border geometries as polygons.
- Admin. Regions: Requires a single parameter column with admin. region names to generate location points. You can also specify a column to be used for country names (if all are unique), or alternatively, type in the custom country name.
- Postal Codes: If your dataset consists of a column with postal codes, this option geocodes those values to generate location points. Your input data must be a text column. You can also specify a column to be used as a country names, similar to the Admin. Regions option. For specific details about how CARTO geocodes US zip codes, see the Postal Code Geocoder section in the Data Servies API documentation.
- IP Addresses: Geocodes your data into point geometries for IP addresses. This is useful if you are analyzing location data based on a set of user’s IP addresses.
- Street Addresses: Geocodes your data into a point geometry for a street address. You can specify the column to be used for the street addresses, in addition to the columns to be used for the city, state and country. You can also specify custom fields using the Advanced Mode.
If a map layer contains raw country data, (where the connected dataset contains a column with country values but the
the_geomcolumn has no coordinates), the connected layer may appear empty. The Countries georeference analysis geocodes your country values and transforms them into country borders, represented by polygons.
Your data must contain either the English name of a country, or the local government endonym. Additionally, ISO (International Organization for Standardization) codes are recognized (such as ISO2 or ISO 3); where each country is represented by two or three letters.
A public IP address is a globally unique address assigned to identify a computing device. Public IP Addresses might be used to locate a group of internet users. If a map layer contains raw IP addresses (where the connected dataset contains a column with IP Address values but the
the_geomcolumn has no coordinates), the connected layer may appear empty. The IP Addresses georeference analysis geocodes your values and transforms them into point geomtries.
When you import data into your account, CARTO automatically includes “intelligent guessing” functionality during the import process. This enables CARTO to read and populate the columns in your dataset when files are missing required upload information. This is also helpful as it can geocode data for some values if geometries are missing. In some cases, you may want to disable this feature if you want to enforce a certain column type or geometry.
For this guide, suppose you are a technology company that provides a digital service and you want identify where to expand marketing opportunities based on internet use. You also want to avoid any computing devices that are known as threats; meaning you want to block any IP Addresses that have been identified as spam.
Two datasets were manually created, and will be provided for this example.
The first dataset, Internet Users by Country, identifies how many people are online in different countries. This layer was created based on data modified from the Central Intelligence Agency’s publication of the World Factbook.
The second dataset, Blocked IP Addresses, was created based on the Raw IPs for the Firewall Block Lists, provided by Emergingthreats.net.
By default, the import guessing functionality automatically geocodes our raw country data; since Builder is able to recognize country names and ISO names!
For this example, let’s remove import guessing during the import process and georeference this data into geometries that can be visualized.
Remove Import Guessing
CARTO automatically includes guessing functionality during the import process, which is useful when files are missing required upload information, such as raw country data. Raw country data might be a table of information, but without any location coordinates. For example, a table of birth rates (by country rankings) that you created based on information provided from Wikipedia.
country | rate Angola | 20% Australia | 21% ...
From Your maps dashboard in CARTO, click NEW MAP.
template_blocked.cartofile, packaged from “Download resources” of this guide.
Click on “Download resources” from this guide to download the zip file to your local machine. Extract the zip file to view the file(s) used for this guide.
Before connecting the map, deselect the Let CARTO automatically guess data types and content on import checkbox.
Why remove import guessing? Since this example contains datasets that were built from scratch,
the_geom column contains no values and requires georeferencing. When sharing .carto files however, Builder automatically georeferences values during the import process. For the purposes of reproducing the behavior as if you created your own dataset, remove import guessing during the import process.
- Click CONNECT DATASET.
Builder opens with Internet Users by Country as the first map layer and Blocked IP Addresses as the second map layer. Both layers indicate that there is no geometry.
- Switch to the Data View for either map layer,
the_geomcolumn contains null values, which indicates that the type of geometry is not identifed.
The Data View and Map View appear as icons on your map visualization when a map layer is selected. Click to switch between viewing your connected dataset as a table, or show the map view of your data.
Let’s transform our values into geometries by applying the Georeference analysis.
Geocode Country Values into Polygons
Geocode country values to visualize how data is transformed into country borders.
Click on the Internet Users by Country map layer.
The STYLE tab indicates that there is no geometry data and provides a shortcut to georeference your data.
Click the ANALYSIS tab and apply the following analysis.
- Select Georeference from the Add a new analysis options.
- Select Countries as the Georeference TYPE.
- Select the column name to be used for the COUNTRY option. For this example, select the
regionnamefrom the dataset.
- Click APPLY.
If you switch the Data View,
the_geom column indicates that polygon geometries have been created for your values!
Display IP Addresses as Point Geometries
From the LAYERS pane in Builder, click the Blocked IP Addresses layer.
Click the GEOREFERENCE shortcut button from the STYLE tab, or navigate to the ANALYSIS tab.
Select Georeference from the Add a new analysis options.
Select IP Adressess as the Georeference TYPE.
Select the column name to be used for the IP Addresses option. For this example, select the
ip_addressesfrom the dataset.
If you switch the Data View,
the_geomcolumn indicates that polygon geometries have been created for your values.
Download the final .carto file, packaged from the “Download resources” of this guide, to view how missing geometries was transformed into countries and IP Addresses. The final map also includes an additional Filter by layer analysis to filer the blocked IP Addresses by country and also includes some widgets.
Geocoder Functions with the API
If you are a developer and have access to the CARTO Engine’s to manage your data, view the Country Geocoder Functions and the IP Addresses Geocoder Functions that can be applied with the Data Services API.
Did you like this guide?
We would love to hear from you! Was it easy to understand? Do you need more information? Let us know.