GISBlox.IO.GeoParquet 1.0.0

dotnet add package GISBlox.IO.GeoParquet --version 1.0.0
                    
NuGet\Install-Package GISBlox.IO.GeoParquet -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GISBlox.IO.GeoParquet" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GISBlox.IO.GeoParquet" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="GISBlox.IO.GeoParquet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GISBlox.IO.GeoParquet --version 1.0.0
                    
#r "nuget: GISBlox.IO.GeoParquet, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GISBlox.IO.GeoParquet@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GISBlox.IO.GeoParquet&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=GISBlox.IO.GeoParquet&version=1.0.0
                    
Install as a Cake Tool

GISBlox.IO.GeoParquet

Introduction

This library allows you to read and write GeoParquet files in a simple and efficient way to and from System.Data.DataTables.

Features

  • Reads and writes GeoParquet metadata.
  • Reads a single column, some columns or all columns in GeoParquet files into a DataTable.
  • Writes one or more columns in a DataTable to a GeoParquet file.
  • Automatically infers the schema of the GeoParquet file from the DataTable and vice-versa.
  • Supports reading and writing geometries in WKT and WKB formats.

Installation

Stable releases are hosted on the default NuGet feed. You can install them using the following command on the package manager command line:

PM> Install-Package GISBlox.IO.GeoParquet

Reading data

To read data from a GeoParquet file, you can use the GeoParquetReader class.

Metadata

The following code snippet shows how to read the file's GeoParquet metadata, which defines how geospatial data is stored, including the representation of geometries and the required additional metadata:

using GISBlox.IO.GeoParquet;

string fileName = "path/to/file.parquet";

GeoFileMetadata metadata = GeoParquetReader.ReadGeoMetadata(fileName);

The ReadGeoMetadata method returns a GeoFileMetadata type with information according to version 1.1.0 of the GeoParquet Specification. A more detailed example is available here.

Read all columns

To read the entire file you can use the following code snippet:

string fileName = "path/to/file.parquet";

DataTable dataTable = GeoParquetReader.ReadAll(fileName, GeometryFormat.WKT);

The ReadAll method reads all data from a GeoParquet file into a DataTable. The format parameter specifies the desired format for the geometries in the DataTable. The supported formats are WKT (Well-Known Text) and WKB (Well-Known Binary).

Read one column

To read a single column from a file you can use the following code:

string fileName = "path/to/file.parquet";

DataTable dataTable = GeoParquetReader.ReadColumn(fileName, "geometry", GeometryFormat.WKT);

The ReadColumn method reads a single column from a GeoParquet file into a DataTable. The column parameter either specifies the name of the column or the column index:

string fileName = "path/to/file.parquet";

// Read the second column from the file in WKB format
DataTable dataTable = GeoParquetReader.ReadColumn(fileName, 1, GeometryFormat.WKB);

👉 You can retrieve any column from the file, not just the geometry column(s).

Read two or more columns

In case you want to read two or more columns from a file you can use the following code:

string fileName = "path/to/file.parquet";
IList<string> columnNames = ["name", "geometry"];

DataTable dataTable = GeoParquetReader.ReadColumns(fileName, columnNames, GeometryFormat.WKT);

The ReadColumns method reads two or more columns from a GeoParquet file into a DataTable. The columnNames parameter specifies the names of the columns to read. Another overload of this method allows you to specify the column indexes instead of the column names:

string fileName = "path/to/file.parquet";
IList<int> columnIndexes = [1, 2];

// Read the second and third columns from the file in WKB format
DataTable dataTable = GeoParquetReader.ReadColumns(fileName, columnIndexes, GeometryFormat.WKB);

👉 You can retrieve any number of columns from the file, not just the geometry column(s).

Writing data

To write data to a GeoParquet file, you can use the GeoParquetWriter class.

Write WKT geometries

The following code snippet shows how to write a DataTable with WKT geometries to a GeoParquet file:

string fileName = "path/to/file.parquet";

// Define data table
var dataTable = new DataTable();
dataTable.Columns.Add("id", typeof(int));
dataTable.Columns.Add("name", typeof(string));
dataTable.Columns.Add("geometry", typeof(string));

// Add rows
dataTable.Rows.Add(1, "Amsterdam", "POINT (4.8913 52.3684)");
dataTable.Rows.Add(2, "Rotterdam", "POINT (4.4868 51.913)");

