Ejemplo n.º 1
0
 public CoordinateSystemServices(ICoordinateSystemFactory coordinateSystemFactory,
                                 ICoordinateTransformationFactory coordinateTransformationFactory,
                                 IEnumerable <KeyValuePair <int, string> > enumeration)
     : this(coordinateSystemFactory, coordinateTransformationFactory)
 {
     FromEnumeration(this, enumeration);
 }
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory,
                                                                ICoordinateSystemFactory csFactory,
                                                                FeatureDataTable schemaTable)
        {
            header("Construct SpatiaLite2 target provider\n" +
                   "* Author Felix Obermaier 2009\n" +
                   "* Ingenieurgruppe IVV GmbH & Co. KG\n" +
                   "* http://www.ivv-aachen.de");

            string connectionString = GetValue("Please enter the connection string for the target database file.\nRemember 'Connection Timeout=0' for large datasets.", Properties.Settings.Default.TargetConnectionString);

            string tableName = GetValue("Please enter the table name.", "");

            SpatiaLite2ShapeType shapeType = GetShapeType();

            SpatiaLite2IndexType spatialIndex = GetSpatialIndex();

            SpatiaLite2Provider.CreateDataTable(schemaTable, tableName,
                                                connectionString, SpatiaLite2Provider.DefaultGeometryColumnName,
                                                shapeType, spatialIndex);

            _targetProvider = new SpatiaLite2Provider(geometryFactory, connectionString, tableName);

            _targetProvider.Open();
            return(_targetProvider);
        }
Ejemplo n.º 3
0
        public void NoPrjFileThenSetCoordinateSystemGivesSpatialRefToGeometries()
        {
            //Layer name: BCROADSWithoutDbf
            //Geometry: Line String
            //Feature Count: 7291
            //Extent: (7332083.212797, 236823.718672) - (7538428.618000, 405610.346926)
            ShapeFileProvider shapeFile = new ShapeFileProvider(
                BcRoadsWithOutDbfShapeFile,
                _geoFactory);

            shapeFile.Open();
            ICoordinateSystemFactory <BufferedCoordinate2D> coordSysFactory
                = _coordSysFactory;
            String wkt = File.ReadAllText(BcRoadsPrjFile);
            IProjectedCoordinateSystem cs = WktReader <BufferedCoordinate2D>
                                            .ToCoordinateSystemInfo(wkt, coordSysFactory) as IProjectedCoordinateSystem;

            shapeFile.SpatialReference = cs;
            Assert.IsNotNull(shapeFile.SpatialReference);

            IGeometry g = shapeFile.GetGeometryByOid(0);

            Assert.IsTrue(g.SpatialReference.EqualParams(createExpectedCoordinateSystem()));

            shapeFile.Close();
        }
 /// <summary>
 /// Creates an instance of this class using the provided <paramref name="coordinateSystemFactory"/>,
 /// <paramref name="coordinateTransformationFactory"/> and enumeration of
 /// </summary>
 /// <param name="coordinateSystemFactory">The factory to use for creating a coordinate system.</param>
 /// <param name="coordinateTransformationFactory">The factory to use for creating a coordinate transformation.</param>
 /// <param name="enumerable">An enumeration if spatial reference ids and coordinate system definition strings pairs</param>
 public CoordinateSystemServices(
     ICoordinateSystemFactory coordinateSystemFactory,
     ICoordinateTransformationFactory coordinateTransformationFactory,
     IEnumerable <KeyValuePair <int, string> > enumerable)
     : this(coordinateSystemFactory, coordinateTransformationFactory)
 {
     PrivAddCoordinateSystems(enumerable);
 }
        //public Func<string, long, string> GetDefinition { get; set; }

        /*
         * public static string GetFromSpatialReferenceOrg(string authority, long code)
         * {
         *  var url = string.Format("http://spatialreference.org/ref/{0}/{1}/ogcwkt/",
         *      authority.ToLowerInvariant(),
         *      code);
         *  var req = (HttpWebRequest) WebRequest.Create(url);
         *  using (var resp = req.GetResponse())
         *  {
         *      using (var resps = resp.GetResponseStream())
         *      {
         *          if (resps != null)
         *          {
         *              using (var sr = new StreamReader(resps))
         *                  return sr.ReadToEnd();
         *          }
         *      }
         *  }
         *  return null;
         * }
         */

        public CoordinateSystemServices(ICoordinateSystemFactory coordinateSystemFactory,
                                        ICoordinateTransformationFactory coordinateTransformationFactory,
                                        IEnumerable <KeyValuePair <int, string> > enumeration)
            : this(coordinateSystemFactory, coordinateTransformationFactory)
        {
            var enumObj = (object)enumeration ?? DefaultInitialization();

            _initialization = new ManualResetEvent(false);
            ThreadPool.QueueUserWorkItem(FromEnumeration, new[] { this, enumObj });
        }
