Search code examples
c#postgresqlasp.net-corepostgisspatial

Uploading spatial data (.shp) to PostGIS db through a .NET Core app


I'm a beginner and I'm currently working on a pet project where a user could upload a shapefile (.shp) to a PostGIS database and then show the uploaded point, line or polygon on a interactive map.

I figured out the showing on map part but I'm clueless what my pipeline for user uploading the .shp files should look like. I added the test files using shp2pgsql. My project is in .NET core and I would be grateful for some code examples with pipeline suggestions.

Bonus question: is there a way to check the coordinate system of the .shp being uploaded?

Thank you!


Solution

  • You can use DotSpatial

                Shapefile shpfile =
                    Shapefile.OpenFile(shpFilePath);
                foreach (var feature in shpfile.Features)
                {
                    Console.WriteLine(feature.Geometry);
                }
    

    PS. Dependencies for code above are: DotSpatial.Data, DotSpatial.GeoAPI, DotSpatial.NetTopologySuite, System.Text.Encoding.CodePages