Reading shapefile coordinates in C #

I want to draw a polyline on "XAML Map Control" with latitude / longitude using the contents of the shapefile.

I have 2 types of shapefile:

  • One with .dbf, .prj, qpj, .shx and, obviously, .shp files.
  • One with a .shp file

Reading with both types of files with different libraries (Net Topology Suite, and now DotSpatial), I get a list of coordinates (DotSpatial.Topology.Coordinate), for example:

X 456874.625438354 Y 5145767.7929015327 
  • How can I convert to latitude / longitude format?
  • What is the current format?
  • Are the files that accompany the .shp file useful?
+5
source share
1 answer

You can use DotSpatial to reprogram to long. If you are reading in a shapefile, and the .prj file exists so that the projection is known, then you only need:

  Shapefile sf = Shapefile.OpenFile("C:\myshapefile.shp"); sf.Reproject(DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984); 

If, however, the .prj file is missing, you need to first define the projection as:

  Shapefile sf = Shapefile.OpenFile("C:\myshapefile.shp"); sf.Projection = DotSpatial.Projections.KnownCoordinateSystems.Projected.UtmWgs1984.WGS1984UTMZone32N; sf.Reproject(DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984); 

But if, for example, you don’t have a shapefile, and you just want to reprogram the coordinate set from one projector to another, you can directly use the reprogramming utility:

  // interleaved x and y values, so like x1, y1, x2, y2 etc. double[] xy = new double[]{456874.625438354,5145767.7929015327}; // z values if any. Typically this is just 0. double[] z = new double[]{0}; // Source projection information. ProjectionInfo source = DotSpatial.Projections.KnownCoordinateSystems.Projected.UtmWgs1984.WGS1984UTMZone32N; // Destination projection information. ProjectionInfo dest = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984; // Call the projection utility. DotSpatial.Projections.Reproject.ReprojectPoints(xy, z, source, dest, 0, 1); 

This last method uses an array such that the projection module can work without a direct reference to the data module.

+5
source

Source: https://habr.com/ru/post/1205210/


All Articles