Ejemplo n.º 6
0
        public void FixtureSetup()
        {
            Directory.CreateDirectory("UnitTestData");

            ICoordinateSequenceFactory<BufferedCoordinate2D> sequenceFactory = new BufferedCoordinate2DSequenceFactory();
            _geoFactory = new GeometryFactory<BufferedCoordinate2D>(sequenceFactory);

            _coordSysFactory = new CoordinateSystemFactory<BufferedCoordinate2D>(
                sequenceFactory.CoordinateFactory, _geoFactory);
        }
Ejemplo n.º 7
0
        public void FixtureSetup()
        {
            Directory.CreateDirectory("UnitTestData");

            ICoordinateSequenceFactory <BufferedCoordinate2D> sequenceFactory = new BufferedCoordinate2DSequenceFactory();

            _geoFactory = new GeometryFactory <BufferedCoordinate2D>(sequenceFactory);

            _coordSysFactory = new CoordinateSystemFactory <BufferedCoordinate2D>(
                sequenceFactory.CoordinateFactory, _geoFactory);
        }
Ejemplo n.º 8
0
 private static ICoordinateSystem CreateCoordinateSystem(ICoordinateSystemFactory coordinateSystemFactory, string wkt)
 {
     try
     {
         return(coordinateSystemFactory.CreateFromWkt(wkt.Replace("ELLIPSOID", "SPHEROID")));
     }
     catch (Exception)
     {
         // as a fallback we ignore projections not supported
         return(null);
     }
 }
Ejemplo n.º 9
0
 private static IEnumerable <KeyValuePair <int, ICoordinateSystem> > CreateCoordinateSystems(
     ICoordinateSystemFactory factory,
     IEnumerable <KeyValuePair <int, string> > enumeration)
 {
     foreach (var sridWkt in enumeration)
     {
         var cs = CreateCoordinateSystem(factory, sridWkt.Value);
         if (cs != null)
         {
             yield return(new KeyValuePair <int, ICoordinateSystem>(sridWkt.Key, cs));
         }
     }
 }
