Example #1
0
        public void method2()
        {
            int           epsgNumber = 4326;
            string        crsCode    = "EPSG:" + epsgNumber;
            CrsIdentifier crsIdentifier; // namespace Programmerare.CrsTransformations.Identifier

            crsIdentifier = CrsIdentifierFactory.CreateFromEpsgNumber(epsgNumber);
            // Alternative:
            crsIdentifier = CrsIdentifierFactory.CreateFromCrsCode(crsCode);

            double latitude  = 59.330231;
            double longitude = 18.059196;

            CrsCoordinate crsCoordinate; // namespace Programmerare.CrsTransformations.Coordinate

            // All the below methods are alternatives for creating the same coordinate
            // with the above latitude/longitude and coordinate reference system.
            // No class or object is used for the methods below because of the following static import:
            // using static Programmerare.CrsTransformations.Coordinate.CrsCoordinateFactory;
            crsCoordinate = LatLon(latitude, longitude, epsgNumber);
            crsCoordinate = LatLon(latitude, longitude, crsCode);
            crsCoordinate = LatLon(latitude, longitude, crsIdentifier);

            crsCoordinate = LonLat(longitude, latitude, epsgNumber);
            crsCoordinate = LonLat(longitude, latitude, crsCode);
            crsCoordinate = LonLat(longitude, latitude, crsIdentifier);

            crsCoordinate = YX(latitude, longitude, epsgNumber);
            crsCoordinate = YX(latitude, longitude, crsCode);
            crsCoordinate = YX(latitude, longitude, crsIdentifier);

            crsCoordinate = XY(longitude, latitude, epsgNumber);
            crsCoordinate = XY(longitude, latitude, crsCode);
            crsCoordinate = XY(longitude, latitude, crsIdentifier);

            crsCoordinate = NorthingEasting(latitude, longitude, epsgNumber);
            crsCoordinate = NorthingEasting(latitude, longitude, crsCode);
            crsCoordinate = NorthingEasting(latitude, longitude, crsIdentifier);

            crsCoordinate = EastingNorthing(longitude, latitude, epsgNumber);
            crsCoordinate = EastingNorthing(longitude, latitude, crsCode);
            crsCoordinate = EastingNorthing(longitude, latitude, crsIdentifier);

            crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude(latitude, longitude, epsgNumber);
            crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude(latitude, longitude, crsCode);
            crsCoordinate = CreateFromYNorthingLatitudeAndXEastingLongitude(latitude, longitude, crsIdentifier);

            crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude(longitude, latitude, epsgNumber);
            crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude(longitude, latitude, crsCode);
            crsCoordinate = CreateFromXEastingLongitudeAndYNorthingLatitude(longitude, latitude, crsIdentifier);

            CrsIdentifier           targetCrs = CrsIdentifierFactory.CreateFromEpsgNumber(3006);
            CrsTransformationResult crsTransformationResult = crsTransformationAdapter.Transform(crsCoordinate, targetCrs);
            // see more example code further down in this webpage
        }
        public void TransformToCoordinate_WhenInputCoordinateIsNull()
        {
            CrsIdentifier crsWgs84 = coordinateWgs84.CrsIdentifier;

            Assert.IsNotNull(crsWgs84);
            CrsCoordinate nullCordinate = null;
            // TransformToCoordinate SHOULD (unlike the transform method)
            // throw exception
            ArgumentNullException exception = Assert.Throws <ArgumentNullException>(() => {
                crsTransformationAdapter.TransformToCoordinate(nullCordinate, crsWgs84);
            });
        }
Example #3
0
 public void CrsIdentifier_ShouldReturnEpsgNumberAndEpsgPrefixedCrsCodeAndBeConsideredAsEpsg_WhenCreatedFromEpsgNumber() {
     int inputEpsgNumber = 3006;
     // No validation that the number is actually an existing EPSG but any positive integer
     // is assumed to be a EPSG number
     CrsIdentifier crsIdentifier = CrsIdentifierFactory.CreateFromEpsgNumber(inputEpsgNumber);
     Assert.AreEqual(
         inputEpsgNumber, // expected
         crsIdentifier.EpsgNumber
     );
     Assert.AreEqual(GetCrsCodeIncludingUppercasedEpsgPrefix(inputEpsgNumber), crsIdentifier.CrsCode);
     Assert.AreEqual(true, crsIdentifier.IsEpsgCode);
 }
