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.

 

ico_nb_arrow_blue.png  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.    

 

eg_gdb_gdal01_19.png

 

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

 

eg_gdb_gdal01_20.png

 

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.

 

eg_gdb_gdal01_21.png

 

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

 

eg_gdb_gdal01_22.png

 

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.

 

dlg_link_shp.png

 

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.

 

eg_link_shp01_01.png

 

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.

 

eg_link_shp01_02.png

 

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.

 

Notes

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

 

GDAL is not Manifold - When connecting to data using GDAL/OGR we must be aware we are no longer using Manifold code but instead are using GDAL code.  GDAL modules have been created over many years by different people and have varying quality, but overall GDAL has earned a good reputation.  GDAL is a solid product that can be used with confidence.  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, so 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.