示例#1
0
        /// <summary>
        /// 整合坡度多边形(Polygon),并清除重叠部份
        /// </summary>
        /// <param name="subPdx"></param>
        /// <returns></returns>
        public static string zhengHePdx(List <string> subPdx)
        {
            OSGeo.OGR.Ogr.RegisterAll();
            OSGeo.OGR.Driver dr  = OSGeo.OGR.Ogr.GetDriverByName("ESRI shapefile");
            string           res = StaticTools.tempFilePath("shp", "整合");

            OSGeo.OGR.DataSource newDS = dr.CreateDataSource(res, null);                                              //////////////待关闭1  has
            Layer newLayer             = newDS.CreateLayer("podu", null, OSGeo.OGR.wkbGeometryType.wkbPolygon, null); //////////////待关闭2

            for (int i = 0; i < subPdx.Count; i++)
            {
                OSGeo.OGR.DataSource ds = dr.Open(subPdx[i], 0);//////////////待关闭3   has
                Layer layer             = ds.GetLayerByIndex(0);
                for (int j = 0; j < layer.GetFeatureCount(0); j++)
                {
                    OSGeo.OGR.Feature  subFeat  = layer.GetFeature(j);
                    OSGeo.OGR.Geometry subGeom  = subFeat.GetGeometryRef();
                    double             thisArea = subGeom.GetArea();
                    // 清理过小Featuer
                    if (thisArea > 200)
                    {
                        newLayer.CreateFeature(layer.GetFeature(j));
                    }
                }
                ds.Dispose();
                Console.WriteLine("完成整合{0}/{1}", i + 1, subPdx.Count);
            }
            newDS.Dispose();
            cleanPdx(res);
            return(res);
        }
示例#2
0
        /// <summary>
        /// 整合坡度线(Line)
        /// </summary>
        /// <param name="subPdx"></param>
        /// <returns></returns>
        public static string zhengHePdLine(List <string> subPdx)
        {
            OSGeo.OGR.Ogr.RegisterAll();
            OSGeo.OGR.Driver dr = OSGeo.OGR.Ogr.GetDriverByName("ESRI shapefile");

            string newPath = StaticTools.tempFilePath("shp", "整合线");

            OSGeo.OGR.DataSource newDs    = dr.CreateDataSource(newPath, null);/////////////////
            OSGeo.OGR.Layer      newLayer = newDs.CreateLayer("Lines",
                                                              dr.Open(subPdx[0], 0).GetLayerByIndex(0).GetSpatialRef(),
                                                              dr.Open(subPdx[0], 0).GetLayerByIndex(0).GetGeomType(), null);

            for (int i = 0; i < subPdx.Count; i++)
            {
                OSGeo.OGR.DataSource dsLine    = dr.Open(subPdx[i], 0);///////////////////////
                OSGeo.OGR.Layer      lineLayer = dsLine.GetLayerByIndex(0);
                for (int j = 0; j < lineLayer.GetFeatureCount(0); j++)
                {
                    newLayer.CreateFeature(lineLayer.GetFeature(j));
                }
                dsLine.Dispose();
            }
            newDs.Dispose();
            return(newPath);
        }
示例#3
0
        public static void selectDZXFromPointM(string point, string dzx, string savePath)
        {
            OSGeo.OGR.Ogr.RegisterAll();
            OSGeo.OGR.Driver dr = OSGeo.OGR.Ogr.GetDriverByName("ESRI shapefile");

            OSGeo.OGR.DataSource poiDS    = dr.Open(point, 0);
            OSGeo.OGR.Layer      poiLayer = poiDS.GetLayerByIndex(0);

            if (File.Exists(savePath))
            {
                File.Delete(savePath);
            }
            OSGeo.OGR.DataSource newDS    = dr.CreateDataSource(savePath, null);
            OSGeo.OGR.Layer      newLayer = newDS.CreateLayer("", null, OSGeo.OGR.wkbGeometryType.wkbPolygon, null);

            tickTime = 0;
            int poiCount = poiLayer.GetFeatureCount(0);

            for (int i = 0; i < poiCount; i++)
            {
                subAdd(poiLayer.GetFeature(i), dzx, newLayer);
            }
            while (tickTime < poiCount)
            {
                Thread.Sleep(2222);
                Console.WriteLine("getFeatureByPoint:{0}/{1}", tickTime, poiCount);
            }

            Console.WriteLine("【本次提取到{0}个要素】", newLayer.GetFeatureCount(0));
            newDS.Dispose();
            poiDS.Dispose();
        }
