How can I traverse a shapefile(.shp) and have height of each coordiantion?

874 Views Asked by At

I have downloaded a shapefile from here which provided a cantor map for me. I have got DotSpatial and loaded the map in c#. I need to traverse the map and get the height of each coordination.

I have created a 3d ViewPort in WPF by C# and have a grid that I just need have the height of each point on the grid to have a 3D map.

1- I don't know whether the file has the heights for coordinations or not. If this site doesn't provide a file with this attribute where can I get files that have height property in them?

2- How can I use DotSpatial to understand the minimum and maximum of Longitude and Latitude of the map?

I want to write some code like this.(It is just a pseudocode)

double dx = Math.Abs(MaxLongitude - minLongitude) / myMapGrid.Nx;
double dy = Math.Abs(MaxLatitude - minLatitude) / myMapGrid.Ny;
for (int x = 0; x < myMapGrid.Nx; x++)
{
    for (int y = 0; y < myMapGrid.Ny; y++)
    {
        double z = GetHeightOfCoordination(map, minLongitude+(x*dx), minLatitude+(y*dy));
        SetMapGridData(myMapGrid, x, y, z);
    }
}

3- and finally how can I get the height value of each coordination point?

1

There are 1 best solutions below

0
On
 var test = Shapefile.OpenFile(@"C:\yourpath");
 while (i < test.Features.Count)
    {
     var temp = test.GetFeature(i);
     var coordinates = temp.Coordinates
     for (int geo = 0; geo <= temp.NumGeometries - 1; geo++)
   {
    foreach (DotSpatial.Topology.Coordinate x in temp.GetBasicGeometryN(geo).Coordinates)
                    {
    int X = x.X;
    int Y = x.Y;
    int Z = x.Z;
    }
    }
    }

Or if you just wanna look at your temp.Coordinates you will get this: [{"M":"NaN","X":494869.712,"Y":5458703.355,"Z":"NaN","NumOrdinates":2}]

(Hopefully yours containing a Z value.)