Beispiel #1
0
        /// <summary>
        /// Coordinate transformation between two world coordinate systems
        /// This Version works with coordinates as X, Y doubles
        /// </summary>
        /// <param name="wkTextSource">The wk text source.</param>
        /// <param name="wkTextTarget">The wk text target.</param>
        /// <param name="inputPointX">The input point X.</param>
        /// <param name="inputPointY">The input point Y.</param>
        /// <param name="transformedPointX">The transformed point X.</param>
        /// <param name="transformedPointY">The transformed point Y.</param>
        /// <returns></returns>
        public static bool TransformPoint2d(string wkTextSource, string wkTextTarget, double inputPointX, double inputPointY, ref double transformedPointX, ref double transformedPointY)
        {
            bool RetVal = false;

            //_logger.Debug("Start TransformPoint2d");
            try
            {
                //Creating coordinate system factory
                MgCoordinateSystemFactory CSFactory = new MgCoordinateSystemFactory();
                //Creating coordinate system objects
                MgCoordinateSystem SourceCS = CSFactory.Create(wkTextSource);
                MgCoordinateSystem TargetCS = CSFactory.Create(wkTextTarget);
                //Creating geometry factory
                MgGeometryFactory GeomFactory = new MgGeometryFactory();
                //Populating geometry factory CreateCoordinateXY
                MgCoordinate SourceCoord = GeomFactory.CreateCoordinateXY(inputPointX, inputPointY);
                //Getting transformation definition
                MgCoordinateSystemTransform CSTransform = CSFactory.GetTransform(SourceCS, TargetCS);
                //Transforming coordinate
                MgCoordinate TargetCoord = CSTransform.Transform(SourceCoord);
                //Populating return coordinate objects
                transformedPointX = TargetCoord.X;
                transformedPointY = TargetCoord.Y;
                RetVal            = true;
            }
            catch (System.Exception ex)
            {
                //_logger.Error("Error in TransformPoint2d", ex);
                throw;
            }
            //_logger.Debug("End TransformPoint2d");
            return(RetVal);
        }
 public void Dispose()
 {
     if (_trans != null)
     {
         _trans.Dispose();
         _trans = null;
     }
 }
        internal LocalNativeSimpleTransform(string sourceWkt, string targetWkt)
        {
            var fact = new MgCoordinateSystemFactory();
            var source = fact.Create(sourceWkt);
            var target = fact.Create(targetWkt);

            _trans = fact.GetTransform(source, target);
        }
Beispiel #4
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         _trans?.Dispose();
         _trans = null;
     }
 }
Beispiel #5
0
        internal LocalNativeSimpleTransform(string sourceWkt, string targetWkt)
        {
            var fact   = new MgCoordinateSystemFactory();
            var source = fact.Create(sourceWkt);
            var target = fact.Create(targetWkt);

            _trans = fact.GetTransform(source, target);
        }
Beispiel #6
0
    string pointTransformAndWriteZ(string geom, MgMap map)
    {
        double[] x = new double[1];
        double[] y = new double[1];
        double[] z = new double[1];

        MgWktReaderWriter wktrwdmr = new MgWktReaderWriter();
        MgPoint           cntr     = wktrwdmr.Read(geom).Centroid;

        x[0] = cntr.Coordinate.X;
        y[0] = cntr.Coordinate.Y;
        z[0] = 0;

        StringBuilder output = new StringBuilder();

        output.Append("<table width=\"100%\" class=\"results\">");

        //WGS preko MG API
        MgCoordinateSystemFactory fact = new MgCoordinateSystemFactory();
        string wktFrom = map.GetMapSRS();

        string wktTo = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]";

        MgCoordinateSystem          CSSource       = fact.Create(wktFrom);
        MgCoordinateSystem          CSTarget       = fact.Create(wktTo);
        MgCoordinateSystemTransform coordTransform = fact.GetTransform(CSSource, CSTarget);

        MgGeometryFactory geomFact = new MgGeometryFactory();

        // GK
        //samo prvo višino zaenkrat, dokler ni enačbe za Z
        output.Append(String.Format("<tr><td class='header'><b>Map koordinates:</b></td><td class=\"results\"><table><tr><td><b>Y:</b></td><td>{0}</td></tr><tr><td><b>X:</b></td><td>{1}</td></tr></table></td></tr>", string.Format("{0:0.0}", x[0]), string.Format("{0:0.0}", y[0])));

        int i = 0;

        //transformacija preko MG koordinatnega sistema
        foreach (double pointX in x)
        {
            MgCoordinate coord = geomFact.CreateCoordinateXY(x[i], y[i]);
            coord = coordTransform.Transform(coord);

            x[i] = coord.X;
            y[i] = coord.Y;

            i++;
        }

        double[] xwgs = x;
        double[] ywgs = y;
        output.Append(String.Format("<tr><td class='header'><b>WGS84:</b></td><td class=\"results\"><table><tr><td><b>Lon:</b></td><td>{0}</td></tr><tr><td><b>Lat:</b></td><td>{1}</td></tr></table></td></tr>", string.Format("{0:0.000000}", xwgs[0]), string.Format("{0:0.000000}", ywgs[0])));

        output.Append("</table>");

        return(output.ToString());
    }
Beispiel #7
0
    public static string TransformGK2Wgs(double x, double y, string ss, string mpN) //Transform from Map to WGS 84 Coordtnate System
    {
        MgMap             map          = new MgMap();
        MgResourceService resourceSrvc = GetMgResurceService(ss);

        map.Open(resourceSrvc, mpN);

        //Create coordinate system factory
        MgCoordinateSystemFactory fact = new MgCoordinateSystemFactory();
        string wktFrom = map.GetMapSRS();
        string wktTo   = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]";

        MgCoordinateSystem coordinateSystemSource = fact.Create(wktFrom);
        MgCoordinateSystem coordinateSystemTarget = fact.Create(wktTo);

        MgGeometryFactory geomFact = new MgGeometryFactory();

        MgCoordinateSystemTransform coordTransform = fact.GetTransform(coordinateSystemSource, coordinateSystemTarget);

        MgCoordinate coord = coordTransform.Transform(x, y);

        return(coord.X.ToString().Replace(',', '.') + ";" + coord.Y.ToString().Replace(',', '.'));
    }