Shapefile Reader

  1. Home
  2. Docs
  3. Shapefile Reader
  4. Quickstart

Quickstart

Shapefile Reader quickstart

The basics

The Shapefile Reader plugin allows you to read data from SHP, SHX, and DBF files. Getting started with the Shapefile Reader plugin is really easy. Using Blueprints, after having installed and activated the plugin:

  • Step 1: Create an actor (or any Blueprint class) and open it
  • Step 2: Right-click on the graph and select the function Open Shapefile (under the category “ShapefileLib”)
    • Provide the path of your file as parameter of this function
  • Step 3: Draw a link from the Handler node, and call Read object
    • This pure function takes one parameter: the index of the object
  • Step 4: Get the result of Read object and extract the required data from the object

After following these steps, you should get a graph similar to the one given in the screen capture.

Once your process of the shapefile is done, don’t forget to call Close handler to close the file.

Preventing errors

This code contains two sources of errors that should be avoided.

Firstly, the previous code may fail if there is no shapefile for the given Path. To prevent this, you should always check the return value of the Open Shapefile function: it’s true if the file has been successfully opened, false otherwise.

Secondly, the code may fail if there are no object for the index 0 (i.e. the file is empty). We must know the total number of objects of the shapefile, and ensure that we don’t excess the max index. This can be done by a call to Get Entities Count on the Handler.

After preventing these sources of errors, we have the following graph:

It’s all you need to know to start using the Shapefile Reader to read shapefiles. For further information, you can read the Code Documentation.

Reading DBF files

Now that we know how to read from SHP files, it’s really easy to read from DBF files: it’s the same principle. A screen capture is worth a thousand words, so let’s see it:

As we can see, the main differences are the Open DBF call (instead of Open shapefile), and the access to the data (we’re accessing data of a DBF file instead of data of a SHP file). But globally it’s the same thing.

Was this article helpful to you? Yes No

How can we help?