ThinkGeo.com    |     Documentation    |     Premium Support

How to calculate latitude and longitude from MultipolygonShape shape

Hi,

How to calculate latitude and longitude from MultipolygonShape.

Thanks,
I am not sure the mean of this one.
If you want to get the center point of the MultipolygonShape. You could try with

var centerPoint = multipolygonShape.GetCenterPoint();

If you want to get each point of the MultipolygonShape. You could try with

multipolygonShape.Polygons[i].InnerRings[j].Vertices[k].X;
multipolygonShape.Polygons[i].InnerRings[j].Vertices[k].Y;

and

    multipolygonShape.Polygons[i].OuterRing.Vertices[k].X
    multipolygonShape.Polygons[i].OuterRing.Vertices[k].Y

Hope this is helpful.

Thanks

Frank

Thanks,

In our application we need to calculate Township, Section and range for legal location.
We are using below API to get these values.

https://gis.blm.gov/arcgis/rest/services/Cadastral/BLM_Natl_PLSS_CadNSDI/MapServer/exts/CadastralSpecialServices/GetTRS?lat={lat}&lon=-{lng}&units=DD&returnlevel=S&returnalllevels=&f=json

This API takes Latitude and Longitude values as input parameters.
We only have Shape data of location and to call above API we need to calculate Latitude and Longitude values.
Please suggest method to be used to calculate latitude and longitude values using ThinkGeo.Core (version 12.0.0.0).

Thanks,
I assume the service will return the property of the specify point. Here is my suggestion.

        MultipolygonShape multipolygonShape = new MultipolygonShape(); // Get your MultipolygonShape
        for (int i = 0; i < multipolygonShape.Polygons.Count; i++)
        {
            var point = multipolygonShape.Polygons[i].GetCenterPoint();
            if (!multipolygonShape.Polygons[i].Contains(point))
            {
                point = multipolygonShape.Polygons[i].GetClosestPointTo(point, GeographyUnit.Meter);
            }
            var latitude = point.Y;
            var longitude = point.X;
            // Use latitude and longitude to call the services
        } 

We are not sure the center point will be inside of the polygon. So we may need find another point in the polygon.

Thanks

Frank

Thanks,
We tried above solution and we are getting below values for Latitude and Longitude.
Latitude: 4996002.1941397255
Longitude:-10115992.205388704

It seems the values are not valid, to call the Legal location API we need to pass latitude and longitude in below format.

This API returns below response. It contains TownShip, Range and Section values.
IL040150N0100E0SN170

Thanks,
You need convert the projection. I assume the one in the shape file is 3857 projection. You need convert it to 4326. Here is the code.

ProjectionConverter projectionConverter = new ProjectionConverter(3857, 4326);
var point = new PointShape(-10115992.205388704, 4996002.1941397255);
projectionConverter.Open();
var result = (PointShape)projectionConverter.ConvertToExternalProjection(point);
// use result.X and result.Y

Thanks

Frank