I'm using GDAL\ogrinfo.exe to read the tab file which includes polygon/LineString/Point coordinates as a stream using the process. I'll store the coordinates in the MongoDB.

My attempt at inserting LineString was a success by using:


I used GeoJsonPolygonCoordinates<GeoJson2DGeographicCoordinates and kept getting the error

{"A bulk write operation resulted in one or more errors.\r\n location object expected, location array not in correct format"}

I used the QGIS to check the tab file, if the polygon is a closed one GeoJsonPolygonCoordinates<GeoJson2DGeographicCoordinates done the job no prob. But if the tab file is like the attached image the ex-occurs.

Sample polygon layout from QGIS

1 Answer 1


Found the answer. As I suspected it was simple enough. Need to use GeoJson.Polygon<TCoordinates> Method (GeoJsonObjectArgs<TCoordinates>, GeoJsonPolygonCoordinates<TCoordinates>) GeoJson Polygon

Some code for reference:

        IMongoClient client = new MongoClient(_mongoConnString);
        var database = client.GetDatabase(MONGO_DB_NAME);

        var collection = database.GetCollection<MongoFence>(MONGO_COLLECTION_NAME);         

        IndexKeysDefinition<MongoFence> keyLocation = "{ Polygon: '2dsphere' }";                
        var locationIndexModel = new CreateIndexModel<MongoFence>(keyLocation);

        GeoJson2DGeographicCoordinates one  = new GeoJson2DGeographicCoordinates(-122.335604, 48.390017);
        GeoJson2DGeographicCoordinates two = new GeoJson2DGeographicCoordinates(-122.333195, 48.390053);
        GeoJson2DGeographicCoordinates three = new GeoJson2DGeographicCoordinates(-122.333088, 48.391189);
        GeoJson2DGeographicCoordinates four = new GeoJson2DGeographicCoordinates(-122.335529, 48.39116);
        GeoJson2DGeographicCoordinates five = new GeoJson2DGeographicCoordinates(-122.335631, 48.390809);
        GeoJson2DGeographicCoordinates six = new GeoJson2DGeographicCoordinates(-122.335604, 48.390017);

        GeoJson2DGeographicCoordinates[] coord_array = new GeoJson2DGeographicCoordinates[] { one, two, three, four, five, six };

        var fenceList = new List<MongoFence>();
        fenceList.Add(new MongoFence
            Name = "1",
            Polygon = GeoJson.Polygon(coord_array)

        await collection.InsertManyAsync(fenceList);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.