GeoParquetWriter.Write(fileName, dataTable, "geometry", GeometryFormat.WKT);

The geometryColumn parameter specifies the name of the geometry column in the DataTable. The format parameter specifies the format of the geometries in the DataTable. The supported formats are WKT (Well-Known Text) and WKB (Well-Known Binary).

The GeoParquetWriter supports writing to either a file or a System.IO.Stream. The following sample shows how to write to a stream:

// Continuing from the previous example...
using var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
GeoParquetWriter.Write(fileStream, dataTable, "geometry", GeometryFormat.WKT);

Write WKB geometries

Writing WKB geometries is similar to writing WKT geometries. The following code snippet shows how to write a DataTable with WKB geometries to a GeoParquet file:

string fileName = "path/to/file.parquet";

// Define data table
var dataTable = new DataTable();
dataTable.Columns.Add("id", typeof(int));
dataTable.Columns.Add("name", typeof(string));
dataTable.Columns.Add("geometry", typeof(byte[]));

// Add rows
dataTable.Rows.Add(1, "Amsterdam", new byte[] { 1, 1, 0, 0, 0, 255, 178, 123, 242, 176, 144, 19, 64, 87, 236, 47, 187, 39, 47, 74, 64 });
dataTable.Rows.Add(2, "Rotterdam", new byte[] { 1, 1, 0, 0, 0, 109, 197, 254, 178, 123, 242, 17, 64, 190, 159, 26, 47, 221, 244, 73, 64 });

GeoParquetWriter.Write(fileName, dataTable, "geometry", GeometryFormat.WKB);

Write multiple geometry types

The following code snippet shows how to write a DataTable with multiple geometry types:

string fileName = "path/to/file.parquet";

// Define data table
var dataTable = new DataTable();
dataTable.Columns.Add("id", typeof(int));
dataTable.Columns.Add("name", typeof(string));
dataTable.Columns.Add("geometry", typeof(string));

// Add rows
dataTable.Rows.Add(1, "Amsterdam", "POINT (4.8913 52.3684)");
dataTable.Rows.Add(2, "Rotterdam", "POINT (4.4868 51.913)");
dataTable.Rows.Add(3, "Connection", "LINESTRING (4.8913 52.3684, 4.4868 51.9130, 4.2949 52.0641)");
dataTable.Rows.Add(4, "Area", "POLYGON ((4.8913 52.3684, 4.4868 51.9130, 4.2949 52.0641, 4.8913 52.3684))");
dataTable.Rows.Add(5, "Den Haag", "POINT (4.2949 52.0641)");

GeoParquetWriter.Write(fileName, dataTable, "geometry", GeometryFormat.WKT);

Inspecting the geo metadata of the new file will show that the geometries are stored in the geometry column with the correct geometry types:

{
  "version": "1.1.0",
  "primary_column": "geometry",
  "columns": {
    "geometry": {
      "additionalProperties": false,
      "bbox": [
        4.2949,
        51.913,
        4.8913,
        52.3684
      ],
      "edges": "Planar",
      "encoding": "WKB",
      "epoch": 0,
      "geometry_types": [
        "Point",
        "LineString",
        "Polygon"
      ]
    }
  }
}

Write two or more geometry columns

A GeoParquet file may contain more than one geometry column. The following code snippet shows how to write a DataTable with two geometry columns:

string fileName = "path/to/file.parquet";

// Define data table with two geometry columns
var dataTable = new DataTable();
dataTable.Columns.Add("id", typeof(int));
dataTable.Columns.Add("name", typeof(string));
dataTable.Columns.Add("geometry1", typeof(string));
dataTable.Columns.Add("other name", typeof(string));
dataTable.Columns.Add("geometry2", typeof(string));

// Add rows
dataTable.Rows.Add(1, "Amsterdam", "POINT (4.8913 52.3684)", "Utrecht", "POINT (5.1037 52.0988)");
dataTable.Rows.Add(2, "Rotterdam", "POINT (4.4868 51.913)", "Den Haag", "POINT (4.2949 52.0641)");

// Specify geometry columns
Dictionary<string, GeometryFormat> geoColumns = new()
{
   { "geometry1", GeometryFormat.WKT },
   { "geometry2", GeometryFormat.WKT }
};

GeoParquetWriter.Write(fileName, dataTable, geoColumns, "geometry1");

👉 All these examples, and more, are available in the Test project.

Dependencies

Questions

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 116 1/24/2025