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
        public static void selectFromPoint(string point, string slopPoly)
        {
            OSGeo.OGR.Ogr.RegisterAll();
            OSGeo.OGR.Driver     dr        = OSGeo.OGR.Ogr.GetDriverByName("ESRI shapefile");
            OSGeo.OGR.DataSource poiDS     = dr.Open(point, 0);
            OSGeo.OGR.DataSource slopDS    = dr.Open(slopPoly, 1);
            OSGeo.OGR.Layer      poiLayer  = poiDS.GetLayerByIndex(0);
            OSGeo.OGR.Layer      slopLayer = slopDS.GetLayerByIndex(0);

            List <int> staIds    = new List <int>();
            int        poiCount  = WorkFlow.pointIds.Count;
            int        slopCount = slopLayer.GetFeatureCount(0);

            for (int i = 0; i < poiCount; i++)
            {
                OSGeo.OGR.Feature  poiFeat = poiLayer.GetFeature(WorkFlow.pointIds[i]);
                OSGeo.OGR.Geometry poiGeom = poiFeat.GetGeometryRef();
                for (int t = 0; t < slopCount; t++)
                {
                    OSGeo.OGR.Feature  slopFeat = slopLayer.GetFeature(t);
                    OSGeo.OGR.Geometry slopGeom = slopFeat.GetGeometryRef();
                    if (poiGeom.Within(slopGeom))
                    {
                        staIds.Add(t);
                        WorkFlow.pointIds[i] = -1;
                    }
                    slopFeat.Dispose();
                }
                poiFeat.Dispose();
            }
            Console.WriteLine("【本次提取到{0}个要素】", staIds.Count);
            while (WorkFlow.pointIds.IndexOf(-1) > -1)
            {
                WorkFlow.pointIds.Remove(-1);
            }

            for (int i = 0; i < slopCount; i++)
            {
                if (staIds.IndexOf(i) == -1)
                {
                    slopLayer.DeleteFeature(i);
                }
            }
            slopDS.deleteFeatUpdate();
            slopDS.Dispose();
            poiDS.Dispose();
        }