Ejemplo n.º 10
0
        private static IEnumerable <ICoordinateSystem> GetList(ICoordinateSystemFactory fact)
        {
            List <ICoordinateSystem> lst = new List <ICoordinateSystem>();

            foreach (Proj4Reader.Proj4SpatialRefSys sys in Proj4Reader.GetSRIDs())
            {
                string wkt = sys.SrText;


                ICoordinateSystem cs = fact.CreateFromWkt(wkt);
                lst.Add(cs);
            }
            return(lst);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a CoordinateSystemServices built with all the values coming from the SpatialRefSys.xml
        /// </summary>
        /// <param name="coordinateSystemFactory"></param>
        /// <param name="coordinateTransformationFactory"></param>
        /// <returns></returns>
        public static CoordinateSystemServices FromSpatialRefSys(ICoordinateSystemFactory coordinateSystemFactory, ICoordinateTransformationFactory coordinateTransformationFactory)
        {
            if (coordinateSystemFactory == null)
            {
                throw new ArgumentNullException("coordinateSystemFactory");
            }

            if (coordinateTransformationFactory == null)
            {
                throw new ArgumentNullException("coordinateTransformationFactory");
            }

            return(new CoordinateSystemServices(coordinateSystemFactory, coordinateTransformationFactory, SpatialReference.GetAllReferenceSystems()));
        }
Ejemplo n.º 12
0
        //public Func<string, long, string> GetDefinition { get; set; }

        /*
         * public static string GetFromSpatialReferenceOrg(string authority, long code)
         * {
         *  var url = string.Format("http://spatialreference.org/ref/{0}/{1}/ogcwkt/",
         *      authority.ToLowerInvariant(),
         *      code);
         *  var req = (HttpWebRequest) WebRequest.Create(url);
         *  using (var resp = req.GetResponse())
         *  {
         *      using (var resps = resp.GetResponseStream())
         *      {
         *          if (resps != null)
         *          {
         *              using (var sr = new StreamReader(resps))
         *                  return sr.ReadToEnd();
         *          }
         *      }
         *  }
         *  return null;
         * }
         */

        public CoordinateSystemServices(ICoordinateSystemFactory coordinateSystemFactory,
                                        ICoordinateTransformationFactory coordinateTransformationFactory,
                                        IEnumerable <KeyValuePair <int, string> > enumeration)
            : this(coordinateSystemFactory, coordinateTransformationFactory)
        {
            var enumObj = (object)enumeration ?? DefaultInitialization();

            _initialization = new ManualResetEvent(false);
#if HAS_SYSTEM_THREADING_TASKS_TASK_RUN
            System.Threading.Tasks.Task.Run(() => FromEnumeration((new[] { this, enumObj })));
#elif HAS_SYSTEM_THREADING_THREADPOOL
            System.Threading.ThreadPool.QueueUserWorkItem(FromEnumeration, new[] { this, enumObj });
#else
#error Must have one or the other
#endif
        }
Ejemplo n.º 13
0
            internal InternalFactoryService()
            {
                _coordinateFactory         = new CoordinateFactory();
                _coordinateSequenceFactory =
                    new CoordinateSequenceFactory((CoordinateFactory)_coordinateFactory);
                _geometryFactory =
                    new GeometryFactory <Coordinate>(
                        (CoordinateSequenceFactory)_coordinateSequenceFactory);
                _coordinateSystemFactory =
                    new CoordinateSystemFactory <Coordinate>((CoordinateFactory)_coordinateFactory,
                                                             (GeometryFactory <Coordinate>)
                                                             _geometryFactory);

                _coordinateTransformationFactory = new CoordinateTransformationFactory <Coordinate>(
                    (CoordinateFactory)_coordinateFactory,
                    (GeometryFactory <Coordinate>)_geometryFactory, new LinearFactory <DoubleComponent>());
            }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates an instance of this class using the provided <paramref name="coordinateSystemFactory"/>,
        /// <paramref name="coordinateTransformationFactory"/> and enumeration of
        /// </summary>
        /// <param name="coordinateSystemFactory">The factory to use for creating a coordinate system.</param>
        /// <param name="coordinateTransformationFactory">The factory to use for creating a coordinate transformation.</param>
        public CoordinateSystemServices(ICoordinateSystemFactory coordinateSystemFactory,
                                        ICoordinateTransformationFactory coordinateTransformationFactory)
        {
            if (coordinateSystemFactory == null)
            {
                throw new ArgumentNullException("coordinateSystemFactory");
            }

            if (coordinateTransformationFactory == null)
            {
                throw new ArgumentNullException("coordinateTransformationFactory");
            }

            _coordinateSystemFactory = coordinateSystemFactory;
            _ctFactory = coordinateTransformationFactory;

            _csBySrid = new Dictionary <int, ICoordinateSystem>();
            _sridByCs = new Dictionary <IInfo, int>(new CsEqualityComparer());
        }
Ejemplo n.º 15
0
        public CoordinateSystemServices(ICoordinateSystemFactory coordinateSystemFactory,
                                        ICoordinateTransformationFactory coordinateTransformationFactory)
        {
            if (coordinateSystemFactory == null)
            {
                throw new ArgumentNullException("coordinateSystemFactory");
            }
            _coordinateSystemFactory = coordinateSystemFactory;

            if (coordinateTransformationFactory == null)
            {
                throw new ArgumentNullException("coordinateTransformationFactory");
            }
            _ctFactory = coordinateTransformationFactory;

            _csBySrid = new Dictionary <int, ICoordinateSystem>();
            _sridByCs = new Dictionary <IInfo, int>(new CsEqualityComparer());

            FromEnumeration(new object[] { this, DefaultInitialization() });
        }
Ejemplo n.º 16
0
        public SridMapStrategy(int priority, ICoordinateSystemFactory csFactory, IEnumerable <ICoordinateSystem> systems)
            : base(priority, csFactory)
        {
            //_coordinateSystems = systems;
            foreach (ICoordinateSystem cs in systems)
            {
                IKey key;
                long code;
                if (long.TryParse(cs.AuthorityCode, out code))
                {
                    key = new LongKey {
                        Authority = cs.Authority, Code = code
                    };
                }
                else
                {
                    key = new StringKey {
                        Authority = cs.Authority, Code = cs.AuthorityCode
                    };
                }
                if (!_map.ContainsKey(key))
                {
                    _map.Add(key, cs);
                }
                else if (!cs.EqualParams(_map[key]))
                {
                    throw new ApplicationException();
                }

                int csKey = HashCoordSystem(cs);
                if (!_hashMap.ContainsKey(csKey))
                {
                    _hashMap.Add(csKey, key);
                }
                else if (!cs.EqualParams(_map[_hashMap[csKey]]))
                {
                    throw new ApplicationException();
                }
            }
        }
Ejemplo n.º 17
0
 static CoordinateSystemBase()
 {
     _csFact = new CoordinateSystemFactory();
 }
Ejemplo n.º 18
0
            internal InternalFactoryService()
            {
                _coordinateFactory = new CoordinateFactory();
                _coordinateSequenceFactory =
                    new CoordinateSequenceFactory((CoordinateFactory)_coordinateFactory);
                _geometryFactory =
                    new GeometryFactory<Coordinate>(
                        (CoordinateSequenceFactory)_coordinateSequenceFactory);
                _coordinateSystemFactory =
                    new CoordinateSystemFactory<Coordinate>((CoordinateFactory)_coordinateFactory,
                                                                    (GeometryFactory<Coordinate>)
                                                                    _geometryFactory);

                _coordinateTransformationFactory = new CoordinateTransformationFactory<Coordinate>(
                      (CoordinateFactory)_coordinateFactory,
                      (GeometryFactory<Coordinate>)_geometryFactory, new LinearFactory<DoubleComponent>());

            }
        /// <remarks>
        /// Note <paramref name="oidType"/> Is ignored for shapefile provider.
        /// </remarks>
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory, ICoordinateSystemFactory csFactory, FeatureDataTable schemaTable)
        {
            EnsureColumnNamesValid(schemaTable);

            string directoryPath = GetDirectoryPath();

            CreateAction overwrite;
            string layerName = GetLayerName(directoryPath, out overwrite);

            ShapeType shapeType = GetShapeType();


            if (overwrite == CreateAction.Append)

                _targetProvider = new ShapeFileProvider(Path.Combine(directoryPath, layerName + ".shp"),
                                                        geometryFactory,
                                                        csFactory);
            else
                _targetProvider = ShapeFileProvider.Create(directoryPath, layerName, shapeType, schemaTable,
                                                           geometryFactory,
                                                           csFactory);

            _targetProvider.Open(WriteAccess.Exclusive);
            return _targetProvider;
        }
