Ejemplo n.º 1
0
        public void WithGrid()
        {
            using (var pc = new ProjContext())
            {
                // Don't use old cache
                pc.SetGridCache(true, Path.Combine(TestContext.TestResultsDirectory, "proj.cache"), 300, 3600 * 24);
                pc.LogLevel = ProjLogLevel.Trace;

                using (var crsAmersfoort = CoordinateReferenceSystem.Create(@"EPSG:4289", pc)) // Amersfoort
                    using (var crsETRS89 = CoordinateReferenceSystem.Create(@"EPSG:4258", pc))
                    {
                        // Do it the dumb way
                        using (var t = CoordinateTransform.Create(crsAmersfoort, crsETRS89))
                        {
                            Assert.IsFalse(t is ChooseCoordinateTransform);
                            var r = t.Apply(51, 4, 0);

                            Assert.AreEqual(50.999, Math.Round(r[0], 3));
                            Assert.AreEqual(4.0, Math.Round(r[1], 3));
                        }

                        // Now, let's enable gridshifts
                        Assert.IsFalse(pc.AllowNetworkConnections);
                        pc.AllowNetworkConnections = true;
                        pc.EndpointUrl             = ProjContext.DefaultEndpointUrl;// "https://cdn.proj.org";
                        bool usedHttp = false;
                        pc.Log += (_, x) => { if (x.Contains("https://"))
                                              {
                                                  usedHttp = true;
                                              }
                        };

                        using (var t = CoordinateTransform.Create(crsAmersfoort, crsETRS89))
                        {
                            ChooseCoordinateTransform cl = t as ChooseCoordinateTransform;
                            Assert.IsNotNull(cl);
                            Assert.AreEqual(2, cl.Count);

                            Assert.IsTrue(cl[0].GridUsageCount > 0);
                            Assert.IsTrue(cl[1].GridUsageCount == 0);

                            Assert.AreEqual(new PPoint(50.999, 4.0), t.Apply(new PPoint(51, 4)).RoundXY(3));
                            var r = t.Apply(51, 4, 0);
                            Assert.IsTrue(usedHttp, "Now http");


                            var r0 = cl[0].Apply(51, 4, 0);
                            usedHttp = false;
                            var r1 = cl[1].Apply(51, 4, 0);
                            Assert.IsFalse(usedHttp, "No http");
                            Assert.IsNotNull(r0);
                            Assert.IsNotNull(r1);

                            Assert.AreEqual(50.999, Math.Round(r0[0], 3));
                            Assert.AreEqual(4.0, Math.Round(r0[1], 3));

                            Assert.AreEqual(50.999, Math.Round(r1[0], 3));
                            Assert.AreEqual(4.0, Math.Round(r1[1], 3));

                            Assert.IsNotNull(cl[0].MethodName);
                        }
                    }
            }
        }