Example #4
0
 public void CrsIdentifier_ShouldReturnEpsgNumberAndUppercasedEpsgPrefixedWhitespaceTrimmedCrsCodeAndBeConsideredAsEpsg_WhenCreatedFromLowecasedEpsgCodeWithSurroundingWhitespace() {
     int inputEpsgNumber = 4326;
     string inputCrsCode = "  epsg:" + inputEpsgNumber + "  "; 
     CrsIdentifier crsIdentifier = CrsIdentifierFactory.CreateFromCrsCode(inputCrsCode);
     // the input should become trimmed and return string with uppercased "EPSG:" prefix
     Assert.AreEqual(
         GetCrsCodeIncludingUppercasedEpsgPrefix(inputEpsgNumber), 
         crsIdentifier.CrsCode
     );
     Assert.AreEqual(true, crsIdentifier.IsEpsgCode);
     Assert.AreEqual(inputEpsgNumber, crsIdentifier.EpsgNumber);
 }
        public void TestAxisOrder()
        {
            if (!File.Exists(EpsgAccessDatabase))
            {
                throw new IgnoreException("Epsg Access Database not found");
            }

            var unusual = new HashSet <int>();

            using (var cn = new System.Data.OleDb.OleDbConnection(
                       //$"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={EpsgAccessDatabase};"
                       $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={EpsgAccessDatabase};"))
            {
                cn.Open();
                var cmd = cn.CreateCommand();
                cmd.CommandText = Sql;
                using (var dr = cmd.ExecuteReader())
                {
                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            var code = dr.GetInt32(0);
                            if (code > 32767)
                            {
                                continue;
                            }
                            unusual.Add(code);
                        }
                    }
                }
            }
            var crsAxisOrderRegistry = new CrsAxisOrderRegistry();

            /*
             * foreach (var code in unusual)
             * {
             *  CrsIdentifier crs;
             *  if (CrsIdentifier.TryParse("urn:ogc:def:crs:EPSG::" + code, out crs))
             *      Assert.AreEqual(1, crsAOR[crs][0]);
             * }*/

            for (var code = 1; code < 32768; code++)
            {
                CrsIdentifier crs;
                if (CrsIdentifier.TryParse("urn:ogc:def:crs:EPSG::" + code, out crs))
                {
                    var expected = unusual.Contains(code) ? 1 : 0;
                    Assert.AreEqual(expected, crsAxisOrderRegistry[crs][0]);
                }
            }
        }
 public void TransformToCoordinate_ShouldThrowException_WhenCrsIdentifierIsNull() {
     CrsIdentifier crsIdentifierNull = null;
     foreach (ICrsTransformationAdapter crsTransformationAdapter in crsTransformationAdapterImplementations) {
         Assert.That(
             () => crsTransformationAdapter.TransformToCoordinate(
                 this.validInputCoordinate,  
                 crsIdentifierNull
             ),
             Throws.Exception 
                 .TypeOf<ArgumentNullException>()
         );
     }
 }
        public void TransformResult_WhenInputCoordinateIsNull()
        {
            CrsIdentifier crsWgs84 = coordinateWgs84.CrsIdentifier;

            Assert.IsNotNull(crsWgs84);
            CrsCoordinate           nullCordinate = null;
            CrsTransformationResult result        = crsTransformationAdapter.Transform(nullCordinate, crsWgs84);

            AssertTransformationResultFailure(
                result,
                nullCordinate,
                crsTransformationAdapter
                );
        }