Ejemplo n.º 20
0
 static CoordinateSystemBase()
 {
     _csFact = new CoordinateSystemFactory();
 }
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory,
                                                                ICoordinateSystemFactory csFactory,
                                                                FeatureDataTable schemaTable)
        {

            header( "Construct SpatiaLite2 target provider\n" +
                  "* Author Felix Obermaier 2009\n" +
                  "* Ingenieurgruppe IVV GmbH & Co. KG\n" + 
                  "* http://www.ivv-aachen.de" );

            string connectionString = GetValue("Please enter the connection string for the target database file.\nRemember 'Connection Timeout=0' for large datasets.",Properties.Settings.Default.TargetConnectionString);

            string tableName = GetValue("Please enter the table name.","");

            SpatiaLite2ShapeType shapeType = GetShapeType();

            SpatiaLite2IndexType spatialIndex = GetSpatialIndex();

            SpatiaLite2Provider.CreateDataTable(schemaTable, tableName, 
                connectionString, SpatiaLite2Provider.DefaultGeometryColumnName,
                shapeType, spatialIndex);

            _targetProvider = new SpatiaLite2Provider(geometryFactory, connectionString, tableName );

            _targetProvider.Open();
            return _targetProvider;
        }
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory,
                                                                ICoordinateSystemFactory csFactory,
                                                                FeatureDataTable schemaTable)
        {
            if (oidType == typeof(UInt16))
            {
                oidType = typeof(Int16);
            }
            else if (oidType == typeof(UInt32))
            {
                oidType = typeof(Int32);
            }
            else if (oidType == typeof(UInt64))
            {
                oidType = typeof(Int64);
            }

            _targetProviderOidType = oidType;

            Type typ = typeof(PostGisProvider <>);

            _specializedType = typ.MakeGenericType(oidType);

            header("Construct PostGis target provider\n" +
                   "* Author Felix Obermaier 2009\n" +
                   "* Ingenieurgruppe IVV GmbH & Co. KG\n" +
                   "* http://www.ivv-aachen.de");

            string connectionString = GetValue(
                "Please enter the connection string for the source database file.",
                Settings.Default.SourceConnectionString);

            string schema = GetValue("Please enter the schema name",
                                     Settings.Default.SourceSchema);

            string tableName = GetValue("Please enter the table name.", null);

            //PostGisProviderStatic.CreateDataTable<oidType.GetType()>( schemaTable, schema, tableName, connectionString)
            Type       pgpstatic         = typeof(PostGisProviderStatic);
            MethodInfo miCreateDataTable = pgpstatic.GetMethod(
                "CreateDataTable",
                BindingFlags.Public | BindingFlags.Static,
                null,
                new[] { typeof(FeatureDataTable), typeof(string), typeof(string), typeof(string), typeof(string) },
                null);

            MethodInfo miCreateDataTableGeneric = miCreateDataTable.MakeGenericMethod(new[] { oidType });

            miCreateDataTableGeneric.Invoke(
                null,
                new object[]
                { schemaTable, schema, tableName, connectionString, PostGisProviderStatic.DefaultGeometryColumnName });

            _targetProvider =
                (IWritableFeatureProvider)
                Activator.CreateInstance(_specializedType,
                                         schemaTable.GeometryFactory,
                                         connectionString, schema, tableName,
                                         schemaTable.Columns[0].ColumnName,
                                         PostGisProviderStatic.DefaultGeometryColumnName,
                                         new GeometryServices().CoordinateTransformationFactory);

            _targetProvider.Open();
            return(_targetProvider);
        }
        public void TestDatumTransform()
        {
            ICoordinateSystemFactory cFac = new ICoordinateSystemFactory();
            
            //Define datums
            IHorizontalDatum wgs72 = HorizontalDatum.WGS72;
            IHorizontalDatum ed50 = HorizontalDatum.ED50;

            //Define geographic coordinate systems
            IGeographicCoordinateSystem gcsWGS72 =
                cFac.CreateGeographicCoordinateSystem("WGS72 Geographic", AngularUnit.Degrees, wgs72,
                                                      PrimeMeridian.Greenwich,
                                                      new AxisInfo("East", AxisOrientation.East),
                                                      new AxisInfo("North", AxisOrientation.North));

            IGeographicCoordinateSystem gcsWGS84 =
                cFac.CreateGeographicCoordinateSystem("WGS84 Geographic", AngularUnit.Degrees, HorizontalDatum.WGS84,
                                                      PrimeMeridian.Greenwich,
                                                      new AxisInfo("East", AxisOrientation.East),
                                                      new AxisInfo("North", AxisOrientation.North));

            IGeographicCoordinateSystem gcsED50 =
                cFac.CreateGeographicCoordinateSystem("ED50 Geographic", AngularUnit.Degrees, ed50,
                                                      PrimeMeridian.Greenwich,
                                                      new AxisInfo("East", AxisOrientation.East),
                                                      new AxisInfo("North", AxisOrientation.North));

            //Define geocentric coordinate systems
            IGeocentricCoordinateSystem gcenCsWGS72 =
                cFac.CreateGeocentricCoordinateSystem("WGS72 Geocentric", wgs72, LinearUnit.Metre,
                                                      PrimeMeridian.Greenwich);
            IGeocentricCoordinateSystem gcenCsWGS84 =
                cFac.CreateGeocentricCoordinateSystem("WGS84 Geocentric", HorizontalDatum.WGS84, LinearUnit.Metre,
                                                      PrimeMeridian.Greenwich);
            IGeocentricCoordinateSystem gcenCsED50 =
                cFac.CreateGeocentricCoordinateSystem("ED50 Geocentric", ed50, LinearUnit.Metre, PrimeMeridian.Greenwich);

            //Define projections
            //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5);
            Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>();
            parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
            parameters.Add(new ProjectionParameter("central_meridian", 9));
            parameters.Add(new ProjectionParameter("scale_factor", 0.9996));
            parameters.Add(new ProjectionParameter("false_easting", 500000));
            parameters.Add(new ProjectionParameter("false_northing", 0));
            IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters);
            IProjectedCoordinateSystem utmED50 =
                cFac.CreateProjectedCoordinateSystem("ED50 UTM Zone 32N", gcsED50, projection, LinearUnit.Metre,
                                                     new AxisInfo("East", AxisOrientation.East),
                                                     new AxisInfo("North", AxisOrientation.North));
            IProjectedCoordinateSystem utmWGS84 =
                cFac.CreateProjectedCoordinateSystem("WGS84 UTM Zone 32N", gcsWGS84, projection, LinearUnit.Metre,
                                                     new AxisInfo("East", AxisOrientation.East),
                                                     new AxisInfo("North", AxisOrientation.North));

            //Set TOWGS84 parameters
            wgs72.Wgs84Parameters = new Wgs84ConversionInfo(0, 0, 4.5, 0, 0, 0.554, 0.219);
            ed50.Wgs84Parameters = new Wgs84ConversionInfo(-81.0703, -89.3603, -115.7526,
                                                           -0.48488, -0.02436, -0.41321,
                                                           -0.540645); //Parameters for Denmark

            //Set up coordinate transformations
            ICoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
            ICoordinateTransformation ctForw = ctFac.CreateFromCoordinateSystems(gcsWGS72, gcenCsWGS72);
                //Geographic->Geocentric (WGS72)
            ICoordinateTransformation ctWGS84_Gcen2Geo = ctFac.CreateFromCoordinateSystems(gcenCsWGS84, gcsWGS84);
                //Geocentric->Geographic (WGS84)
            ICoordinateTransformation ctWGS84_Geo2UTM = ctFac.CreateFromCoordinateSystems(gcsWGS84, utmWGS84);
                //UTM ->Geographic (WGS84)
            ICoordinateTransformation ctED50_UTM2Geo = ctFac.CreateFromCoordinateSystems(utmED50, gcsED50);
                //UTM ->Geographic (ED50)
            ICoordinateTransformation ctED50_Geo2Gcen = ctFac.CreateFromCoordinateSystems(gcsED50, gcenCsED50);
                //Geographic->Geocentric (ED50)

            //Test datum-shift from WGS72 to WGS84
            //Point3D pGeoCenWGS72 = ctForw.MathTransform.Transform(pLongLatWGS72) as Point3D;
            IPoint3D pGeoCenWGS72 = new IPoint3D(3657660.66, 255768.55, 5201382.11);
            ICoordinateTransformation geocen_ed50_2_Wgs84 = ctFac.CreateFromCoordinateSystems(gcenCsWGS72, gcenCsWGS84);
            IPoint3D pGeoCenWGS84 = geocen_ed50_2_Wgs84.MathTransform.Transform(pGeoCenWGS72) as IPoint3D;
            //Point3D pGeoCenWGS84 = wgs72.Wgs84Parameters.Apply(pGeoCenWGS72);

            Assert.IsTrue(toleranceLessThan(new IPoint3D(3657660.78, 255778.43, 5201387.75), pGeoCenWGS84, 0.01));

            ICoordinateTransformation utm_ed50_2_Wgs84 = ctFac.CreateFromCoordinateSystems(utmED50, utmWGS84);
            IPoint pUTMED50 = new IPoint(600000, 6100000);
            IPoint pUTMWGS84 = utm_ed50_2_Wgs84.MathTransform.Transform(pUTMED50);
            Assert.IsTrue(toleranceLessThan(new IPoint(599928.6, 6099790.2), pUTMWGS84, 0.1));
            //Perform reverse
            ICoordinateTransformation utm_Wgs84_2_Ed50 = ctFac.CreateFromCoordinateSystems(utmWGS84, utmED50);
            pUTMED50 = utm_Wgs84_2_Ed50.MathTransform.Transform(pUTMWGS84);
            Assert.IsTrue(toleranceLessThan(new IPoint(600000, 6100000), pUTMED50, 0.1));
            //Assert.IsTrue(Math.Abs((pUTMWGS84 as Point3D).Z - 36.35) < 0.5);
            //Point pExpected = Point.FromDMS(2, 7, 46.38, 53, 48, 33.82);
            //ED50_to_WGS84_Denmark: datum.Wgs84Parameters = new Wgs84ConversionInfo(-89.5, -93.8, 127.6, 0, 0, 4.5, 1.2);
        }
 public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory,
                                                         ICoordinateSystemFactory csFactory,
                                                         FeatureDataTable schemaTable)
 {
     throw new NotImplementedException();
 }
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory,
                                                                ICoordinateSystemFactory csFactory,
                                                                FeatureDataTable schemaTable)
        {
            if (oidType == typeof (UInt16))
                oidType = typeof (Int16);
            else if (oidType == typeof (UInt32))
                oidType = typeof (Int32);
            else if (oidType == typeof (UInt64))
                oidType = typeof (Int64);

            _targetProviderOidType = oidType;

            Type typ = typeof (PostGisProvider<>);
            _specializedType = typ.MakeGenericType(oidType);

            header("Construct PostGis target provider\n" +
                   "* Author Felix Obermaier 2009\n" +
                   "* Ingenieurgruppe IVV GmbH & Co. KG\n" +
                   "* http://www.ivv-aachen.de");

            string connectionString = GetValue(
                "Please enter the connection string for the source database file.",
                Settings.Default.SourceConnectionString);

            string schema = GetValue("Please enter the schema name",
                                     Settings.Default.SourceSchema);

            string tableName = GetValue("Please enter the table name.", null);

            //PostGisProviderStatic.CreateDataTable<oidType.GetType()>( schemaTable, schema, tableName, connectionString)
            Type pgpstatic = typeof (PostGisProviderStatic);
            MethodInfo miCreateDataTable = pgpstatic.GetMethod(
                "CreateDataTable",
                BindingFlags.Public | BindingFlags.Static,
                null,
                new[] {typeof (FeatureDataTable), typeof (string), typeof (string), typeof (string), typeof (string)},
                null);

            MethodInfo miCreateDataTableGeneric = miCreateDataTable.MakeGenericMethod(new[] {oidType});

            miCreateDataTableGeneric.Invoke(
                null,
                new object[]
                    {schemaTable, schema, tableName, connectionString, PostGisProviderStatic.DefaultGeometryColumnName});

            _targetProvider =
                (IWritableFeatureProvider)
                Activator.CreateInstance(_specializedType,
                                         schemaTable.GeometryFactory,
                                         connectionString, schema, tableName,
                                         schemaTable.Columns[0].ColumnName,
                                         PostGisProviderStatic.DefaultGeometryColumnName,
                                         new GeometryServices().CoordinateTransformationFactory);

            _targetProvider.Open();
            return _targetProvider;
        }
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory,
                                                                ICoordinateSystemFactory csFactory,
                                                                FeatureDataTable schemaTable)
        {
            if (oidType == typeof (UInt16))
                oidType = typeof (Int16);
            else if (oidType == typeof (UInt32))
                oidType = typeof (Int32);
            else if (oidType == typeof (UInt64))
                oidType = typeof (Int64);

            Type typ = typeof (MsSqlServer2008Provider<>);
            _specializedType = typ.MakeGenericType(oidType);
            _targetProviderOidType = oidType;

            Console.WriteLine(
                "Please enter the connection string for the target database server. Press enter to use the one below.(Remember 'Connection Timeout=0' for large datasets.)");
            Console.WriteLine(Settings.Default.TargetConnectionString);


            string connectionString = Console.ReadLine();
            if (connectionString == "")
                connectionString = Settings.Default.TargetConnectionString;
            else
                Settings.Default.TargetConnectionString = connectionString;
            Settings.Default.Save();

            Console.WriteLine("Please enter the schema for the table.");
            string schemaName = Console.ReadLine();

            Console.WriteLine("Please enter the table name.");
            string tableName = Console.ReadLine();

            _targetProvider = (IWritableFeatureProvider) _specializedType.GetMethod(
                                                             "Create",
                                                             BindingFlags.Public | BindingFlags.Static,
                                                             null,
                                                             CallingConventions.Standard,
                                                             new[]
                                                                 {
                                                                     typeof (string), typeof (IGeometryFactory),
                                                                     typeof (string), typeof (string),
                                                                     typeof (FeatureDataTable)
                                                                 }, null)
                                                             .Invoke(null,
                                                                     new object[]
                                                                         {
                                                                             connectionString, geometryFactory,
                                                                             schemaName,
                                                                             tableName, schemaTable
                                                                         });

            _targetProvider.Open();
            return _targetProvider;
        }
        public void TestDatumTransform()
        {
            ICoordinateSystemFactory cFac = new ICoordinateSystemFactory();

            //Define datums
            IHorizontalDatum wgs72 = HorizontalDatum.WGS72;
            IHorizontalDatum ed50  = HorizontalDatum.ED50;

            //Define geographic coordinate systems
            IGeographicCoordinateSystem gcsWGS72 =
                cFac.CreateGeographicCoordinateSystem("WGS72 Geographic", AngularUnit.Degrees, wgs72,
                                                      PrimeMeridian.Greenwich,
                                                      new AxisInfo("East", AxisOrientation.East),
                                                      new AxisInfo("North", AxisOrientation.North));

            IGeographicCoordinateSystem gcsWGS84 =
                cFac.CreateGeographicCoordinateSystem("WGS84 Geographic", AngularUnit.Degrees, HorizontalDatum.WGS84,
                                                      PrimeMeridian.Greenwich,
                                                      new AxisInfo("East", AxisOrientation.East),
                                                      new AxisInfo("North", AxisOrientation.North));

            IGeographicCoordinateSystem gcsED50 =
                cFac.CreateGeographicCoordinateSystem("ED50 Geographic", AngularUnit.Degrees, ed50,
                                                      PrimeMeridian.Greenwich,
                                                      new AxisInfo("East", AxisOrientation.East),
                                                      new AxisInfo("North", AxisOrientation.North));

            //Define geocentric coordinate systems
            IGeocentricCoordinateSystem gcenCsWGS72 =
                cFac.CreateGeocentricCoordinateSystem("WGS72 Geocentric", wgs72, LinearUnit.Metre,
                                                      PrimeMeridian.Greenwich);
            IGeocentricCoordinateSystem gcenCsWGS84 =
                cFac.CreateGeocentricCoordinateSystem("WGS84 Geocentric", HorizontalDatum.WGS84, LinearUnit.Metre,
                                                      PrimeMeridian.Greenwich);
            IGeocentricCoordinateSystem gcenCsED50 =
                cFac.CreateGeocentricCoordinateSystem("ED50 Geocentric", ed50, LinearUnit.Metre, PrimeMeridian.Greenwich);

            //Define projections
            //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5);
            Collection <ProjectionParameter> parameters = new Collection <ProjectionParameter>();

            parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
            parameters.Add(new ProjectionParameter("central_meridian", 9));
            parameters.Add(new ProjectionParameter("scale_factor", 0.9996));
            parameters.Add(new ProjectionParameter("false_easting", 500000));
            parameters.Add(new ProjectionParameter("false_northing", 0));
            IProjection projection             = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters);
            IProjectedCoordinateSystem utmED50 =
                cFac.CreateProjectedCoordinateSystem("ED50 UTM Zone 32N", gcsED50, projection, LinearUnit.Metre,
                                                     new AxisInfo("East", AxisOrientation.East),
                                                     new AxisInfo("North", AxisOrientation.North));
            IProjectedCoordinateSystem utmWGS84 =
                cFac.CreateProjectedCoordinateSystem("WGS84 UTM Zone 32N", gcsWGS84, projection, LinearUnit.Metre,
                                                     new AxisInfo("East", AxisOrientation.East),
                                                     new AxisInfo("North", AxisOrientation.North));

            //Set TOWGS84 parameters
            wgs72.Wgs84Parameters = new Wgs84ConversionInfo(0, 0, 4.5, 0, 0, 0.554, 0.219);
            ed50.Wgs84Parameters  = new Wgs84ConversionInfo(-81.0703, -89.3603, -115.7526,
                                                            -0.48488, -0.02436, -0.41321,
                                                            -0.540645); //Parameters for Denmark

            //Set up coordinate transformations
            ICoordinateTransformationFactory ctFac  = new CoordinateTransformationFactory();
            ICoordinateTransformation        ctForw = ctFac.CreateFromCoordinateSystems(gcsWGS72, gcenCsWGS72);
            //Geographic->Geocentric (WGS72)
            ICoordinateTransformation ctWGS84_Gcen2Geo = ctFac.CreateFromCoordinateSystems(gcenCsWGS84, gcsWGS84);
            //Geocentric->Geographic (WGS84)
            ICoordinateTransformation ctWGS84_Geo2UTM = ctFac.CreateFromCoordinateSystems(gcsWGS84, utmWGS84);
            //UTM ->Geographic (WGS84)
            ICoordinateTransformation ctED50_UTM2Geo = ctFac.CreateFromCoordinateSystems(utmED50, gcsED50);
            //UTM ->Geographic (ED50)
            ICoordinateTransformation ctED50_Geo2Gcen = ctFac.CreateFromCoordinateSystems(gcsED50, gcenCsED50);
            //Geographic->Geocentric (ED50)

            //Test datum-shift from WGS72 to WGS84
            //Point3D pGeoCenWGS72 = ctForw.MathTransform.Transform(pLongLatWGS72) as Point3D;
            IPoint3D pGeoCenWGS72 = new IPoint3D(3657660.66, 255768.55, 5201382.11);
            ICoordinateTransformation geocen_ed50_2_Wgs84 = ctFac.CreateFromCoordinateSystems(gcenCsWGS72, gcenCsWGS84);
            IPoint3D pGeoCenWGS84 = geocen_ed50_2_Wgs84.MathTransform.Transform(pGeoCenWGS72) as IPoint3D;

            //Point3D pGeoCenWGS84 = wgs72.Wgs84Parameters.Apply(pGeoCenWGS72);

            Assert.IsTrue(toleranceLessThan(new IPoint3D(3657660.78, 255778.43, 5201387.75), pGeoCenWGS84, 0.01));

            ICoordinateTransformation utm_ed50_2_Wgs84 = ctFac.CreateFromCoordinateSystems(utmED50, utmWGS84);
            IPoint pUTMED50  = new IPoint(600000, 6100000);
            IPoint pUTMWGS84 = utm_ed50_2_Wgs84.MathTransform.Transform(pUTMED50);

            Assert.IsTrue(toleranceLessThan(new IPoint(599928.6, 6099790.2), pUTMWGS84, 0.1));
            //Perform reverse
            ICoordinateTransformation utm_Wgs84_2_Ed50 = ctFac.CreateFromCoordinateSystems(utmWGS84, utmED50);

            pUTMED50 = utm_Wgs84_2_Ed50.MathTransform.Transform(pUTMWGS84);
            Assert.IsTrue(toleranceLessThan(new IPoint(600000, 6100000), pUTMED50, 0.1));
            //Assert.IsTrue(Math.Abs((pUTMWGS84 as Point3D).Z - 36.35) < 0.5);
            //Point pExpected = Point.FromDMS(2, 7, 46.38, 53, 48, 33.82);
            //ED50_to_WGS84_Denmark: datum.Wgs84Parameters = new Wgs84ConversionInfo(-89.5, -93.8, 127.6, 0, 0, 4.5, 1.2);
        }
