Esempio n. 1
0
        /**
         * The FileInfo with coordinates are generated from another project "crsCodeGeneration" (a JVM project from which this .NET solution was ported).
         *  (the class 'CoordinateTestDataGenerator' which are creating the data from a relational database ("EPSG database")
         *  and from shapeFileInfo with polygon used for creating the coordinates as centroid points
         *  within a certain area where the EPSG code is defined to be used)
         *  Both the relational (SQL) database and the polygon was downloaded from EPSG website.
         */
        public static IList <EpsgCrsAndAreaCodeWithCoordinates> GetCoordinatesFromGeneratedCsvFile()
        {
            var list  = new List <EpsgCrsAndAreaCodeWithCoordinates>();
            var lines = GetAllLinesFromTextFileUTF8(new FileInfo(INPUT_TEST_DATA_FILE));

            foreach (string line in lines)
            {
                EpsgCrsAndAreaCodeWithCoordinates epsgCrsAndAreaCodeWithCoordinates = CreateEpsgCrsAndAreaCodeWithCoordinatesFromLineInCsvFile(line);
                list.Add(epsgCrsAndAreaCodeWithCoordinates);
            }
            return(list);
        }
Esempio n. 2
0
        public void FindTheNumberOfEpsgCodesPotentiallySupported()
        {
            IList <EpsgCrsAndAreaCodeWithCoordinates> coordinatesFromGeneratedCsvFile = CoordinateTestDataGeneratedFromEpsgDatabaseTest.GetCoordinatesFromGeneratedCsvFile();

            int totalNumberOfSeconds;

            foreach (ICrsTransformationAdapter leafAdapter in base.crsTransformationAdapterLeafImplementations)
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                int numberOfFailures  = 0;
                int numberOfSuccesses = 0;
                for (int i = 0; i < coordinatesFromGeneratedCsvFile.Count; i++)
                {
                    EpsgCrsAndAreaCodeWithCoordinates epsgCrsAndAreaCodeWithCoordinates = coordinatesFromGeneratedCsvFile[i];
                    CrsCoordinate coordinateInputWgs84 = CrsCoordinateFactory.LatLon(
                        epsgCrsAndAreaCodeWithCoordinates.centroidY,
                        epsgCrsAndAreaCodeWithCoordinates.centroidX
                        );
                    CrsTransformationResult resultOutputFromWgs4 = leafAdapter.Transform(
                        coordinateInputWgs84, epsgCrsAndAreaCodeWithCoordinates.epsgCrsCode
                        );
                    if (resultOutputFromWgs4.IsSuccess)
                    {
                        numberOfSuccesses++;
                        //WriteLine("Success " + DateTime.Now + " " + leafAdapter.AdapteeType + " " + resultOutputFromWgs4.OutputCoordinate);
                    }
                    else
                    {
                        //WriteLine("Failure " + DateTime.Now + " " + leafAdapter.AdapteeType);
                        numberOfFailures++;
                    }
                    if (i % 500 == 0)
                    {
                        //WriteLine("number of rows iterated so far: " + i + " (for leafAdapter " + leafAdapter.AdapteeType + " )");
                        totalNumberOfSeconds = (int)stopWatch.Elapsed.TotalSeconds;
                        //WriteLine("Number of seconds so far (for the above adapter) : " + totalNumberOfSeconds);
                        //if(i > 500) break;
                    }
                }
                totalNumberOfSeconds = (int)stopWatch.Elapsed.TotalSeconds;
                WriteLine("---------------------");
                WriteLine("Result for adapter: " + leafAdapter.AdapteeType);
                WriteLine("numberOfSuccesses: " + numberOfSuccesses);
                WriteLine("numberOfFailures: " + numberOfFailures);
                WriteLine("Number of seconds: " + totalNumberOfSeconds);
                WriteLine("---------------------");
            }
        }
Esempio n. 3
0
 public TestResultItem(
     EpsgCrsAndAreaCodeWithCoordinates item,
     CrsCoordinate inputCoordinateWGS84,
     CrsTransformationResult resultOfTransformationFromWGS84,
     CrsTransformationResult resultOfTransformationBackToWGS84
     )
 {
     wgs84sourceX = "" + item.centroidX;
     wgs84sourceY = "" + item.centroidY;
     epsgCrsCode  = "" + item.epsgCrsCode;
     if (resultOfTransformationFromWGS84 != null && resultOfTransformationFromWGS84.IsSuccess)
     {
         CrsCoordinate outputCoordinate = resultOfTransformationFromWGS84.OutputCoordinate;
         epsgTargetSourceX = "" + outputCoordinate.XEastingLongitude;
         epsgTargetSourceY = "" + outputCoordinate.YNorthingLatitude;
     }
     if (resultOfTransformationBackToWGS84 != null && resultOfTransformationBackToWGS84.IsSuccess)
     {
         CrsCoordinate outputCoordinate = resultOfTransformationBackToWGS84.OutputCoordinate;
         wgs84targetX = "" + outputCoordinate.XEastingLongitude;
         wgs84targetY = "" + outputCoordinate.YNorthingLatitude;
     }
 }
Esempio n. 4
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);
                    }
                }
            }
        }