Import and Query GIS

This page shows how to upload a Shapefile to the GIS storage and how to query features within a polygon from it using the SDK. The sample writes out geometries of selected features in the Well Known Text (WKT) format to the console.

Shapefile format of spatial data consists of several files (e.g. .shp, .dbf, .shx, .prj, ...), which must be zipped into a zip archive for upload.

ITransferClient transferClient; // see SDK on how to get the transfer client
IGISClient gisClient; // see SDK on how to get the GIS client
var projectId = Guid.NewGuid(); // Provide relevant project Id.

var filePath = "./Data/countries.zip";

var dataset = await _transferClient
    .CreateFileImport(projectId, filePath)
    .WithReader(new GenericReader("ShpReader"))
    .WithWriter(new GenericWriter("GISWriter"))
    .ExecuteAndWaitAsync();

var queryGeometryWkt = "POLYGON((7.59 53.21,23.76 53.21,23.76 44.70,7.59 44.70,7.59 53.21))";
var wktReader = new WKTReader();
var queryGeometry = wktReader.Read(queryGeometryWkt);

var conditions = new QueryCondition[] {
    new SpatialQueryCondition { Geometry = queryGeometry, Operator = SpatialOperator.Intersects }
};

var fc = await gisClient.QueryFeatureClassAsync(_fixture.ProjectId, datasetId, conditions);

foreach(var feature in fc.Features){
    Console.WriteLine(feature.Geometry.AsText());
}