Ejemplo n.º 28
0
 protected SridMapStrategyBase(int priority, ICoordinateSystemFactory coordSysFactory)
 {
     Priority = priority;
     CoordinateSystemFactory = coordSysFactory;
 }
Ejemplo n.º 29
0
 public SridProj4Strategy(int priority, ICoordinateSystemFactory csFactory)
     : base(priority, csFactory, GetList(csFactory))
 {
 }
 public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory,
                                                         ICoordinateSystemFactory csFactory,
                                                         FeatureDataTable schemaTable)
 {
     throw new NotImplementedException();
 }
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory,
                                                                ICoordinateSystemFactory csFactory,
                                                                FeatureDataTable schemaTable)
        {
            if (oidType == typeof(UInt16))
            {
                oidType = typeof(Int16);
            }
            else if (oidType == typeof(UInt32))
            {
                oidType = typeof(Int32);
            }
            else if (oidType == typeof(UInt64))
            {
                oidType = typeof(Int64);
            }

            Type typ = typeof(MsSqlServer2008Provider <>);

            _specializedType       = typ.MakeGenericType(oidType);
            _targetProviderOidType = oidType;

            Console.WriteLine(
                "Please enter the connection string for the target database server. Press enter to use the one below.(Remember 'Connection Timeout=0' for large datasets.)");
            Console.WriteLine(Settings.Default.TargetConnectionString);


            string connectionString = Console.ReadLine();

            if (connectionString == "")
            {
                connectionString = Settings.Default.TargetConnectionString;
            }
            else
            {
                Settings.Default.TargetConnectionString = connectionString;
            }
            Settings.Default.Save();

            Console.WriteLine("Please enter the schema for the table.");
            string schemaName = Console.ReadLine();

            Console.WriteLine("Please enter the table name.");
            string tableName = Console.ReadLine();

            _targetProvider = (IWritableFeatureProvider)_specializedType.GetMethod(
                "Create",
                BindingFlags.Public | BindingFlags.Static,
                null,
                CallingConventions.Standard,
                new[]
            {
                typeof(string), typeof(IGeometryFactory),
                typeof(string), typeof(string),
                typeof(FeatureDataTable)
            }, null)
                              .Invoke(null,
                                      new object[]
            {
                connectionString, geometryFactory,
                schemaName,
                tableName, schemaTable
            });

            _targetProvider.Open();
            return(_targetProvider);
        }
Ejemplo n.º 32
0
        /// <remarks>
        /// Note <paramref name="oidType"/> Is ignored for shapefile provider.
        /// </remarks>
        public IWritableFeatureProvider ConstructTargetProvider(Type oidType, IGeometryFactory geometryFactory, ICoordinateSystemFactory csFactory, FeatureDataTable schemaTable)
        {
            EnsureColumnNamesValid(schemaTable);

            string directoryPath = GetDirectoryPath();

            CreateAction overwrite;
            string       layerName = GetLayerName(directoryPath, out overwrite);

            ShapeType shapeType = GetShapeType();


            if (overwrite == CreateAction.Append)
            {
                _targetProvider = new ShapeFileProvider(Path.Combine(directoryPath, layerName + ".shp"),
                                                        geometryFactory,
                                                        csFactory);
            }
            else
            {
                _targetProvider = ShapeFileProvider.Create(directoryPath, layerName, shapeType, schemaTable,
                                                           geometryFactory,
                                                           csFactory);
            }

            _targetProvider.Open(WriteAccess.Exclusive);
            return(_targetProvider);
        }