-1

I 've question regarding spatial data and spatial data processing. Does anyone have any experience with spatial data or spatial data processing in .NET and can u please point me in right direction regarding spatial data packages.

In my search I've found this link but it's 10 years old and it is now pretty obsolete and unfortunately it doesn't serve my needs.

One of the requirements is that I can create spatial entities (polygon, line, point) from provided coordinates in WGS format (43.524477,26.571517...etc...) and the other is to be able to create some topological processing such as intersecting and clipping polygons and lines

At the moment, technology that I'm using is NHibernate as ORM and Maria DB as database provider.

Current version of my Microsoft.AspNet.Mvc solution is 5.2.3 and we are planning in very near future to transition in .NET Core 3.0.

Thank you in advance. Any link, advice and examples are highly appreciated

2

There's an Nuget package called Microsoft.SqlServer.Types that allows you to use spatial types in code.

https://www.nuget.org/packages/Microsoft.SqlServer.Types/

Despite being shipped with the "SqlServer" name, the types are actually fully independent and can load WKT from other sources, or simple lat/lng if that's what you have.

I found this code example in my github, I recall you have to ship the native assemblies so I am not sure whether this will work cross-platform.

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.SqlServer.Types;

namespace GeoCalc
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

            const int srid = 4326;

            var population = new List<PopulationDatum>();

            using (var s = typeof(Program).Assembly.GetManifestResourceStream("GeoCalc.Data.popcounts.txt"))
            using (var r = new StreamReader(s))
            {
                while (!r.EndOfStream)
                {
                    var line = r.ReadLine();

                    if (line == null) continue;

                    population.Add(new PopulationDatum(line, srid));
                }
            }

            var high = SqlGeography.Point(54.942380, -1.671109, srid);
            var low = SqlGeography.Point(51.929182, -1.071103, srid);

            const int radiusInMetres = 10000;

            var highScore = population
                .Where(p => p.Point.STDistance(high).Value <= radiusInMetres)
                .GroupBy(_ => 0)
                .Select(g => new PopulationScore(g.Sum(_ => _.Males), g.Sum(_ => _.Females), g.Sum(_ => _.Households)))
                .First();

            var lowScore = population
                .Where(p => p.Point.STDistance(low).Value <= radiusInMetres)
                .GroupBy(_ => 0)
                .Select(g => new PopulationScore(g.Sum(_ => _.Males), g.Sum(_ => _.Females), g.Sum(_ => _.Households)))
                .First();

        }
    }
}
| improve this answer | |

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.