Mapping: My SHP file isn't where it should be.

You might get a SHP file from a colleague or download one from a website so that you can create a map with your data on it. When you open the SHP file in Epi Info’s mapping module, you notice it’s not where you expect it to be. It might even be on a different continent.

Most likely the issue has to do with a difference in the Coordinate Reference System (CRS) between the basemap you’ve selected and the SHP file you’re using to highlight some geographical feature (e.g, state or county boundaries).

Basemaps that are produced by Google or ESRI generally use a CRS=EPSG:3857. The CRS basically tells the software where to put the map in relation to the basemap.

So, the task then is to change the CRS of your SHP file to match the one used by the basemap. This cannot be done within Epi Info. It requires mapping software like ESRI’s ArcGIS or QGIS, which is free for download.

 

You should set aside approximately 30 minutes to do this task.

Example issue with Epi Info

The SHP file you’re going to see below is a boundary map for Compeche, a city in Mexico along the Yucatan Peninsula.

If you open the SHP file before having a base map in Epi Info, you won’t think there is any problem. The file looks like this:

SHP_open_EI.PNG

To add a base map in Epi Info, you have to select a Map Server. At the end of this document, you’ll find a table with some free map servers. There is also one included on the Epi Info screen that you can copy and paste. For this example, we’re going to use a simple, light gray map of the world (found below or just copy this link).

EI_base_layer.jpg
Epi Info’s Base Map screen

If you opened the base map after the SHP file, you won’t see anything other than the base map. You might spend some time scouring the entire map and you won’t find your city outline. The reason for this is that mapping programs present things in terms of “layers.” Those map details that are the top layer will be visible over those in lower layers. You can have many layers when working with maps.

At the bottom of your screen, you’ll see a small box that states “Map Layers 2.” This is a Map Layers pop-up and if you mouse-over this box, it will rise up and you will see this:

The #2 in this case is just letting you know that you have two layers on your map. If you had four layers, it would read “Map Layers 4.” You need to bring your Shapefile to the top-most layer for this example. The base map is gray and opaque--you can’t see through it, so your Shape file is hidden behind it. So, you have to move it to the top layer. You do that by the arrows to the right of the boxes. Incidentally, you can remove layers by clicking the “X.” If you do this accidentally, do not worry, you can just add the layer back as you did previously and arrange your layers to display as needed.

Once you do this, your map should look like this:

You’ll notice that the outline boundary for Campeche is in the wrong location on the wrong continent (red circle). The Campeche boundary area should be where the blue circle is.

 

To fix this issue, you can do one of three things:

  1. If you received this map from a colleague or mapping institution, you could ask them to create a new map with a different CRS that matches the base map EPSG:3857.

    1. It may even be possible that if you received your map from a GIS-related entity, they may be able to give you a base map that has the same CRS as your SHP file. That would be the easiest way to solve this problem.

  2. Download a different map which may or may not have the CRS you need.

  3. Fix the coordinate system yourself using GIS software.

 Instructions for changing a SHP file’s CRS in QGIS

For this tutorial, we’re going to use QGIS to change the CRS to match the base map. You can also do this with other mapping software. Since QGIS is free and relatively easy to use, we recommend that software to do mapping tasks that are beyond the capabilities of Epi Info.

Your version of QGIS might look slightly different than the version being used here depending on when you read this guide.

Assuming you have downloaded and installed QGIS, we’re going to use it to change the CRS of the SHP file that you have. Conceptually, we’re going to do the same thing we did in Epi Info. Open a SHP file; add a base layer; then make sure the SHP file is the top-most layer. Once the SHP file’s CRS gets changed and it’s in the correct location, we will have to EXPORT a different SHP file (and all the files that go along with a SHP file) and use the new file in Epi Info.

Let’s get started!

  1. Open QGIS and select ‘Project’ then choose ‘New’ or you can type ‘Ctrl + N’.

  2. Next, click ‘Layer’ then ‘Add Layer’ then select ‘Add Vector Layer’. Select you SHP file here.

     

  3. Once that is done, you can add a base layer easily by just double-clicking one in the QGIS browser under XYZ tiles. To match the one we used in Epi Info, select “Esri Gray (light) and double-click it.

