Exemple #1
0
        /// <summary>
        /// 清理重复的Featuer----------多线程----与单线程效率差别很小,不推荐
        /// </summary>
        /// <param name="filePath"></param>
        public static void cleanPdxM(string filePath)
        {
            OSGeo.OGR.Ogr.RegisterAll();
            OSGeo.OGR.Driver     dr    = OSGeo.OGR.Ogr.GetDriverByName("ESRI shapefile");
            OSGeo.OGR.DataSource ds    = dr.Open(filePath, 1);
            OSGeo.OGR.Layer      layer = ds.GetLayerByIndex(0);
            int featCount = layer.GetFeatureCount(0);

            var sw = new System.Diagnostics.Stopwatch(); sw.Start();

            for (int i = 0; i < featCount - 1; i++)
            {
                getDoubFeat(filePath, i, featCount);
            }
            while (tickTime != featCount - 1)
            {
                Thread.Sleep(2000);
                Console.WriteLine(tickTime.ToString() + " /" + featCount.ToString() + "/ deletePoint " + ids.Count().ToString());
            }
            sw.Stop(); Console.WriteLine("多线程清理重复Featuer用时:" + sw.Elapsed.ToString());

            for (int i = 0; i < ids.Count; i++)
            {
                layer.DeleteFeature(ids[i]);
            }
            string a = "REPACK " + layer.GetName();

            ds.ExecuteSQL(a, null, "");
            ds.Dispose();
        }
Exemple #2
0
        /****************************** Delete Feature Update ********************************************/

        public static void deleteFeatUpdate(this OSGeo.OGR.DataSource myDS)
        {
            string a = "REPACK " + myDS.GetLayerByIndex(0).GetName();

            myDS.ExecuteSQL(a, null, "");
            myDS.Dispose();
        }
Exemple #3
0
        public FeatureDataSet ExecuteQuery(string query, Geometry filter)
        {
            try
            {
                FeatureDataSet   ds   = new FeatureDataSet();
                FeatureDataTable myDt = new FeatureDataTable();

                Layer results = _OgrDataSource.ExecuteSQL(query, filter, "");

                //reads the column definition of the layer/feature
                ReadColumnDefinition(myDt, results);

                OSGeo.OGR.Feature _OgrFeature;
                results.ResetReading();
                while ((_OgrFeature = results.GetNextFeature()) != null)
                {
                    FeatureDataRow _dr = myDt.NewRow();
                    for (int iField = 0; iField < _OgrFeature.GetFieldCount(); iField++)
                    {
                        if (myDt.Columns[iField].DataType == System.Type.GetType("System.String"))
                        {
                            _dr[iField] = _OgrFeature.GetFieldAsString(iField);
                        }
                        else if (myDt.Columns[iField].GetType() == System.Type.GetType("System.Int32"))
                        {
                            _dr[iField] = _OgrFeature.GetFieldAsInteger(iField);
                        }
                        else if (myDt.Columns[iField].GetType() == System.Type.GetType("System.Double"))
                        {
                            _dr[iField] = _OgrFeature.GetFieldAsDouble(iField);
                        }
                        else
                        {
                            _dr[iField] = _OgrFeature.GetFieldAsString(iField);
                        }
                    }

                    _dr.Geometry = this.ParseOgrGeometry(_OgrFeature.GetGeometryRef());
                    myDt.AddRow(_dr);
                }
                ds.Tables.Add(myDt);
                _OgrDataSource.ReleaseResultSet(results);

                return(ds);
            }
            catch (Exception exc)
            {
                System.Diagnostics.Debug.WriteLine(exc.ToString());
                return(new FeatureDataSet());
            }
        }