public PostGisProvider(IGeometryFactory geometryFactory, string connectionString,
                               string tableSchema, string tableName, string oidColumn, string geometryColumn,
                               ICoordinateTransformationFactory coordinateTransformationFactory)
            : base(
                new PostGisDbUtility(), geometryFactory, connectionString, tableSchema,
                tableName,
                oidColumn,
                geometryColumn,
                coordinateTransformationFactory)
        {
            using (NpgsqlConnection cn = (NpgsqlConnection)DbUtility.CreateConnection(connectionString))
            {
                try
                {
                    cn.Open();

                    if (!PostGisProviderStatic.Has_X_Privilege(cn, "table", "\"public\".\"geometry_columns\"", "SELECT"))
                    {
                        throw new PostGisException(
                                  "Insufficient rights to access table \"public\".\"geometry_columns\"!");
                    }

                    if (
                        !PostGisProviderStatic.Has_X_Privilege(cn, "table",
                                                               string.Format("\"{0}\".\"{1}\"", tableSchema, tableName),
                                                               "SELECT"))
                    {
                        throw new PostGisException(string.Format(
                                                       "Insufficient rights to access table \"{0}\".\"{1}\"!",
                                                       tableSchema, tableName));
                    }

                    NpgsqlCommand cmd = (NpgsqlCommand)DbUtility.CreateCommand();
                    cmd.Connection  = cn;
                    cmd.CommandText =
                        @"SELECT x.""type""
    FROM ""public"".""geometry_columns"" AS x
    WHERE (x.""f_table_schema""=:p0 AND x.""f_table_name""=:p1 AND x.""f_geometry_column""=:p2);";
                    cmd.Parameters.Add(DbUtility.CreateParameter("p0", tableSchema, ParameterDirection.Input));
                    cmd.Parameters.Add(DbUtility.CreateParameter("p1", tableName, ParameterDirection.Input));
                    cmd.Parameters.Add(DbUtility.CreateParameter("p2", geometryColumn, ParameterDirection.Input));

                    NpgsqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    if (dr.HasRows)
                    {
                        dr.Read();
                        //valid geometry type
                        _validGeometryType = parseGeometryType(dr.GetString(0));
                    }
                    else
                    {
                        _validGeometryType = OgcGeometryType.Geometry;
                    }
                }
                catch (Exception)
                {
                    _validGeometryType = OgcGeometryType.Unknown;
                }
            }
        }
Exemple #2
0
 public CoordinateSystemServices(ICoordinateSystemFactory coordinateSystemFactory,
                                 ICoordinateTransformationFactory coordinateTransformationFactory,
                                 IEnumerable <KeyValuePair <int, string> > enumeration)
     : this(coordinateSystemFactory, coordinateTransformationFactory)
 {
     FromEnumeration(this, enumeration);
 }
 /// <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);
 }
Exemple #4
0
        protected SpatialDbProviderBase(IDbUtility dbUtility,
                                        IGeometryFactory geometryFactory,
                                        String connectionString,
                                        String tableSchema,
                                        String tableName,
                                        String oidColumn,
                                        String geometryColumn,
                                        ICoordinateTransformationFactory coordinateTransformationFactory)
        {
            DbUtility                = dbUtility;
            GeometryFactory          = geometryFactory.Clone();
            OriginalSpatialReference = GeometryFactory.SpatialReference;
            OriginalSrid             = GeometryFactory.Srid;

            if (geometryFactory.SpatialReference != null)
            {
                _geometryFactorySridInt = SridMap.DefaultInstance.Process(geometryFactory.SpatialReference, (int?)null);
            }

            if (!String.IsNullOrEmpty(connectionString))
            {
                ConnectionString = connectionString;
            }

            if (!String.IsNullOrEmpty(tableSchema))
            {
                TableSchema = tableSchema;
            }

            if (!String.IsNullOrEmpty(oidColumn))
            {
                OidColumn = oidColumn;
            }

            if (!String.IsNullOrEmpty(geometryColumn))
            {
                GeometryColumn = geometryColumn;
            }

            if (!String.IsNullOrEmpty(tableName))
            {
                Table = tableName;
            }

            CoordinateTransformationFactory = coordinateTransformationFactory;

            ICoordinateSystem cs;
            string            srid;

            ReadSpatialReference(out cs, out srid);

            OriginalSpatialReference         = cs;
            OriginalSrid                     = srid;
            GeometryFactory.SpatialReference = SpatialReference;
            GeometryFactory.Srid             = Srid;
        }
        //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 });
        }
        //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
        }
Exemple #7
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>());
            }
        /// <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());
        }
Exemple #9
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() });
        }
Exemple #10
0
        /// <summary>
        /// Creates a new instance of a Map with the given title.
        /// </summary>
        public Map(String title, IGeometryFactory geoFactory, ICoordinateTransformationFactory coordTransformFactory)
        {
            _geoFactory            = geoFactory;
            _coordTransformFactory = coordTransformFactory;
            _emptyPoint            = _geoFactory.CreatePoint();
            _layers              = new LayerCollection(this);
            _layers.ListChanged += handleLayersChanged;
            _featureDataSet      = new FeatureDataSet(title, geoFactory);

            // TODO: tool configuration should come from a config file and / or reflection
            IMapTool[] mapTools = new IMapTool[]
            {
                StandardMapView2DMapTools.Pan,
                StandardMapView2DMapTools.Query,
                StandardMapView2DMapTools.ZoomIn,
                StandardMapView2DMapTools.ZoomOut
            };

            // I18N_UNSAFE
            Tools = new MapToolSet("Standard Map View Tools", mapTools);
        }
        /// <summary>
        /// Creates a CoordinateSystemServices built with all the values coming from the SpatialRefSys.xml
        /// </summary>
        /// <param name="coordinateSystemFactory">A coordinate system factory</param>
        /// <param name="coordinateTransformationFactory">A coordinate transformation factory</param>
        /// <returns>A coordinate system services instance.</returns>
        /// <exception cref="ArgumentNullException">Thrown, if either <paramref name="coordinateSystemFactory"/> or <paramref name="coordinateTransformationFactory"/> is null.</exception>
        public static ICoordinateSystemServices FromSpatialRefSys(ICoordinateSystemFactory coordinateSystemFactory, ICoordinateTransformationFactory coordinateTransformationFactory)
        {
            if (coordinateSystemFactory == null)
            {
                throw new ArgumentNullException("coordinateSystemFactory");
            }

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

            var css = new CoordinateSystemServices(coordinateSystemFactory, coordinateTransformationFactory);

            css.AddCoordinateSystems(SpatialReference.GetAllReferenceSystems());

            return(css);
        }
Exemple #12
0
 public UtmCoordianesTransformer()
 {
     this.gcsWGS84 = GeographicCoordinateSystem.WGS84;
     this.coordinateTransformationFactory = new CoordinateTransformationFactory();
 }
Exemple #13
0
 /// <summary>
 /// Creates a new instance of a <see cref="Map"/> with a title describing
 /// when the map was created.
 /// </summary>
 public Map(IGeometryFactory geoFactory, ICoordinateTransformationFactory coordTransformFactory)
 // I18N_UNSAFE
     : this("Map created " + DateTime.Now.ToShortDateString(), geoFactory, coordTransformFactory)
 {
     _defaultName = _featureDataSet.DataSetName;
 }
            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>());

            }