Table of Contents

Method ImportGeoJSON

Namespace
YndigoBlue.Velocity.Engine
Assembly
YndigoBlue.Velocity.dll

ImportGeoJSON(Table, string, GeoJSONImportConfig, bool)

Imports a GeoJSON file into a database table.

public void ImportGeoJSON(Table table, string dataFilePath, GeoJSONImportConfig geoJsonImportConfig, bool streamImport = false)

Parameters

table Table

The Table to import data into.

dataFilePath string

The path to the GeoJSON file to import.

geoJsonImportConfig GeoJSONImportConfig

A GeoJSONImportConfig mapping the features' geometry, id and properties onto table columns.

streamImport bool

When true the file is read and sent to the database in chunks of ImportBatchSize features instead of being loaded into memory in full first. Defaults to false.

Examples

using (var m = new Manager(conn))
{
    var schema = m.LoadSchema("app");
    var sitesTable = schema["sites"];

    var config = new GeoJSONImportConfig();
    config.MapGeometry("location", DataType.Geography);
    config.MapId("site_id", DataType.Long);
    config.MapProperty("location_name", "name", DataType.VarChar);
    config.MapProperty("contact_info.manager", "manager", DataType.VarChar);

    m.ImportGeoJSON(sitesTable, "sites.geojson", config);

    // Stream a large file rather than loading it all into memory
    m.ImportGeoJSON(sitesTable, "sites_1m_features.geojson", config, streamImport: true);
}

Remarks

Warning

The ImportGeoJSON method is not available in the Community Edition of Velocity. It requires the Full Edition.

Features are appended to the table, exactly as rows are by ImportData(Table, string, ImportConfig, bool); the table is not emptied first. Columns the configuration does not map are left to the database.

Every object GeoJSON allows at the top level is accepted. A FeatureCollection imports one row per feature; a bare Feature, or a bare geometry of any type (Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon or GeometryCollection), imports one row. A bare geometry carries neither an id nor properties, so only a geometry mapping draws anything from it.

A Feature has three parts and each is mapped separately: the geometry with MapGeometry(string, DataType), the top-level id with MapId(string, DataType), and entries under properties with MapProperty(string, string, DataType). A nested property is addressed with a dotted path such as contact_info.manager, and a path that does not resolve imports as null rather than failing.

Arrays are not supported: a property holding an array, or a path that runs through one, imports as null.

Exceptions

DbException

Thrown when a database error occurs.

InvalidImportMappingsException

Thrown when a mapped column does not exist on the table, or a value cannot be converted to its column's type.

ValueSetForAutoGeneratedColumnException

Thrown when a mapping targets an auto-increment column and KeepIdentity is not set.

InvalidDataException

Thrown when the file is not well-formed GeoJSON, or is a JSON document of some other kind.

See Also