コード例 #1
0
        public IEnumerable <IFeature> GetFeatures(IGeometry bbox, string filter, double scale)
        {
            OpenConnection();
            OleDbDataReader dr = null;

            Topology.IO.WKBReader wkb = new Topology.IO.WKBReader();
            LinkedList <IFeature> ret = new LinkedList <IFeature>();

            try
            {
                OleDbCommand cmd = m_conn.CreateCommand();
                //cmd.CommandText = "SELECT [" + m_geocolumnname + "].STAsBinary() FROM [" + m_tablename + "] WHERE geometry::STGeomFromWKB(?, 0).STIntersects([" + m_geocolumnname + "]) = 1";
                cmd.CommandText = "SELECT [" + m_geocolumnname + "].STAsBinary() FROM [" + m_tablename + "]";
                //cmd.Parameters.Add(bbox.AsBinary());
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    ret.AddLast(new SimpleFeature(wkb.Read((byte[])dr.GetValue(0)), m_areastyle));
                }

                return(ret);
            }
            catch (Exception ex)
            {
                throw new Exception("Couldn't load features\nError: " + ex.Message);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
            }
        }
コード例 #2
0
		public IEnumerable<IFeature> GetFeatures(IGeometry bbox, string filter, double scale)
		{
			OpenConnection();
			OleDbDataReader dr = null;
			Topology.IO.WKBReader wkb = new Topology.IO.WKBReader();
			LinkedList<IFeature> ret = new LinkedList<IFeature>();
			try
			{
				OleDbCommand cmd = m_conn.CreateCommand();
				//cmd.CommandText = "SELECT [" + m_geocolumnname + "].STAsBinary() FROM [" + m_tablename + "] WHERE geometry::STGeomFromWKB(?, 0).STIntersects([" + m_geocolumnname + "]) = 1";
				cmd.CommandText = "SELECT [" + m_geocolumnname + "].STAsBinary() FROM [" + m_tablename + "]";
				//cmd.Parameters.Add(bbox.AsBinary());
				dr = cmd.ExecuteReader();
				while (dr.Read())
				{
					ret.AddLast( new SimpleFeature( wkb.Read((byte[])dr.GetValue(0)), m_areastyle));
				}

				return ret;
			}
			catch (Exception ex)
			{
				throw new Exception("Couldn't load features\nError: " + ex.Message);
			}
			finally
			{
				if (dr != null) dr.Close();
			}
		}
