예제 #1
0
        public Feature[] GetFeatures(string fname)
        {
            if (fname == null)
            {
                return(null);
            }
            IVectorFeatureDataReader dr = VectorDataReaderFactory.GetUniversalDataReader(fname) as IVectorFeatureDataReader;

            if (dr == null)
            {
                return(null);
            }
            try
            {
                Feature[] fets = dr.FetchFeatures();
                if (fets == null || fets.Length == 0)
                {
                    return(null);
                }
                List <Feature> features = new List <Feature>();
                foreach (Feature fet in fets)
                {
                    if (fet.Geometry is ShapePolygon)
                    {
                        features.Add(fet);
                    }
                }
                return(features != null?features.ToArray() : null);
            }
            finally
            {
                dr.Dispose();
            }
        }
예제 #2
0
        public Feature[] LoadFeatures()
        {
            if (_urls == null)
            {
                return(null);
            }
            List <Feature>           fets = new List <Feature>();
            IVectorFeatureDataReader dr   = null;

            Feature[] temp = null;
            foreach (string url in _urls)
            {
                dr = VectorDataReaderFactory.GetUniversalDataReader(url) as IVectorFeatureDataReader;
                if (dr == null)
                {
                    continue;
                }
                try
                {
                    temp = dr.FetchFeatures();
                    if (temp == null || temp.Length == 0)
                    {
                        continue;
                    }
                    fets.AddRange(temp);
                }
                finally
                {
                    dr.Dispose();
                }
            }
            return(fets.Count == 0 ? null : fets.ToArray());
        }
예제 #3
0
 public override void EndRead()
 {
     try
     {
         if (_reader != null)
         {
             _reader.Dispose();
             _reader = null;
         }
     }
     finally
     {
         _readIsFinished = true;
         _isReady        = false;
     }
 }
예제 #4
0
 public void Dispose()
 {
     if (_vdr != null)
     {
         _vdr.Dispose();
         //_vdr = null;
     }
 }
예제 #5
0
        public ShapePolygon[] GetGeometry(List <string> retNames, string nameField)
        {
            string fname = FindVector();

            if (fname == null)
            {
                return(null);
            }
            IVectorFeatureDataReader dr = VectorDataReaderFactory.GetUniversalDataReader(fname) as IVectorFeatureDataReader;

            if (dr == null)
            {
                return(null);
            }
            try
            {
                Feature[] fets;
                if (_where != null)
                {
                    fets = dr.FetchFeatures((f) => { return(_where(f)); });
                }
                else
                {
                    Feature f = dr.FetchFirstFeature();
                    if (f != null)
                    {
                        fets = new Feature[] { f }
                    }
                    ;
                    else
                    {
                        return(null);
                    }
                }
                if (fets == null || fets.Length == 0)
                {
                    return(null);
                }
                List <ShapePolygon> geometrys = new List <ShapePolygon>();
                foreach (Feature fet in fets)
                {
                    geometrys.Add(fet.Geometry as ShapePolygon);
                    if (retNames != null)
                    {
                        retNames.Add(fet.GetFieldValue(nameField) ?? string.Empty);
                    }
                }
                return(geometrys.ToArray());
            }
            finally
            {
                dr.Dispose();
            }
        }