Example #8
0
 public void CreateFromXEastingLongitudeAndYNorthingLatitude_ShouldThrowException_WhenCrsIdentifierIsNull() {
     CrsIdentifier crsIdentifier = null;
     ArgumentException exception = Assert.Throws<ArgumentNullException>( () => {
         CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(
             60.0,
             20.0,
             crsIdentifier
         );
     });
     // F# may throw this: nullArg "crsIdentifier"
     // which creates the following kind of message:
     // "Value cannot be null. Parameter name: crsIdentifier"
     AssertExceptionMessageForIllegalArgumentException(exception, "crsIdentifier");
 }
Example #9
0
        public void ResultCoordinates_MustBeDefinedWithTheSameCoordinateReferenceSystem()
        {
            var resultCoordinates = base.allCoordinateResultsForTheDifferentImplementations;
            List <IGrouping <CrsIdentifier, CrsCoordinate> > res = resultCoordinates.GroupBy(c => c.CrsIdentifier).ToList();
            string messageIfFailing = "all coordinates should have the same CRS, since thet should all be the result of a transform to the same CRS";

            Assert.AreEqual(1, res.Count, messageIfFailing);
            CrsIdentifier crsIdentifier = res[0].Key;

            Assert.AreEqual(
                resultCoordinates[0].CrsIdentifier,
                crsIdentifier
                );
        }
 public void TransformResult_ShouldContainArgumentNullException_WhenCrsIdentifierIsNull() {
     CrsIdentifier crsIdentifierNull = null;
     foreach (ICrsTransformationAdapter crsTransformationAdapter in crsTransformationAdapterImplementations) {
         var transformationResult = crsTransformationAdapter.Transform(
             this.validInputCoordinate,
             crsIdentifierNull
         );
         Assert.IsNotNull(transformationResult);
         Assert.IsNotNull(transformationResult.Exception);
         Assert.AreEqual(
             transformationResult.Exception.GetType(), 
             typeof(ArgumentNullException),
             "Failing adapter: " + crsTransformationAdapter.GetType().FullName
         );
     }
 }
        public void TestEpsgCodeUom()
        {
            if (!File.Exists(EpsgAccessDatabase))
            {
                throw new IgnoreException("Epsg Access Database not found");
            }

            var connectionString = $"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={EpsgAccessDatabase};";

            using (var connection = new System.Data.OleDb.OleDbConnection(connectionString))
            {
                connection.Open();
                var cmd = connection.CreateCommand();
                cmd.CommandText = SqlEpsgToUom;
                var uomr = new CrsUnitOfMeasureRegistry();
                using (var dr = cmd.ExecuteReader())
                {
                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            if ((int)dr[0] > 32768)
                            {
                                break;
                            }

                            CrsIdentifier crs;
                            if (CrsIdentifier.TryParse(string.Format("urn:ogc:def:crs:EPSG::{0}", dr.GetInt32(0)), out crs))
                            {
                                var uom = new UnitOfMeasure();
                                Assert.DoesNotThrow(() => uom = uomr[crs], "Getting unit of measure failed for {0}", crs);

                                var uomCode = dr.GetInt32(1);
                                if (uomCode == 9001 || uomCode == 1024)
                                {
                                    Assert.AreEqual(1d, uom.ToMeter, "Unit of measure ToMeter is not 1d: {0}", crs);
                                }
                                else
                                {
                                    Assert.AreNotEqual(1d, uom.ToMeter, "Unit of measure ToMeter should not be 1d: {0}", crs);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #12
0
            public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
            {
                var ts = (WmtsTileSchema)obj;

                ts.Name = info.GetString("name");
                ts.Srs  = info.GetString("srs");
                var extentRef = (ExtentSurrogate.ExtentRef)info.GetValue("extent", typeof(ExtentSurrogate.ExtentRef));

                ts.Extent = (Extent)((IObjectReference)extentRef).GetRealObject(context);
                ts.Format = info.GetString("format");

                var type  = (Type)info.GetValue("resolutionsType", typeof(Type));
                var list  = (IDictionary <string, Resolution>)Activator.CreateInstance(type);
                var count = info.GetInt32("resolutionsCount");

                for (var i = 0; i < count; i++)
                {
                    var key      = info.GetString(string.Format("rk{0}", i));
                    var valueRef = (IObjectReference)
                                   info.GetValue(string.Format("rv{0}", i), typeof(ResolutionSurrogate.ResolutionRef));
                    var value = (Resolution)valueRef.GetRealObject(context);
                    list.Add(key, value);
                }
                Utility.SetPropertyValue(ref obj, "Resolutions", BindingFlags.Public | BindingFlags.Instance, list);

                ts.YAxis = (YAxis)info.GetInt32("axis");

                //Utility.SetPropertyValue(ref obj, "Identifier", BindingFlags.Instance | BindingFlags.Public, info.GetString("identifier"));
                Utility.SetPropertyValue(ref obj, "Layer", BindingFlags.Instance | BindingFlags.Public, info.GetString("layer"));
                Utility.SetPropertyValue(ref obj, "Title", BindingFlags.Instance | BindingFlags.Public, info.GetString("title"));
                Utility.SetPropertyValue(ref obj, "Abstract", BindingFlags.Instance | BindingFlags.Public, info.GetString("abstract"));
                Utility.SetPropertyValue(ref obj, "Style", BindingFlags.Instance | BindingFlags.Public, info.GetString("style"));
                Utility.SetPropertyValue(ref obj, "TileMatrixSet", BindingFlags.Instance | BindingFlags.Public, info.GetString("tileMatrixSet"));

                CrsIdentifier tmp;

                if (CrsIdentifier.TryParse(info.GetString("supportedSRS"), out tmp))
                {
                    Utility.SetPropertyValue(ref obj, "SupportedSRS", BindingFlags.Instance | BindingFlags.Public, tmp);
                }

                return(ts);
            }
Example #13
0
 public void CrsIdentifier_ShouldReturnWhitespaceTrimmedCrsCodeAndNotBeConsideredAsEpsg_WhenCreatedFromNonEpsgString() {
     CrsIdentifier crsIdentifier = CrsIdentifierFactory.CreateFromCrsCode("  abc  ");
     Assert.AreEqual("abc", crsIdentifier.CrsCode);
     Assert.AreEqual(false, crsIdentifier.IsEpsgCode);
 }
Example #14
0
 public void CrsIdentifiers_ShouldBeEqual_WhenCreatedFromEpsgNumberAndCorrespondingCrsCode() {
     CrsIdentifier fromEpsgNumber = CrsIdentifierFactory.CreateFromEpsgNumber(3006);
     CrsIdentifier fromCrsCode = CrsIdentifierFactory.CreateFromCrsCode("  epsg:3006   ");
     Assert.AreEqual(fromEpsgNumber, fromCrsCode);
     Assert.AreEqual(fromEpsgNumber.GetHashCode(), fromCrsCode.GetHashCode());
 }
        public void SetUp()
        {
            weightFactory = CrsTransformationAdapterWeightFactory.Create();

            crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();
            double[] outputLatitudes =
            {
                59.1,
                59.2,
                59.3,
                59.4,
                59.6,
            };
            expectedMedianLatitude  = 59.3;
            expectedAverageLatitude = 59.32;

            double[] outputLongitudes =
            {
                18.2,
                18.3,
                18.4,
                18.8,
                18.9
            };
            expectedMedianLongitude  = 18.4;
            expectedAverageLongitude = 18.52;

            outputCoordinateWgs84ForImplementation_1 = CrsCoordinateFactory.CreateFromLatitudeLongitude(outputLatitudes[0], outputLongitudes[3]);
            outputCoordinateWgs84ForImplementation_2 = CrsCoordinateFactory.CreateFromLatitudeLongitude(outputLatitudes[2], outputLongitudes[1]);
            outputCoordinateWgs84ForImplementation_3 = CrsCoordinateFactory.CreateFromLatitudeLongitude(outputLatitudes[4], outputLongitudes[4]);
            outputCoordinateWgs84ForImplementation_4 = CrsCoordinateFactory.CreateFromLatitudeLongitude(outputLatitudes[1], outputLongitudes[0]);
            outputCoordinateWgs84ForImplementation_5 = CrsCoordinateFactory.CreateFromLatitudeLongitude(outputLatitudes[3], outputLongitudes[2]);
            outputCoordinates = new List <CrsCoordinate> {
                outputCoordinateWgs84ForImplementation_1,
                outputCoordinateWgs84ForImplementation_2,
                outputCoordinateWgs84ForImplementation_3,
                outputCoordinateWgs84ForImplementation_4,
                outputCoordinateWgs84ForImplementation_5
            };

            mock1 = new Mock <ICrsTransformationAdapter>();
            mock2 = new Mock <ICrsTransformationAdapter>();
            mock3 = new Mock <ICrsTransformationAdapter>();
            mock4 = new Mock <ICrsTransformationAdapter>();
            mock5 = new Mock <ICrsTransformationAdapter>();

            leafAdapterImplementation_1 = mock1.Object;
            leafAdapterImplementation_2 = mock2.Object;
            leafAdapterImplementation_3 = mock3.Object;
            leafAdapterImplementation_4 = mock4.Object;
            leafAdapterImplementation_5 = mock5.Object;

            inputCoordinateSweref99 = CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(6580822.0, 674032.0, EpsgNumber.SWEDEN__SWEREF99_TM__3006);

            CrsTransformationResult leafResult1 = CrsTransformationResult._CreateCrsTransformationResult(
                inputCoordinateSweref99,
                outputCoordinateWgs84ForImplementation_1,
                null,
                true,
                leafAdapterImplementation_1,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List <CrsTransformationResult>())
                );
            CrsTransformationResult leafResult2 = CrsTransformationResult._CreateCrsTransformationResult(
                inputCoordinateSweref99,
                outputCoordinateWgs84ForImplementation_2,
                null,
                true,
                leafAdapterImplementation_2,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List <CrsTransformationResult>())
                );
            CrsTransformationResult leafResult3 = CrsTransformationResult._CreateCrsTransformationResult(
                inputCoordinateSweref99,
                outputCoordinateWgs84ForImplementation_3,
                null,
                true,
                leafAdapterImplementation_3,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List <CrsTransformationResult>())
                );
            CrsTransformationResult leafResult4 = CrsTransformationResult._CreateCrsTransformationResult(
                inputCoordinateSweref99,
                outputCoordinateWgs84ForImplementation_4,
                null,
                true,
                leafAdapterImplementation_4,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List <CrsTransformationResult>())
                );
            CrsTransformationResult leafResult5 = CrsTransformationResult._CreateCrsTransformationResult(
                inputCoordinateSweref99,
                outputCoordinateWgs84ForImplementation_5,
                null,
                true,
                leafAdapterImplementation_5,
                CrsTransformationResultStatistic._CreateCrsTransformationResultStatistic(new List <CrsTransformationResult>())
                );

            crsIdentifierWGS84 = CrsIdentifierFactory.CreateFromEpsgNumber(EpsgNumber.WORLD__WGS_84__4326);

            mock1.Setup(leaf => leaf.Transform(inputCoordinateSweref99, crsIdentifierWGS84)).Returns(leafResult1);
            mock2.Setup(leaf => leaf.Transform(inputCoordinateSweref99, crsIdentifierWGS84)).Returns(leafResult2);
            mock3.Setup(leaf => leaf.Transform(inputCoordinateSweref99, crsIdentifierWGS84)).Returns(leafResult3);
            mock4.Setup(leaf => leaf.Transform(inputCoordinateSweref99, crsIdentifierWGS84)).Returns(leafResult4);
            mock5.Setup(leaf => leaf.Transform(inputCoordinateSweref99, crsIdentifierWGS84)).Returns(leafResult5);

            //mock1.Setup(leaf => leaf.LongNameOfImplementation).Returns("1");
            //mock2.Setup(leaf => leaf.LongNameOfImplementation).Returns("2");
            //mock3.Setup(leaf => leaf.LongNameOfImplementation).Returns("3");
            //mock4.Setup(leaf => leaf.LongNameOfImplementation).Returns("4");
            //mock5.Setup(leaf => leaf.LongNameOfImplementation).Returns("5");
            mock1.Setup(leaf => leaf.AdapteeType).Returns(CrsTransformationAdapteeType.LEAF_DOT_SPATIAL_2_0_0_RC1);
            mock2.Setup(leaf => leaf.AdapteeType).Returns(CrsTransformationAdapteeType.LEAF_PROJ_NET_2_0_0);
            mock3.Setup(leaf => leaf.AdapteeType).Returns(CrsTransformationAdapteeType.LEAF_MIGHTY_LITTLE_GEODESY_1_0_2);
            // The type must be different but there are only three concrete types as above to use
            // but then instead can use the ones below (and the purpose of this enum is to use it as key in a dictionary/hashtable)
            mock4.Setup(leaf => leaf.AdapteeType).Returns(CrsTransformationAdapteeType.UNSPECIFIED_LEAF);
            mock5.Setup(leaf => leaf.AdapteeType).Returns(CrsTransformationAdapteeType.UNSPECIFIED);

            allLeafAdapters = new List <ICrsTransformationAdapter> {
                leafAdapterImplementation_1,
                leafAdapterImplementation_2,
                leafAdapterImplementation_3,
                leafAdapterImplementation_4,
                leafAdapterImplementation_5
            };
        }
Example #16
0
 /// <summary>
 /// Creates an instance for this class
 /// </summary>
 /// <param name="name"></param>
 /// <param name="crs"></param>
 /// <param name="items"></param>
 public ScaleSet(string name, CrsIdentifier crs, IEnumerable<ScaleSetItem> items)
 {
     Name = name;
     Crs = crs;
     _items = items.ToArray();
 }
        /// <summary>
        /// Gets the axis order for *all* EPSG defined coordinate reference systems with an srid less than 32768
        /// </summary>
        /// <param name="identifier">The identifier</param>
        /// <returns>The axis order</returns>
        public int[] this[CrsIdentifier identifier]
        {
            get
            {
                switch (identifier.Authority)
                {
                    //case "OGC":
                    default:
                        return Usual;

                    case "EPSG":
                        var code = Int32.Parse(identifier.Identifier);
                        if (code == 900913) code = 3857;
                        if (code < 0)
                            throw new ArgumentException("Invalid Epsg identifier");

                        var byteIndex = code / 8;
                        var bitIndex = code % 8;
                        var flag = 1 << bitIndex;//1 << (7 - bitIndex);
                        return (EpsgAxisOrderBitField[byteIndex] & flag) == flag ? Unusual : Usual;

                }
            }
        }
 private double GetDeltaValueForComparisons(
     CrsIdentifier crsIdentifier
 ) {
     return GetDeltaValueForComparisons(crsIdentifier.EpsgNumber);
 }
Example #19
0
    public void Coordinates_ShouldBeEqual_WhenCreatedWithTheSameValuesButDifferentFactoryMethods() {
        CrsIdentifier crsIdentifier = CrsIdentifierFactory.CreateFromEpsgNumber(epsgNumberSweref99);
        string epsgCode = EpsgPrefix + epsgNumberSweref99;
        
        CrsCoordinate expectedCoordinate = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(xLongitude, yLatitude, epsgNumberSweref99);
        // all should be equal to each other, so one of them was chosen above 
        // as the "expected" and then the others are compared with it in the below assertions

        // -----------------------------------------------------------------------
        // the last parameter (epsgNumber) is an integer in the first below assertions:
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.LonLat(xLongitude, yLatitude, epsgNumberSweref99)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.XY(xLongitude, yLatitude, epsgNumberSweref99)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.EastingNorthing(xLongitude, yLatitude, epsgNumberSweref99)
        );

        // the below four assertions are using x/y values in the opposite order 
        // compared to the above three assertions
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(yLatitude, xLongitude, epsgNumberSweref99)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.LatLon(yLatitude, xLongitude, epsgNumberSweref99)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.YX(yLatitude, xLongitude, epsgNumberSweref99)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.NorthingEasting(yLatitude, xLongitude, epsgNumberSweref99)
        );

        // -----------------------------------------------------------------------
        // epsg code (string parameter) is the last parameter below
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(xLongitude, yLatitude, epsgCode)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.LonLat(xLongitude, yLatitude, epsgCode)   
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.XY(xLongitude, yLatitude, epsgCode)   
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.EastingNorthing(xLongitude, yLatitude, epsgCode)  
        );

        // the below four assertions are using x/y values in the opposite order 
        // compared to the above four assertions

        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(yLatitude, xLongitude, epsgCode)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.LatLon(yLatitude, xLongitude, epsgCode)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.YX(yLatitude, xLongitude, epsgCode)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.NorthingEasting(yLatitude, xLongitude, epsgCode)
        );        

        // -----------------------------------------------------------------------
        // crsIdentifier obkect is the last parameter below
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(xLongitude, yLatitude, crsIdentifier)   
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.LonLat(xLongitude, yLatitude, crsIdentifier)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.XY(xLongitude, yLatitude, crsIdentifier)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.EastingNorthing(xLongitude, yLatitude, crsIdentifier)
        );

        // the below four assertions are using x/y values in the opposite order 
        // compared to the above four assertions

        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(yLatitude, xLongitude, crsIdentifier)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.LatLon(yLatitude, xLongitude, crsIdentifier)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.YX(yLatitude, xLongitude, crsIdentifier)
        );
        AssertEqualCoordinates(expectedCoordinate,
            CrsCoordinateFactory.NorthingEasting(yLatitude, xLongitude, crsIdentifier)
        );        
    }
