0

I want to "convert" cartesian coordinates of distance to meters.

I added

I try to use the following code:

        return new PagedList<Dto.DrugConsortium.CollectionSiteWithCoordinatesDto>(query.Select(p =>
            new Dto.DrugConsortium.CollectionSiteWithCoordinatesDto { CollectionSite = p, Distance = p.Location.ProjectTo(2855).Distance(myLocation) }).ToList(), pageIndex, pageSize);

where is my extension:

public static class GeometryExtensions
{
    static readonly IGeometryServices _geometryServices = NtsGeometryServices.Instance;
    static readonly ICoordinateSystemServices _coordinateSystemServices
        = new CoordinateSystemServices(
            new CoordinateSystemFactory(),
            new CoordinateTransformationFactory(),
            new Dictionary<int, string>
            {
            // Coordinate systems:

            // (3857 and 4326 included automatically)

            // This coordinate system covers the area of our data.
            // Different data requires a different coordinate system.
            [2855] =
                @"
                PROJCS[""NAD83(HARN) / Washington North"",
                    GEOGCS[""NAD83(HARN)"",
                        DATUM[""NAD83_High_Accuracy_Regional_Network"",
                            SPHEROID[""GRS 1980"",6378137,298.257222101,
                                AUTHORITY[""EPSG"",""7019""]],
                            AUTHORITY[""EPSG"",""6152""]],
                        PRIMEM[""Greenwich"",0,
                            AUTHORITY[""EPSG"",""8901""]],
                        UNIT[""degree"",0.01745329251994328,
                            AUTHORITY[""EPSG"",""9122""]],
                        AUTHORITY[""EPSG"",""4152""]],
                    PROJECTION[""Lambert_Conformal_Conic_2SP""],
                    PARAMETER[""standard_parallel_1"",48.73333333333333],
                    PARAMETER[""standard_parallel_2"",47.5],
                    PARAMETER[""latitude_of_origin"",47],
                    PARAMETER[""central_meridian"",-120.8333333333333],
                    PARAMETER[""false_easting"",500000],
                    PARAMETER[""false_northing"",0],
                    UNIT[""metre"",1,
                        AUTHORITY[""EPSG"",""9001""]],
                    AUTHORITY[""EPSG"",""2855""]]
            "
            });

    public static IGeometry ProjectTo(this IGeometry geometry, int srid)
    {
        var geometryFactory = _geometryServices.CreateGeometryFactory(srid);
        var transformation = _coordinateSystemServices.CreateTransformation(geometry.SRID, srid);

        return GeometryTransform.TransformGeometry(
            geometryFactory,
            geometry,
            transformation.MathTransform);
    }
}

ProjNet4GeoAPI nuget package is added (v 1.4.1)

But I can't resolve GeometryTransform class, it's not found.

How to resolve it?

Oleg Sh
  • 8,496
  • 17
  • 89
  • 159

1 Answers1

1

First GeometryTransform.TransformGeometry() is a method that is under NetTopologySuite.CoordinateSystems.Transformations namespace. Do you have

"using NetTopologySuite.CoordinateSystems.Transformations;"

at the top of your extension method?

Second I would add that 2855 is a coordinate system for NorthWest Washington state. I would check to see if your coordinates that you are using are within that area.

Also, each coordinate system has its own units of measurement. For example, SRID:4326 is in degrees for geometry(Cartesian coordinates) and meters for geography types.

SRID:2855 is in feet

You can check out this site to get a list of the coordinate systems available. https://epsg.io/

I am new to geography types and transforms but in my search this is what I found.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Brian W.
  • 118
  • 6