Example: Connect to a Shapefile usng GDAL/OGR

In this example we will use GDAL/OGR to get data from a shapefile.   This is a goofy thing to do, since Manifold can read/write shapefiles directly with no need to use third party software like GDAL/OGR, but sometimes the best way to learn how to use a third party thing like GDAL/OGR is to duplicate what we routinely do directly in Manifold.   GDAL/OGR is an open source library for reading many different GIS formats.   Manifold does not install GDAL/OGR automatically, but it is easy to download and install if we want to use it.

 

 To use GDAL or OGR we must install GDAL in Windows, and then we can use it from Manifold.  If we do not install GDAL, we will not be able to use the capabilities described in this topic. See the the GDAL / OGR topic for installation instructions. The Manifold GDAL dataport allows working with GDAL 2.0.x, 2.1.x , 2.2.x, 2.3, 2.4, or 3.0, and automatically selects the latest version available with automatic adjustments for the call interface.

Using GDAL from Manifold to Import a Shapefile

Because both GDAL/OGR and Manifold each have a vast library of formats they know, in many cases formats are supported both by Manifold native capabilities and also within GDAL.   If we want to import a format, such as shapefiles, that Manifold knows but for some reason we want to use GDAL code instead of Manifold native code we can do that.    

 

In the main menu choose File - Create - New Data Source.

 

 

Choose More... to launch the New Data Source dialog.

 

 

We specify the Name we want to use for the new data source and a Type of File: gdal.   Click the [...] browse button.

 

 

We browse into the folder where the desired shapefile is located and click it to highlight it and to enter the name into the File name box.  Click Open.

 

 

Back in the New Data Source dialog, click Create Data Source.

 

To fit into this documentation, the following illustration shows an artificially small Manifold desktop, with only a few panes, docked to the right side.   In real life we use a much larger Manifold desktop, and all panes would be turned on, with some panes docked to the left and others docked to the right.

 

 

Manifold creates a new data source named as we specified.  Expanding the data source and double-clicking on the drawing we open it to see that Manifold has connected through GDAL to the shapefile we want.

 

GDAL connections are always read-only, so we cannot edit this drawing.    If we want an editable version we should copy the drawing and the drawing's table and paste them into the project outside of the data source.  Even better, we should link the shapefile using Manifold's own shapefile dataport.

Linking a Shapefile Using Manifold's Own Dataport

Manifold, as we might expect, includes native ability to read/link/write shapefiles with no need to install or to rely upon any third party software.   See the SHP, Shapefiles  topic for a discussion and examples.  Manifold's own shapefile dataport is fully read/write, fully parallel and fully 64-bit.

 

Important: When linking a shapefile the tables and queries that appear in that data source in the Manifold project stay resident in the shapefile.   They are DB components even though they may appear in many respects, for the convenience of the user, to be Manifold components.   Shapefiles linked into a Manifold project are fully read/write.

 

We can use File - Create Data Source or simply choose File - Link.

 

 

The Save cache  button allows setting cache options.   Most often when linking to a format like shapefiles, we will ensure the Save cached box is not checked.  Working with a linked shapefile will be faster if we check the box, but if we are going to cache data within the project we may as well simply import the shapefileand use full Manifold speed.   We uncheck the box and then we press Link.

 

To link a shapefile:

 

  1. Choose File-Link from the main menu.

  2. In the Link dialog browse to the folder containing the .shp file.

  3. Click the .shp file desired.

  4. Check or uncheck the Save cache box as desired.

  5. Press Link.  A linked data source will appear in the project.

  6. Press the + icon next to the data source to expand the data source to see the tables and queries it contains.

 

 

That creates a data source called Mexico that contains the Mexico drawing and table in the shapefile.  We can click on the + icon by the data source cylinder to expand the Mexico hierarchy.  We also see the two system tables that seem to appear courtesy of Manifold's internal functioning.

 

 

Double-clicking the Mexico drawing, we can apply Style to color the provinces in Mexico that it shows.   Since it is linked, the drawing is still resident in the shapefile.

Problems with GDAL imports

If nothing appears when importing using GDAL, launch the Log Window to see if there are any error messages.   For example, when importing an ESRI .e00 file fails, in the Log Window you might see an error message such as:

 

*** (import) This looks like a compressed E00 file and cannot be processed directly. You may need to uncompress it first using the E00compr library or the e00conv program.

 

Error messages in the Log Window might report other problems, such as the necessary GDAL .dll files not being found.  That usually happens when the PATH environment variable does not include the GDAL installation folders.  See the discussion in the GDAL / OGR topic on setting the PATH environment variable.

 

Notes

File - Import -  This topic creates a data source using GDAL.   A much simpler procedure is to use File - Import, as shown in the Example: Import a Shapefile topic.

 

GDAL is not Manifold - When connecting to GDB using GDAL/OGR we must be aware we are no longer using Manifold code but instead are using GDAL code.  GDAL has earned a good reputation.  It is a tremendous advantage to use GDAL's very broad reach of modules from Manifold to connect to many niche or nearly-extinct formats, and GDAL does a great job at that.    However, GDAL's code in general is not as bulletproof as the Radian technology used in Manifold.  Connections using GDAL fall outside of Manifold's reputation for never crashing.      

See Also

Drawings

 

Style

 

Maps

 

GDAL / OGR

 

SHP, Shapefiles

 

Example: Connect to an ESRI GDB File Geodatabase - Connect Manifold to an ESRI GDB file geodatabase, display the contents, make a selection in the GDB and overlay in a map.

 

 

Example: Connect to an ESRI GDB usng GDAL/OGR  -  Instead of using Manifold's built-in ability to connect to modern ESRI GDB file geodatabases, use the Manifold GDAL/OGR dataport to take advantage of the GDAL library's ability to connect to deprecated GDB formats.