Пример #1
0
        public void WellKnownTextConverterToIdentifiedObjectTest()
        {
            for (Int32 index = 0; index < this.identifiedObjects.Length; index++)
            {
                IdentifiedObject identifiedObject = WellKnownTextConverter.ToIdentifiedObject(this.identifiedObjectsText[index], TestUtilities.ReferenceProvider);
                Assert.AreEqual(this.identifiedObjects[index], identifiedObject);
            }

            Meridian meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM[\"Greenwich\",0.0]", TestUtilities.ReferenceProvider) as Meridian;

            Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]);

            meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM(\"Greenwich\",0.0)", TestUtilities.ReferenceProvider) as Meridian;
            Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]);

            meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM(Greenwich,0.0)", TestUtilities.ReferenceProvider) as Meridian;
            Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]);

            meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\", 8901]]", TestUtilities.ReferenceProvider) as Meridian;
            Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]);

            meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM [\"Greenwich\", 0.0, AUTHORITY [\"EPSG\", 8901]])", TestUtilities.ReferenceProvider) as Meridian;
            Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]);

            meridian = WellKnownTextConverter.ToIdentifiedObject("PRIMEM[Greenwich, 0.0, AUTHORITY[EPSG, 8901]]", TestUtilities.ReferenceProvider) as Meridian;
            Assert.AreEqual(meridian, TestUtilities.ReferenceProvider.Meridians["EPSG", 8901]);

            Assert.Throws <ArgumentNullException>(() => WellKnownTextConverter.ToIdentifiedObject(null, null));
            Assert.Throws <ArgumentException>(() => WellKnownTextConverter.ToIdentifiedObject(String.Empty, TestUtilities.ReferenceProvider));
            Assert.Throws <ArgumentException>(() => WellKnownTextConverter.ToIdentifiedObject("UNDEFINED[\"something\"]", TestUtilities.ReferenceProvider));
        }
Пример #2
0
        public void WellKnownTextConverterIdentifiedObjectTest()
        {
            // conversion from string instance

            String projectedUTMZone33 = "PROJCS[\"UTM Zone 33, Northern Hemisphere\",GEOGCS[\"Geographic Coordinate System\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137,298.257223560493]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",15],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]";
            String UTMZone10NAD83     = "PROJCS[\"NAD_1983_UTM_Zone_10N\", GEOGCS[\"GCS_North_American_1983\", DATUM[ \"D_North_American_1983\",ELLIPSOID[\"GRS_1980\",6378137,298.257222101]], PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]], PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",500000.0], PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",-123.0], PARAMETER[\"Scale_Factor\",0.9996],PARAMETER[\"Latitude_of_Origin\",0.0], UNIT[\"Meter\",1.0]]";
            String geodeticBase       = "GEOGCS[\"Unknown\",DATUM[\"D_Unknown\",SPHEROID[\"Clarke_1866\",6378206.4,294.978698213901]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]";
            String wgs1984            = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.017453292519943295]]";

            Assert.IsNotNull(WellKnownTextConverter.ToWellKnownText(WellKnownTextConverter.ToIdentifiedObject(projectedUTMZone33)));
            Assert.IsNotNull(WellKnownTextConverter.ToWellKnownText(WellKnownTextConverter.ToIdentifiedObject(UTMZone10NAD83)));
            Assert.IsNotNull(WellKnownTextConverter.ToWellKnownText(WellKnownTextConverter.ToIdentifiedObject(geodeticBase)));
            Assert.IsNotNull(WellKnownTextConverter.ToWellKnownText(WellKnownTextConverter.ToIdentifiedObject(wgs1984)));

            // conversion from identified object instance

            foreach (ProjectedCoordinateReferenceSystem projected in ProjectedCoordinateReferenceSystems.All)
            {
                String wkt = WellKnownTextConverter.ToWellKnownText(projected as IReferenceSystem);
                ProjectedCoordinateReferenceSystem converted = WellKnownTextConverter.ToIdentifiedObject(wkt) as ProjectedCoordinateReferenceSystem;
                Assert.AreEqual(projected, converted);
            }

            foreach (GeographicCoordinateReferenceSystem geodetic in Geographic2DCoordinateReferenceSystems.All)
            {
                String wkt = WellKnownTextConverter.ToWellKnownText(geodetic as IReferenceSystem);
                GeographicCoordinateReferenceSystem converted = WellKnownTextConverter.ToIdentifiedObject(wkt) as GeographicCoordinateReferenceSystem;
                Assert.AreEqual(geodetic, converted);
            }
        }
 /// <summary>
 /// Writes the reference system file.
 /// </summary>
 /// <param name="referenceSystem">The reference system.</param>
 protected override void WriteGeometryReferenceSystem(IReferenceSystem referenceSystem)
 {
     using (StreamWriter writer = new StreamWriter(_fileSystem.CreateFile(_basePath + _fileSystem.DirectorySeparator + _baseFileName + ".prj")))
     {
         String refSystem = WellKnownTextConverter.ToWellKnownText(referenceSystem);
         writer.Write(refSystem);
     }
 }
Пример #4
0
        public void WellKnownTextConverterGeometryTest()
        {
            foreach (IGeometry geometry in _geometries)
            {
                String    wkt       = WellKnownTextConverter.ToWellKnownText(geometry);
                IGeometry converted = WellKnownTextConverter.ToGeometry(wkt, _factory);

                Assert.AreEqual(0, new GeometryComparer().Compare(geometry, converted));
            }
        }