コード例 #3
0
        public IEnumerable <IFeature> GetFeatures(IEnvelope bbox, string filter, double scale)
        {
            //are we cached?
            Polygon p = null;

            foreach (IEnvelope area in m_cachedareas.Query(bbox))
            {
                if (p == null)
                {
                    p = ConvertEnvelopeToPolygon(area);
                }
                else
                {
                    p.Union(ConvertEnvelopeToPolygon(area));
                }
            }
            if (p != null && p.Covers(ConvertEnvelopeToPolygon(bbox)))
            {
                //load from cache
                LinkedList <IFeature> ret = new LinkedList <IFeature>();
                m_objects.Query(bbox, new FeatureLinkedListVisitor(ret));
                return(ret);
            }

            OpenConnection();

            //load from DB
            IDbCommand cmd = m_conn.CreateCommand();

            cmd.CommandText = "SELECT " + m_PrimaryColumn + ", " + m_WKBColumn + " FROM " + m_tablename + " WHERE "
                              + m_X1Column + " >= " + bbox.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_X1Column + " <= " + bbox.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y1Column + " >= " + bbox.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y1Column + " <= " + bbox.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " OR "
                              + m_X2Column + " >= " + bbox.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_X2Column + " <= " + bbox.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y1Column + " >= " + bbox.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y1Column + " <= " + bbox.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " OR "
                              + m_X2Column + " >= " + bbox.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_X2Column + " <= " + bbox.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y2Column + " >= " + bbox.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y2Column + " <= " + bbox.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " OR "
                              + m_X1Column + " >= " + bbox.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_X1Column + " <= " + bbox.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y2Column + " >= " + bbox.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y2Column + " <= " + bbox.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture);

            IDataReader           dr     = null;
            LinkedList <IFeature> fromdb = new LinkedList <IFeature>();

            try
            {
                dr = cmd.ExecuteReader();
                Topology.IO.WKBReader wkbreader = new Topology.IO.WKBReader();
                int nmap = dr.GetOrdinal(m_WKBColumn);
                int npk  = dr.GetOrdinal(m_PrimaryColumn);
                while (dr.Read())
                {
                    IGeometry     g  = wkbreader.Read((byte[])dr.GetValue(nmap));
                    int           pk = (int)dr.GetValue(npk);
                    SimpleFeature f  = new SimpleFeature(g, m_areastyle, pk);
                    if (!m_PrimaryKeyIndex.ContainsKey(pk))
                    {
                        fromdb.AddLast(f);
                        m_PrimaryKeyIndex.Add(pk, f);
                        m_objects.Insert(g.EnvelopeInternal, f);
                    }
                    else
                    {
                        fromdb.AddLast(m_PrimaryKeyIndex[pk]);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Couldn't load features\nError: " + ex.Message);
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
            }

            //add to cache
            m_cachedareas.Insert(bbox, bbox);

            return(fromdb);
        }
		public IEnumerable<IFeature> GetFeatures(IEnvelope bbox, string filter, double scale)
		{
			//are we cached?
			Polygon p = null;
			foreach (IEnvelope area in m_cachedareas.Query(bbox))
			{
				if (p == null) p = ConvertEnvelopeToPolygon(area);
				else p.Union(ConvertEnvelopeToPolygon(area));
			}
			if(p != null && p.Covers(ConvertEnvelopeToPolygon(bbox)))
			{
				//load from cache
				LinkedList<IFeature> ret = new LinkedList<IFeature>();
				m_objects.Query(bbox, new FeatureLinkedListVisitor(ret));
				return ret;
			}

			OpenConnection();

			//load from DB
			IDbCommand cmd = m_conn.CreateCommand();
			cmd.CommandText = "SELECT " + m_PrimaryColumn + ", " + m_WKBColumn + " FROM " + m_tablename + " WHERE "
				+ m_X1Column + " >= " + bbox.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_X1Column + " <= " + bbox.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y1Column + " >= " + bbox.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y1Column + " <= " + bbox.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " OR "
				+ m_X2Column + " >= " + bbox.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_X2Column + " <= " + bbox.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y1Column + " >= " + bbox.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y1Column + " <= " + bbox.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " OR "
				+ m_X2Column + " >= " + bbox.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_X2Column + " <= " + bbox.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y2Column + " >= " + bbox.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y2Column + " <= " + bbox.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " OR "
				+ m_X1Column + " >= " + bbox.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_X1Column + " <= " + bbox.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y2Column + " >= " + bbox.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture) + " AND " + m_Y2Column + " <= " + bbox.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture);

			IDataReader dr = null;
			LinkedList<IFeature> fromdb = new LinkedList<IFeature>();
			try
			{
				dr = cmd.ExecuteReader();
				Topology.IO.WKBReader wkbreader = new Topology.IO.WKBReader();
				int nmap = dr.GetOrdinal(m_WKBColumn);
				int npk = dr.GetOrdinal(m_PrimaryColumn);
				while (dr.Read())
				{
					IGeometry g = wkbreader.Read((byte[])dr.GetValue(nmap));
					int pk = (int)dr.GetValue(npk);
					SimpleFeature f = new SimpleFeature(g, m_areastyle, pk);
					if (!m_PrimaryKeyIndex.ContainsKey(pk))
					{
						fromdb.AddLast(f);
						m_PrimaryKeyIndex.Add(pk, f);
						m_objects.Insert(g.EnvelopeInternal, f);
					}
					else fromdb.AddLast(m_PrimaryKeyIndex[pk]);
				}
			}
			catch (Exception ex)
			{
				throw new Exception("Couldn't load features\nError: " + ex.Message);
			}
			finally
			{
				if (dr != null) dr.Close();
			}

			//add to cache
			m_cachedareas.Insert(bbox, bbox);

			return fromdb;
				
		}