예제 #6
0
        private void LoadMaskTemplateFromShapeFile(string filename)
        {
            IVectorFeatureDataReader vdr = VectorDataReaderFactory.GetUniversalDataReader(filename) as IVectorFeatureDataReader;

            if (vdr == null)
            {
                MessageBox.Show("输入的矢量文件\"" + filename + "\"格式错误,无法作为模板装入!");
                return;
            }
            if (vdr.ShapeType != enumShapeType.Polygon)
            {
                MessageBox.Show("不支持非多边形矢量文件作为模板装入!");
                return;
            }
            try
            {
                int fetCount = vdr.FeatureCount;
                if (fetCount == 1)
                {
                    SetMaskTemplateMatrixFromFeature(filename, vdr.Features[0]);
                }
                else
                {
                    using (frmFeatureSelector frm = new frmFeatureSelector(vdr.Features))
                    {
                        //frm.TopMost = true;
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                            txtFileName.Text = filename;
                            Feature[] fets = frm.GetSelectedVectorFeatures();
                            if (fets == null || fets.Length == 0)
                            {
                                return;
                            }
                            for (int i = 0; i < fets.Length; i++)
                            {
                                SetMaskTemplateMatrixFromFeature(filename, fets[i]);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (vdr != null)
                {
                    vdr.Dispose();
                }
            }
        }
예제 #7
0
        private void LoadMaskTemplateFromShapeFile(string filename)
        {
            IVectorFeatureDataReader vdr = VectorDataReaderFactory.GetUniversalDataReader(filename) as IVectorFeatureDataReader;

            if (vdr == null)
            {
                //MsgBox.ShowInfo("输入的矢量文件\"" + filename + "\"格式错误,无法作为模板装入!");
                return;
            }
            if (vdr.ShapeType != enumShapeType.Polygon)
            {
                //MsgBox.ShowInfo("不支持非多边形矢量文件作为模板装入!");
                return;
            }
            try
            {
                _maskObj = vdr.Features[0];
                //int fetCount = vdr.FeatureCount;
                //if (fetCount == 1)
                //{
                //    SetMaskTemplateMatrixFromFeature(filename, vdr.FetchFirstFeature());
                //}
                //else
                //{
                //    using (frmFeatureSelector frm = new frmFeatureSelector(vdr.Features))
                //    {
                //        if (frm.ShowDialog() == DialogResult.OK)
                //        {
                //            Feature[] fets = frm.GetSelectedVectorFeatures();
                //            if (fets == null || fets.Length == 0)
                //                return;
                //            for (int i = 0; i < fets.Length; i++)
                //            {
                //                SetMaskTemplateMatrixFromFeature(filename, fets[i]);
                //            }
                //        }
                //    }
                //}
            }
            finally
            {
                if (vdr != null)
                {
                    vdr.Dispose();
                }
            }
        }
예제 #8
0
        public Feature[] GetFeatures()
        {
            string fname = FindVector();

            if (fname == null)
            {
                return(null);
            }
            IVectorFeatureDataReader dr = VectorDataReaderFactory.GetUniversalDataReader(fname) as IVectorFeatureDataReader;

            if (dr == null)
            {
                return(null);
            }
            try
            {
                Feature[] fets;
                if (_where != null)
                {
                    fets = dr.FetchFeatures((f) => { return(_where(f)); });
                }
                else
                {
                    Feature f = dr.FetchFirstFeature();
                    if (f != null)
                    {
                        fets = new Feature[] { f }
                    }
                    ;
                    else
                    {
                        return(null);
                    }
                }
                return(fets.Length == 0 ? null : fets.ToArray());
            }
            finally
            {
                dr.Dispose();
            }
        }
예제 #9
0
        private object ReadFeatures(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return(null);
            }
            IVectorFeatureDataReader dr = VectorDataReaderFactory.GetUniversalDataReader(filename) as IVectorFeatureDataReader;

            if (dr == null)
            {
                return(null);
            }
            try
            {
                return(dr.Features);
            }
            finally
            {
                dr.Dispose();
            }
        }
예제 #10
0
        protected override bool Execute(IContextMessage contextMessage)
        {
            IVectorFeatureDataReader vdr  = null;
            OdbcConnection           conn = null;
            OdbcCommand cmd = null;

            try
            {
                if (!ResFieldIsOK(out vdr))
                {
                    contextMessage.AddError("字段映射关系中源字段设置有错误。");
                    return(false);
                }
                if (!DesFieldIsOK(out conn, out cmd))
                {
                    contextMessage.AddError("字段映射关系中目标字段设置有错误。");
                    return(false);
                }
                ImportFeatures(conn, cmd, vdr);
                return(true);
            }
            finally
            {
                if (vdr != null)
                {
                    vdr.Dispose();
                }
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                if (conn != null)
                {
                    conn.Dispose();
                }
            }
        }
예제 #11
0
        public int[] ProcessVectorToArray(string shpFileName, string firlistfname)
        {
            //sw.WriteLine("NO.\t" + "Latitude\t" + "Longitude\t" + "Size/ha\t" + "Temperature/K\t" + "Fire_Intensity\t" + "Reliability");
            Feature[] features          = null;
            IVectorFeatureDataReader dr = null;

            if (Path.GetExtension(shpFileName).ToUpper() == ".SHP")
            {
                dr = VectorDataReaderFactory.GetUniversalDataReader(shpFileName) as IVectorFeatureDataReader;
                if (dr == null)
                {
                    return(null);
                }
                features = dr.Features;
            }
            else if (Path.GetExtension(shpFileName).ToUpper() == ".TXT")
            {
                string[]       pointContext = File.ReadAllLines(shpFileName);
                List <Feature> featureList  = new List <Feature>();
                Feature        tempFeature  = null;
                if (pointContext != null && pointContext.Length != 0)
                {
                    int length = pointContext.Length;
                    for (int i = 1; i < length; i++)
                    {
                        string[] tempSplit = pointContext[i].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                        if (tempSplit == null || tempSplit.Length != 7)
                        {
                            continue;
                        }
                        tempFeature = new Feature(int.Parse(tempSplit[0]), new ShapePoint(double.Parse(tempSplit[2]), double.Parse(tempSplit[1])),
                                                  new string[] { "0", "1", "2", "Latitude", "Longitude", "Size", "Temperature", "Fire_Intensity", "Reliability" },
                                                  new string[] { "0", "1", "2", tempSplit[1], tempSplit[2], tempSplit[3], tempSplit[4], tempSplit[5], tempSplit[6] }, null);
                        featureList.Add(tempFeature);
                    }
                }
                features = featureList.Count == 0 ? null : featureList.ToArray();
            }
            if (features == null || features.Length < 1)
            {
                return(null);
            }
            using (StreamWriter sw = new StreamWriter(firlistfname, true, Encoding.Default))
            {
                List <int> index = new List <int>();
                int        position;
                string[]   fieldValues;
                foreach (Feature fea in features)
                {
                    fieldValues = fea.FieldValues;
                    _firePointsCount++;
                    if (fea.FieldValues != null)
                    {
                        //_firePointsCount++;
                        sw.WriteLine(_firePointsCount + "\t" + fieldValues[3].PadLeft(7) + "\t\t" + fieldValues[4].PadLeft(7) + "\t\t" + fieldValues[5].PadLeft(7) + "\t\t" + fieldValues[6] + "\t\t" + fieldValues[7] + "\t\t" + fieldValues[8]);
                        ShapePoint pt  = fea.Geometry as ShapePoint;
                        int        col = (int)Math.Ceiling((pt.X + 180) / _resolution) - 1;
                        int        row = (int)Math.Ceiling((90 - pt.Y) / _resolution) - 1;
                        position = _datwidth * row + col;
                        index.Add(position);
                    }
                    else
                    {
                        sw.WriteLine(_firePointsCount);
                    }
                }
                return(index.ToArray());
            }
            if (dr != null)
            {
                dr.Dispose();
            }
        }