Once both things are done (SHP file and base map added to QGIS), make sure your SHP file is the top-most layer in QGIS. If the base map is the top-most layer, just drag it under the SHP file. It should look like this . . . but, only for a second and then the base-map will disappear. Don’t be alarmed--there is a reason for this. What will be left on your screen will only be the SHP file’s boundaries (the part in green).

One thing you’ll notice right away is that QGIS correctly put the map boundary for Compeche on the correct continent. QGIS has a lot more GIS programming under-the-hood than Epi Info and correctly figured out where the ShapeFile should go. But, because the ShapeFile doesn’t have a CRS, QGIS is still unsure and the reason the base map disappears. If you removed the Compeche SHP file, the base map would reappear.

OK . . . so now what do we do?

Look in the lower right-hand corner of QGIS (bottom ribbon) and you will see ‘Unknown CRS.’ That message is telling us that one of our layers has an unknown CRS. If you hover over the base map, you’ll see what that layer’s CRS is. Our Shape File doesn’t have this . . . yet!

So, our base map has a CRS of EPSG:3857. That is what we need to set our SHP file to.

There are two ways to do this. The easiest is to right-click the base map (i.e., “Esri Gray (light)) and go to ‘Layer CRS,’ then choose ‘Set Project CRS from Layer’.

The alternative method is as follows:

Click the ‘Unknown CRS’ in the bottom ribbon of QGIS. When you do that, a CRS properties window is spawned giving you a lot of information about the project’s CRS.

In the ‘filter’ box, type in “EPSG:3857” and click “WGS 84 / Psuedo-Mercator” in the “Predefined Coordinate Reference Systems” box. Then click “Apply” at the bottom of the screen and then “OK.”

Voila! You have told QGIS that you want to use a specific CRS for this project and we can now see the SHP file and the base map at the same time.

But, the CRS of the SHP file is still not set, so we need to do that next.

If you right-click on the layer ‘campeche’ and select ‘Set Layer CRS’

On the next screen, choose ‘Predefined CRS’.

On the following screen, filter the options again to EPSG:3857 if it’s not already in your ‘Recently Used CRS’ box. Then click ‘OK.’

Now, if you hover over ‘campeche’ in the ‘Layers’ box, you’ll see it has the correct CRS. We’re almost finished.

Right-click on the ‘campeche’ layer and choose ‘Export’ then ‘Save Features As’.

There’s a lot going on in this dialog . . . so let’s take it slow.

First, you don’t want to save over your original SHP file. Keep that as it was in case something goes wrong.

Because there are a lot of other files that tag along with a SHP file, it’s best to create a new folder for your exported SHP file. Do this now.

Once you’ve created your folder make sure:

  • your Format is ‘ESRI Shapefile’

  • your File Name goes to your new folder and that you’re not over-writing your original SHP file

  • the CRS should be set to the Project CRS

  • now, check the box Extent

  • uncheck ‘Add saved file to map’ (this isn’t necessary since we already have this map on our screen). This entire exercise has been to merely export a new Shapefile with the correct CRS.

  • click OK

 

Now, you should have a newly exported SHP file in your export folder. If you don’t . . . or, if you have another file type (e.g., CSV), make sure your screen looks like the one above. You’re done with QGIS!

Now, go back to Epi Info and delete your original SHP file from the pop-up at the bottom of the screen (not your original SHP file).

Add in your new SHP file and make sure it is the top-most layer.

Your map should now look like this:

 

You are finished!

 Alternate sources for base maps

Epi Info used to come with a default basemap, but there were some licensening changes from ESRI, so we had to remove the default map. But, you can add your own using the links below.

Description

Base Map URL

Description

Base Map URL

ESRI World Map

World Map (Light Gray)

ESRI World Imagery

World Imagery

ESRI World Topography

World Topography

ESRI World Street Map

World Street Map