示例#4
0
        /************************************  对比并筛选 ***************************************************/

        /// <summary>
        /// 通过ID数组提取出所有要素,创建动作
        /// </summary>
        /// <param name="dzLine"></param>
        /// <param name="pdLing"></param>
        /// <param name="savePath"></param>
        public static void selectFeat(string dzx, string pdx, string savePath)
        {
            Stopwatch ssww = new Stopwatch(); ssww.Start();

            //获得数组
            int[] a = getMinIdGroupM(dzx, pdx);

            Console.WriteLine("ID to Feater...");
            OSGeo.OGR.Ogr.RegisterAll();
            OSGeo.OGR.Driver     dr      = OSGeo.OGR.Ogr.GetDriverByName("ESRI shapefile");
            OSGeo.OGR.DataSource dzDS    = dr.Open(dzx, 0);
            OSGeo.OGR.Layer      dzLayer = dzDS.GetLayerByIndex(0);
            if (System.IO.File.Exists(savePath))
            {
                System.IO.File.Delete(savePath);
            }
            OSGeo.OGR.DataSource ds        = dr.CreateDataSource(savePath, null);
            OSGeo.OGR.Layer      fileLayer = ds.CreateLayer("", null, OSGeo.OGR.wkbGeometryType.wkbPolygon, null);
            //get featuer by ID
            for (int i = 0; i < a.Length; i++)
            {
                fileLayer.CreateFeature(dzLayer.GetFeature(a[i]));
                dzLayer.GetFeature(a[i]).Dispose();
            }
            dzLayer.Dispose();
            dzDS.Dispose();
            fileLayer.Dispose();
            ds.Dispose();
            _2_坡度线.OutLine.CutImg.cleanPdxM(savePath);
            ssww.Stop();
            Console.WriteLine("提取轮廓线完成!用时:{0}", ssww.Elapsed.ToString());
        }
示例#5
0
        /*************************************  点角式  *****************************************/
        /// <summary>
        /// 清理等后生成新的文件
        ///
        /// </summary>
        public static void claenPoint(string filePath, string savefile, double jiaodu, int cishu)
        {
            OSGeo.OGR.Ogr.RegisterAll();
            OSGeo.OGR.Driver dr = OSGeo.OGR.Ogr.GetDriverByName("ESRI shapefile");
            //进来的Layer
            OSGeo.OGR.DataSource oriDs    = dr.Open(filePath, 0);
            OSGeo.OGR.Layer      oriLayer = oriDs.GetLayerByIndex(0);
            //出去的Layer
            if (System.IO.File.Exists(savefile))
            {
                savefile.deleteFiles();
            }
            OSGeo.OGR.DataSource targDs    = dr.CreateDataSource(savefile, null);
            OSGeo.OGR.Layer      targLayer = targDs.CreateLayer("targ", null, OSGeo.OGR.wkbGeometryType.wkbPolygon, null);

            int featCount = oriLayer.GetFeatureCount(0);

            for (int i = 0; i < featCount; i++)
            {
                ///进来的Featuer
                OSGeo.OGR.Feature oriFeat = oriLayer.GetFeature(i);

                ///把一个Featuer转为点数组
                OSGeo.OGR.Geometry oriGeom = oriFeat.GetGeometryRef();
                OSGeo.OGR.Geometry subGeom = oriGeom.GetGeometryRef(0);
                int     pointCount         = subGeom.GetPointCount();
                Point[] aFeat = new Point[pointCount];
                for (int c = 0; c < pointCount; c++)
                {
                    aFeat[c].X = subGeom.GetX(c);
                    aFeat[c].Y = subGeom.GetY(c);
                    aFeat[c].Z = subGeom.GetZ(c);
                }

                ///调选点方法,得到一个新的Featuer
                Geometry newGeom = null;
                if (aFeat.Length > cishu * 3)
                {
                    newGeom = JID(aFeat, jiaodu, cishu);
                }
                else
                {
                    oriFeat.Dispose();
                    continue;
                }
                if (newGeom != null)
                {
                    Feature temp = new Feature(new FeatureDefn(""));
                    temp.SetGeometry(newGeom);
                    targLayer.CreateFeature(temp);
                    temp.Dispose();
                }
                oriFeat.Dispose();
                Console.WriteLine("已完成{0}/{1}", i, featCount);
            }
            oriDs.Dispose();
            targDs.Dispose();
        }
示例#6
0
        public static void selectDZXFromPoint(string point, string dzx, string savePath)
        {
            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 dzxDS = dr.Open(dzx, 0);
            if (File.Exists(savePath))
            {
                File.Delete(savePath);
            }
            OSGeo.OGR.DataSource newDS    = dr.CreateDataSource(savePath, null);
            OSGeo.OGR.Layer      poiLayer = poiDS.GetLayerByIndex(0);
            OSGeo.OGR.Layer      dzxLayer = dzxDS.GetLayerByIndex(0);
            OSGeo.OGR.Layer      newLayer = newDS.CreateLayer("", dzxLayer.GetSpatialRef(), dzxLayer.GetGeomType(), null);

            int poiCount = poiLayer.GetFeatureCount(0);
            int dzxCount = dzxLayer.GetFeatureCount(0);

            for (int i = 0; i < poiCount; i++)
            {
                OSGeo.OGR.Feature  poiFeat = poiLayer.GetFeature(i);
                OSGeo.OGR.Geometry poiGeom = poiFeat.GetGeometryRef();
                for (int t = 0; t < dzxCount; t++)
                {
                    OSGeo.OGR.Feature  dzxFeat = dzxLayer.GetFeature(t);
                    OSGeo.OGR.Geometry dzxGeom = dzxFeat.GetGeometryRef();

                    if (poiGeom.Within(dzxGeom))
                    {
                        newLayer.CreateFeature(dzxFeat);
                    }
                    dzxFeat.Dispose();
                    Console.WriteLine("getFeatureByPoint:{0}/{1}", i, poiCount);
                }
                poiFeat.Dispose();
            }
            Console.WriteLine("【本次提取到{0}个要素】", newLayer.GetFeatureCount(0));
            newDS.Dispose();
            dzxDS.Dispose();
            poiDS.Dispose();
        }