public bool Init()
        {
            if (!System.IO.File.Exists(PolylineFile))
            {
                return(false);
            }
            _polylineFeatureClass = PolylineFile.GetShpFeatureClass();
            if (_polylineFeatureClass == null)
            {
                return(false);
            }
            ISpatialReference spatialReference = SpatialReferenceManager.GetSpatialReference(_polylineFeatureClass);

            _polygonFeatureClass = FeatureClassManager.CreateFeatrueClass(PolygonFile, spatialReference, esriGeometryType.esriGeometryPolygon);
            if (_polygonFeatureClass == null)
            {
                return(false);
            }
            _index = _polygonFeatureClass.Fields.FindField("TCMC");
            if (_index > -1)
            {
                return(true);
            }
            return(false);
        }
        public bool Init()
        {
            if (!System.IO.File.Exists(PolylineFile))
            {
                _error += string.Format("文件:{0} 不存在", PolylineFile);
                return(false);
            }
            _polylineFeatureClass = PolylineFile.GetShpFeatureClass();
            if (_polylineFeatureClass == null)
            {
                _error += string.Format("无法读取文件:{0}", PolylineFile);
                return(false);
            }
            ISpatialReference spatialReference = SpatialReferenceManager.GetSpatialReference(_polylineFeatureClass);

            if (System.IO.File.Exists(PolygonFile))
            {
                System.IO.File.Delete(PolygonFile);
            }
            _polygonFeatureClass = FeatureClassManager.CreateFeatrueClass(PolygonFile, spatialReference, esriGeometryType.esriGeometryPolygon);
            if (_polygonFeatureClass == null)
            {
                _error += string.Format("创建文件:{0}  失败", PolygonFile);
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <returns></returns>
        private bool Init()
        {
            if (CADFiles == null || CADFiles.Count == 0)
            {
                _error += "CAD文件列表为空;";
                return(false);
            }
            if (System.IO.File.Exists(PolylineFile))
            {
                System.IO.File.Delete(PolylineFile);
            }
            var first        = CADFiles[0];
            var featureClass = CADManager.GetFeatureClass(first);

            if (featureClass == null)
            {
                _error += string.Format("读取到的文件:{0}  无法读取信息;", System.IO.Path.GetFileNameWithoutExtension(first));
                return(false);
            }
            ISpatialReference spatialReference = SpatialReferenceManager.GetSpatialReference(featureClass);

            _polylineFeatureClass = FeatureClassManager.CreateFeatrueClass(PolylineFile, spatialReference, esriGeometryType.esriGeometryPolyline);
            if (_polylineFeatureClass == null)
            {
                _error += string.Format("创建shapefile文件:{0}  失败!", PolylineFile);
                return(false);
            }
            _errorList = new List <string>();
            return(true);
        }
        private bool TranslatePolylineToPolygon(string inputFilePath, string SaveFilePath, string layerName)
        {
            IFeatureClass featureClass = inputFilePath.GetShpFeatureClass();

            if (featureClass == null)
            {
                return(false);
            }
            ISpatialReference spatialReference   = SpatialReferenceManager.GetSpatialReference(featureClass);
            IFeatureClass     createFeatureClass = FeatureClassManager.CreateFeatrueClass(SaveFilePath, spatialReference, esriGeometryType.esriGeometryPolygon);

            if (createFeatureClass == null)
            {
                return(false);
            }
            var index = createFeatureClass.Fields.FindField("TCMC");

            if (index > -1)
            {
                var            cursor2       = createFeatureClass.Insert(true);
                IFeatureCursor featureCursor = featureClass.Search(null, false);
                IFeature       feature       = featureCursor.NextFeature();
                while (feature != null)
                {
                    if (IsPolygon(feature))
                    {
                        var pg = GeneratePolygon(feature.ShapeCopy);
                        if (pg != null)
                        {
                            var buffer = createFeatureClass.CreateFeatureBuffer();
                            buffer.Shape = pg;
                            buffer.set_Value(index, layerName);
                            cursor2.InsertFeature(buffer);
                        }
                    }
                    feature = featureCursor.NextFeature();
                }
                cursor2.Flush();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
            }

            return(true);
        }