ToGeoJson and ToWKT for the Esri FGDB API

In support of some of our ongoing PIM work, we’ve been integrating the Esri File Geodatabase (FGDB) API into some tools. Without going into a level of detail that would hijack this post, one of the many functions performed by some of the tools is to validate physical spatial databases against established data models to analyze compliance and identify differences. These databases may be in Esri or non-Esri formats and we have traditionally handled Esri geodatabases through ArcObjects since it provides a relatively uniform interface across the various flavors of geodatabase.

Of course, ArcObjects requires an ArcGIS license of some sort and we are finding out that this is not always available to users in the field under many situations so the FGDB API gets past that for file geodatabases, at least.

Since the PIM is really a configuration management system for spatial data models, the tools need to support a wide variety of scenarios, including data migration between platforms, versions, approved user-defined implementations, etc. in a manner that’s compliant with the data model being managed. As a result, some ETL-like tools are built into the workflows, although ETL is not a primary focus of the PIM.

Since the PIM tools are written in .NET, I built a couple of extension methods to assist with some of the workflows in the existing tools. They enable outbound support for GeoJSON and WKT. The GeoJSON methods work on RowCollection, Row, and ShapeBuffer objects to create FeatureCollection, Feature, and Geometry types respectively. In practice, they’d be used something like this example from a very simple ASP.NET MVC sample application:

The WKT method only works on ShapeBuffer objects to export geometries. The code for the extension methods themselves can be found on GitHub here. It includes a five-minutes-or-less MVC sample from which the above code was lifted. I know I’ll be doing some cleanup on the GeoJSON in the near future and I’ll probably add support for EWKT to smooth our interactions with PostGIS and SpatiaLite and may also add support for WKB.

As I said, I developed these to support workflows in existing applications. If you’re looking to just perform data conversion or ETL, you should just use OGR or FME.