Пример #5
0
        public void WellKnownTextConverterToWellKnownTextTest()
        {
            for (Int32 index = 0; index < this.geometries.Length; index++)
            {
                String text = WellKnownTextConverter.ToWellKnownText(this.geometries[index]);
                Assert.AreEqual(this.geometriesText[index], text);
            }

            Assert.Throws <ArgumentNullException>(() => WellKnownTextConverter.ToWellKnownText(null));
            Assert.Throws <ArgumentException>(() => WellKnownTextConverter.ToWellKnownText(this.factory.CreatePoint(Coordinate.Empty), 1));
            Assert.Throws <ArgumentException>(() => WellKnownTextConverter.ToWellKnownText(this.factory.CreateGeometryCollection <IGeometry>()));
        }
Пример #6
0
        public void WellKnownTextConverterToWellKnownTextTest()
        {
            for (Int32 index = 0; index < this.identifiedObjects.Length - 1; index++)
            {
                String           text             = WellKnownTextConverter.ToWellKnownText(this.identifiedObjects[index]);
                IdentifiedObject identifiedObject = WellKnownTextConverter.ToIdentifiedObject(text, TestUtilities.ReferenceProvider);

                Assert.AreEqual(this.identifiedObjects[index], identifiedObject);
            }

            Assert.Throws <ArgumentNullException>(() => WellKnownTextConverter.ToWellKnownText((IdentifiedObject)null));
            Assert.Throws <ArgumentNullException>(() => WellKnownTextConverter.ToWellKnownText((IReferenceSystem)null));
        }
Пример #7
0
        /// <summary>
        /// Reads the reference system.
        /// </summary>
        private void ReadReferenceSystem()
        {
            // read the reference system from the WKT text
            using (StreamReader reader = new StreamReader(OpenPath(ReferenceSystemFilePath)))
            {
                StringBuilder builder = new StringBuilder();
                while (!reader.EndOfStream)
                {
                    builder.Append(reader.ReadLine().Trim());
                }

                _referenceSystem = WellKnownTextConverter.ToReferenceSystem(builder.ToString());
            }
        }
        /// <summary>
        /// Reads the reference system.
        /// </summary>
        private void ReadReferenceSystem()
        {
            // read the reference system from the WKT text
            using (StreamReader reader = new StreamReader(_fileSystem.OpenFile(_basePath + _fileSystem.DirectorySeparator + _baseFileName + ".prj", FileMode.Open)))
            {
                StringBuilder builder = new StringBuilder();
                while (!reader.EndOfStream)
                {
                    builder.Append(reader.ReadLine().Trim());
                }

                _referenceSystem = WellKnownTextConverter.ToReferenceSystem(builder.ToString());
            }
        }
Пример #9
0
        /// <summary>
        /// Writes the reference system.
        /// </summary>
        private void WriteReferenceSystem()
        {
            if (_referenceSystem == null)
            {
                return;
            }

            // writes the reference system as WKT text
            using (StreamWriter writer = new StreamWriter(OpenPath(ReferenceSystemFilePath)))
            {
                String text = WellKnownTextConverter.ToWellKnownText(_referenceSystem);
                writer.WriteLine(text);
            }
        }
Пример #10
0
        public void WellKnownTextConverterToGeometryTest()
        {
            for (Int32 index = 0; index < this.geometries.Length; index++)
            {
                IGeometry geometry = WellKnownTextConverter.ToGeometry(this.geometriesText[index], this.factory);
                Assert.AreEqual(0, this.geometryComparer.Compare(geometry, this.geometries[index]));
            }

            IPoint point = WellKnownTextConverter.ToGeometry("POINT(1 1)", this.factory) as IPoint;

            Assert.AreEqual(new Coordinate(1, 1), point.Coordinate);

            point = WellKnownTextConverter.ToGeometry("POINT (1 1)", this.factory) as IPoint;
            Assert.AreEqual(new Coordinate(1, 1), point.Coordinate);

            point = WellKnownTextConverter.ToGeometry("POINT (1 1 1)", this.factory) as IPoint;
            Assert.AreEqual(new Coordinate(1, 1), point.Coordinate);

            point = WellKnownTextConverter.ToGeometry("POINT Z (1 1 1)", this.factory) as IPoint;
            Assert.AreEqual(new Coordinate(1, 1, 1), point.Coordinate);

            point = WellKnownTextConverter.ToGeometry("POINT M (1 1 1)", this.factory) as IPoint;
            Assert.AreEqual(new Coordinate(1, 1), point.Coordinate);

            point = WellKnownTextConverter.ToGeometry("POINT ZM (1 1 1 1)", this.factory) as IPoint;
            Assert.AreEqual(new Coordinate(1, 1, 1), point.Coordinate);

            point = WellKnownTextConverter.ToGeometry("POINT ZM(1 1 1 1)", this.factory) as IPoint;
            Assert.AreEqual(new Coordinate(1, 1, 1), point.Coordinate);

            point = WellKnownTextConverter.ToGeometry("POINT EMPTY", this.factory) as IPoint;
            Assert.AreEqual(Coordinate.Empty, point.Coordinate);

            point = WellKnownTextConverter.ToGeometry("POINT (0 0)", this.factory) as IPoint;
            Assert.AreEqual(Coordinate.Empty, point.Coordinate);

            point = WellKnownTextConverter.ToGeometry("POINT Z (0 0 0)", this.factory) as IPoint;
            Assert.AreEqual(Coordinate.Empty, point.Coordinate);

            Assert.Throws <ArgumentNullException>(() => WellKnownTextConverter.ToGeometry(null, this.factory));
            Assert.Throws <ArgumentException>(() => WellKnownTextConverter.ToGeometry(String.Empty, this.factory));
            Assert.Throws <ArgumentException>(() => WellKnownTextConverter.ToGeometry("UNDEFINED (0 0 0)", this.factory));
        }