Пример #1
1
 public static void Main(string[] args)
 {
     try
     {
         /* -------------------------------------------------------------------- */
         /*      Initialize srs                                                  */
         /* -------------------------------------------------------------------- */
         SpatialReference src = new SpatialReference("");
         src.ImportFromProj4("+proj=latlong +datum=WGS84 +no_defs");
         Console.WriteLine( "SOURCE IsGeographic:" + src.IsGeographic() + " IsProjected:" + src.IsProjected() );
         SpatialReference dst = new SpatialReference("");
         dst.ImportFromProj4("+proj=somerc +lat_0=47.14439372222222 +lon_0=19.04857177777778 +x_0=650000 +y_0=200000 +ellps=GRS67 +units=m +no_defs");
         Console.WriteLine( "DEST IsGeographic:" + dst.IsGeographic() + " IsProjected:" + dst.IsProjected() );
         /* -------------------------------------------------------------------- */
         /*      making the transform                                            */
         /* -------------------------------------------------------------------- */
         CoordinateTransformation ct = new CoordinateTransformation(src, dst);
         double[] p = new double[3];
         p[0] = 19; p[1] = 47; p[2] = 0;
         ct.TransformPoint(p);
         Console.WriteLine("x:" + p[0] + " y:" + p[1] + " z:" + p[2]);
         ct.TransformPoint(p, 19.2, 47.5, 0);
         Console.WriteLine("x:" + p[0] + " y:" + p[1] + " z:" + p[2]);
     }
     catch (Exception e)
     {
         Console.WriteLine("Error occurred: " + e.Message);
         System.Environment.Exit(-1);
     }
 }
    public static string ToCoordinateSystem(string srs, bool isName)
    {
      if (string.IsNullOrEmpty(srs))
        return srs;

      string result = null;
      if (_srCache.TryGetValue(srs, out result))
        return result;

      using (SpatialReference sr = new SpatialReference(null))
      {
        if (isName)
        {
          int srsId;
          if (int.TryParse(srs, out srsId))
            sr.ImportFromEPSG(srsId);
          else
          {
            // TODO
          }
        }
        else
        {
          if (srs.StartsWith("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0"))
          {   //      +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs
              //sr.ImportFromProj4(srs);
            sr.ImportFromEPSG(900913);
          }
          else
          {
            sr.ImportFromProj4(srs);
          }
        }

        sr.ExportToWkt(out result);

        if (result != null)
          _srCache.TryAdd(srs, result);

        return result;
      }
    }
        private static NetTopologySuite.Geometries.Point Wgs84ToWgs84UpsNorth(Point location)
        {
            if (location.SRID != 4326)
            {
                throw new Exception("Unsupported coordinate system: " + location.SRID);
            }

            OSGeo.OSR.SpatialReference wgs84Src = new OSGeo.OSR.SpatialReference("");
            wgs84Src.ImportFromProj4("+proj=longlat +datum=WGS84 +no_defs");

            OSGeo.OSR.SpatialReference stereoNorthPoleDest = new OSGeo.OSR.SpatialReference("");
            stereoNorthPoleDest.ImportFromProj4("+proj=stere +lat_0=90 +lat_ts=90 +lon_0=0 +k=0.994 +x_0=2000000 +y_0=2000000 +datum=WGS84 +units=m +no_defs");

            OSGeo.OSR.CoordinateTransformation ct = new OSGeo.OSR.CoordinateTransformation(wgs84Src, stereoNorthPoleDest);

            double[] point = new double[3];
            point[0] = location.X;
            point[1] = location.Y;
            point[2] = location.Z;

            ct.TransformPoint(point);

            return(new Point(point[0], point[1]));
        }