Example #20
0
 public void Coordinates_ShouldBeEqual_WhenUsingCrsIdentifierAndDifferentFactoryMethodsWithParametersInDifferentOrder() {
     CrsIdentifier crsIdentifier = CrsIdentifierFactory.CreateFromEpsgNumber(3006);
     CrsCoordinate coordinate1 = CrsCoordinateFactory.CreateFromXEastingLongitudeAndYNorthingLatitude(xLongitude, yLatitude, crsIdentifier);
     CrsCoordinate coordinate2 = CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(yLatitude, xLongitude, crsIdentifier);
     AssertEqualCoordinates(coordinate1, coordinate2);
 }
Example #21
0
        public void FindPotentialBuggyImplementationsHelper(
            int minEpsgCrsCode,
            int maxEpsgCrsCode,
            double?optionalDelta = null
            )
        {
            int    numberIfEpsgCodesToConsiderInIteration = maxEpsgCrsCode - minEpsgCrsCode;
            bool   manyWillBeIterated = numberIfEpsgCodesToConsiderInIteration > 100;
            double deltaDiffToUse     = manyWillBeIterated ? deltaDiff : double.MinValue;

            if (optionalDelta.HasValue)
            {
                deltaDiffToUse = optionalDelta.Value;
            }

            var crsTransformationAdapterCompositeFactory = CrsTransformationAdapterCompositeFactory.Create();
            CrsTransformationAdapterComposite crsTransformationComposite = crsTransformationAdapterCompositeFactory.CreateCrsTransformationMedian();

            verifyThreeImplementations(crsTransformationComposite); // to make sure that the above factory really creates an object which will use three implementations

            IList <CrsTransformationResult> transformResultsWithLargeDifferences = new List <CrsTransformationResult>();

            CrsIdentifier wgs84 = CrsIdentifierFactory.CreateFromEpsgNumber(EpsgNumber.WORLD__WGS_84__4326);

            var stopWatch = new Stopwatch();

            stopWatch.Start();
            IList <EpsgCrsAndAreaCodeWithCoordinates> coordinatesFromGeneratedCsvFile = CoordinateTestDataGeneratedFromEpsgDatabaseTest.GetCoordinatesFromGeneratedCsvFile();
            int seconds = (int)stopWatch.Elapsed.TotalSeconds;

            WriteLine("Time for reading the content of the input file: " + seconds);
            stopWatch.Restart();
            int totalNumberOfSeconds;

            WriteLine("number of rows to iterate: " + coordinatesFromGeneratedCsvFile.Count);
            for (int i = 0; i < coordinatesFromGeneratedCsvFile.Count; i++)
            {
                if (manyWillBeIterated && (i % 100 == 0))
                {
                    //WriteLine("number of rows iterated so far: " + i);
                    totalNumberOfSeconds = (int)stopWatch.Elapsed.TotalSeconds;
                    //WriteLine("Number of seconds so far: " + totalNumberOfSeconds);
                    // if (i > 50) break;
                }
                EpsgCrsAndAreaCodeWithCoordinates epsgCrsAndAreaCodeWithCoordinates = coordinatesFromGeneratedCsvFile[i];
                if (
                    epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode < minEpsgCrsCode
                    ||
                    epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode > maxEpsgCrsCode
                    )
                {
                    continue;
                }
                if (!manyWillBeIterated)
                {
                    //Console.WriteLine("iterated epsgCrsCode: " + epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode);
                }


                CrsCoordinate coordinateInputWgs84 = CrsCoordinateFactory.CreateFromYNorthingLatitudeAndXEastingLongitude(epsgCrsAndAreaCodeWithCoordinates.centroidY, epsgCrsAndAreaCodeWithCoordinates.centroidX, wgs84);

                CrsTransformationResult resultOutputFromWgs4 = crsTransformationComposite.Transform(coordinateInputWgs84, epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode);
                if (!resultOutputFromWgs4.IsSuccess)
                {
                    continue;
                }

                CrsTransformationResult resultWhenTransformedBackToWgs84 = crsTransformationComposite.Transform(resultOutputFromWgs4.OutputCoordinate, wgs84);
                if (!resultWhenTransformedBackToWgs84.IsSuccess)
                {
                    continue;
                }

                CrsTransformationResultStatistic crsTransformationResultStatistic = resultWhenTransformedBackToWgs84.CrsTransformationResultStatistic;
                Assert.IsNotNull(crsTransformationResultStatistic);
                Assert.IsTrue(crsTransformationResultStatistic.IsStatisticsAvailable);
                if (
                    crsTransformationResultStatistic.MaxDifferenceForXEastingLongitude > deltaDiffToUse
                    ||
                    crsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude > deltaDiffToUse
                    )
                {
                    transformResultsWithLargeDifferences.Add(resultWhenTransformedBackToWgs84);
                }
                else
                {
                    if (!manyWillBeIterated)
                    {
                        //Console.WriteLine("NOT 'big' difference for EPSG " + epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode);
                        int count = crsTransformationComposite.TransformationAdapterChildren.Count;
                        //Console.WriteLine("Number of implementations not having big difference: " + count);
                    }
                }
            }
            WriteLine("Number of iterated rows/coordinates: " + coordinatesFromGeneratedCsvFile.Count);

            WriteLine("Number of results with 'large' differences: " + transformResultsWithLargeDifferences.Count);
            for (int i = 0; i < transformResultsWithLargeDifferences.Count; i++)
            {
                CrsTransformationResult transformResult = transformResultsWithLargeDifferences[i];
                WriteLine("----------------------------------------");
                WriteLine("epsg " + transformResult.InputCoordinate.CrsIdentifier.CrsCode);
                WriteLine("MaxDiffYLatitude : " + transformResult.CrsTransformationResultStatistic.MaxDifferenceForYNorthingLatitude);
                WriteLine("MaxDiffYLongitude: " + transformResult.CrsTransformationResultStatistic.MaxDifferenceForXEastingLongitude);
                IList <CrsTransformationResult> subResults = transformResult.TransformationResultChildren;
                for (int j = 0; j < subResults.Count; j++)
                {
                    CrsTransformationResult subTransformResult = subResults[j];
                    if (subTransformResult.IsSuccess)
                    {
                        WriteLine(subTransformResult.OutputCoordinate + " , " + subTransformResult.CrsTransformationAdapterResultSource.AdapteeType);
                    }
                }
            }
        }