Exemplo n.º 1
0
 private static ILayer CreateVectorLayer(GpkgContent content, IProvider provider)
 {
     return(new VectorLayer(content.TableName, provider)
     {
         Style = VectorStyle.CreateRandomStyle()
     });
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates an instanc of this class
 /// </summary>
 /// <param name="content">The geopackage content</param>
 public GpkgProvider(GpkgContent content)
     :base(content.SRID)
 {
     _content = content;
     ConnectionID = content.ConnectionString;
     _reader = new GpkgStandardBinaryReader(GeoAPI.GeometryServiceProvider.Instance);
     _extent = content.Extent;
     _baseTable = content.GetBaseTable();
     _rtreeConstraint = BuildRtreeConstraint(content);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates an instanc of this class
 /// </summary>
 /// <param name="content">The geopackage content</param>
 public GpkgProvider(GpkgContent content)
     : base(content.SRID)
 {
     _content         = content;
     ConnectionID     = content.ConnectionString;
     _reader          = new GpkgStandardBinaryReader(GeoAPI.GeometryServiceProvider.Instance);
     _extent          = content.Extent;
     _baseTable       = content.GetBaseTable();
     _rtreeConstraint = BuildRtreeConstraint(content);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Method to get a feature layer for the given content
        /// </summary>
        /// <param name="content">The content</param>
        /// <param name="createLayer">A delegate function to create the layer</param>
        /// <returns>A layer</returns>
        public ILayer GetFeatureLayer(GpkgContent content, Func <GpkgContent, IProvider, ILayer> createLayer = null)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            createLayer = createLayer ?? CreateVectorLayer;
            return(createLayer(content, GetFeatureProvider(content)));
        }
Exemplo n.º 5
0
        public IProvider GetFeatureProvider(GpkgContent content)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            var p = new GpkgProvider(content);

            return(p);
        }
Exemplo n.º 6
0
        private static void TestProvider(IProvider provider, GpkgContent content)
        {
            int numFeatures = 0;
            Assert.DoesNotThrow(() => numFeatures = provider.GetFeatureCount(),
                    "GetFeatureCount threw exception:\n\tConnection{0}\n\t{1}",
                    provider.ConnectionID, content.TableName);

            var extent = provider.GetExtents();

            Collection<uint> oids = null;
            Assert.DoesNotThrow(() => oids = provider.GetObjectIDsInView(extent), 
                    "GetObjectIDsInView threw exception:\n\tConnection{0}\n\t{1}", 
                    provider.ConnectionID, content.TableName);
            Assert.AreEqual(numFeatures, oids.Count);

            foreach (var oid in oids)
            {
                IGeometry geom = null;
                Assert.DoesNotThrow(() => geom = provider.GetGeometryByID(oid), 
                    "GetGeometryByID threw exception:\n\tConnection{0}\n\t{1}", 
                    provider.ConnectionID, content.TableName);
                FeatureDataRow feat = null;
                Assert.DoesNotThrow(() => feat = provider.GetFeature(oid), 
                    "GetFeature threw exception:\n\tConnection{0}\n\t{1}", 
                    provider.ConnectionID, content.TableName);
                
                Assert.IsTrue(geom.EqualsExact(feat.Geometry));

            }

            Collection<IGeometry> geoms = null;
            Assert.DoesNotThrow(() => geoms = provider.GetGeometriesInView(extent),
                    "GetFeature threw exception:\n\tConnection{0}\n\t{1}",
                    provider.ConnectionID, content.TableName);

            Assert.AreEqual(numFeatures, geoms.Count);
            
            var fds = new FeatureDataSet();
            Assert.DoesNotThrow(() => provider.ExecuteIntersectionQuery(extent, fds),
                    "GetFeature threw exception:\n\tConnection{0}\n\t{1}",
                    provider.ConnectionID, content.TableName);
            Assert.AreEqual(numFeatures, fds.Tables[0].Rows.Count);


        }
Exemplo n.º 7
0
        private string BuildRtreeConstraint(GpkgContent content)
        {
            string rtreeName;
            using (var cn = new SQLiteConnection(_content.ConnectionString).OpenAndReturn())
            {
                var cmd = new SQLiteCommand(SqlBuildRtreeConstraint, cn);
                cmd.Parameters.AddWithValue(null, content.TableName);
                var tmp = cmd.ExecuteScalar();
                if (tmp == null) 
                    return string.Empty;
                rtreeName = (string) tmp;
            }

            var sb = new StringBuilder();
            sb.AppendFormat(" \"{0}\" IN (", _content.OidColumn);
            sb.AppendFormat("SELECT \"id\" FROM \"{0}\" WHERE minX>=? AND maxX<=? AND minY>=? AND maxY<=?)", rtreeName);
            
            return sb.ToString();
        }
Exemplo n.º 8
0
        private string BuildRtreeConstraint(GpkgContent content)
        {
            string rtreeName;

            using (var cn = new SQLiteConnection(_content.ConnectionString).OpenAndReturn())
            {
                var cmd = new SQLiteCommand(SqlBuildRtreeConstraint, cn);
                cmd.Parameters.AddWithValue(null, content.TableName);
                var tmp = cmd.ExecuteScalar();
                if (tmp == null)
                {
                    return(string.Empty);
                }
                rtreeName = (string)tmp;
            }

            var sb = new StringBuilder();

            sb.AppendFormat(" \"{0}\" IN (", _content.OidColumn);
            sb.AppendFormat("SELECT \"id\" FROM \"{0}\" WHERE minX>=? AND maxX<=? AND minY>=? AND maxY<=?)", rtreeName);

            return(sb.ToString());
        }
Exemplo n.º 9
0
 private static ILayer CreateVectorLayer(GpkgContent content, IProvider provider)
 {
     return new VectorLayer(content.TableName, provider) { Style = VectorStyle.CreateRandomStyle() };
 }
Exemplo n.º 10
0
        /// <summary>
        /// Method to get a feature layer for the given content
        /// </summary>
        /// <param name="content">The content</param>
        /// <param name="createLayer">A delegate function to create the layer</param>
        /// <returns>A layer</returns>
        public ILayer GetFeatureLayer(GpkgContent content, Func<GpkgContent, IProvider, ILayer> createLayer = null)
        {
            if (content == null)
                throw new ArgumentNullException("content");

            createLayer = createLayer ?? CreateVectorLayer;
            return createLayer(content, GetFeatureProvider(content));
        }
Exemplo n.º 11
0
        public IProvider GetFeatureProvider(GpkgContent content)
        {
            if (content == null)
                throw new ArgumentNullException("content");

            var p = new GpkgProvider(content);
            return p;
        }