private void AddFields(string shapeFilePath, string fieldName, esriFieldType type)
        {
            _shapeOp.FilePath = shapeFilePath;
            IFeatureClass pFeatureClass = _shapeOp.OpenFeatureClass();

            if (pFeatureClass.Fields.FindField(fieldName) == -1)
            {
                _shapeOp.AddField(pFeatureClass, fieldName, type);
                GC.Collect();
            }
        }
Exemplo n.º 2
0
 private void LoadMap(string layerType, esriGeometryType targetType)
 {
     try
     {
         //如果存在,删除
         if (_mapIndex.ContainsKey(layerType))
         {
             var pLayer = _axMapControl.Map.Layer[_mapIndex[layerType]];
             _axMapControl.Map.DeleteLayer(pLayer);
             _mapIndex.Remove(layerType);
         }
         //添加
         var pFeatureClass = _shapeOp.OpenFeatureClass();
         if (!pFeatureClass.GeometryTypeCheck(targetType))
         {
             throw new Exception("打开要素类型不正确");
         }
         _axMapControl.Map.AddLayer(new FeatureLayerClass()
         {
             FeatureClass = pFeatureClass
         });
         _mapIndex.Add(layerType, _axMapControl.Map.LayerCount - 1);
     }
     catch (Exception e)
     {
         Messenger.Default.Send(new GenericMessage <string>(e.Message), "Exception");
     }
 }
Exemplo n.º 3
0
        public static IEnumerable <HighTrainPath> ReadRailway(string filePath)
        {
            _shapeOp = new ShapeOp(filePath);
            var pFeatureClass = _shapeOp.OpenFeatureClass();

            if (!pFeatureClass.FieldExistCheck("Speed", "起点", "终点"))
            {
                throw new ArgumentException("部分字段不存在");
            }
            IFeatureCursor pFeaureCursor = pFeatureClass.Search(null, false);
            IFeature       pFeature;
            int            speedIndex = pFeatureClass.Fields.FindField("Speed");
            int            startIndex = pFeatureClass.Fields.FindField("起点");
            int            stopIndex  = pFeatureClass.Fields.FindField("终点");

            while ((pFeature = pFeaureCursor.NextFeature()) != null)
            {
                var       speed    = Convert.ToSingle(pFeature.Value[speedIndex]);
                var       start    = Convert.ToString(pFeature.Value[startIndex]);
                var       stop     = Convert.ToString(pFeature.Value[stopIndex]);
                IPolyline polyline = pFeature.Shape as IPolyline;
                var       distance = (float)polyline.Length;
                yield return(new HighTrainPath(start, stop, distance, speed));
            }
            Marshal.ReleaseComObject(pFeaureCursor);
        }
Exemplo n.º 4
0
        private void InitDic()
        {
            ShapeOp       shapeOp       = new ShapeOp(CityFilePath);
            IFeatureClass pFeatureClass = shapeOp.OpenFeatureClass();
            var           res           = shapeOp.FindValue(pFeatureClass, "Name", SelectedIndex);

            foreach (var re in res)
            {
                CityValues.Add(re.Key, Convert.ToSingle(re.Value));
            }
        }
        private void InitPop()
        {
            _popDic = new Dictionary <string, float>();
            if (String.IsNullOrEmpty(_selectedPopIndex))
            {
                return;
            }
            ShapeOp op            = new ShapeOp(CityFilePath);
            var     pFeatureClass = op.OpenFeatureClass();
            var     res           = op.FindValue(pFeatureClass, "Name", SelectedPopIndex);

            foreach (var re in res)
            {
                _popDic.Add(re.Key, Convert.ToSingle(re.Value));
            }
        }
Exemplo n.º 6
0
 private void InitControls()
 {
     Cities = new ObservableCollection <CalculatorCity>();
     try
     {
         var cities = NetWorkUtil.ReadCities(CityFilePath);
         foreach (var city in cities)
         {
             Cities.Add(new CalculatorCity(city));
         }
         ShapeOp shapeOp = new ShapeOp(CityFilePath);
         Indexes = shapeOp.OpenFeatureClass().NumbericFieldsName();
     }
     catch (ArgumentException e)
     {
         Messenger.Default.Send(new GenericMessage <string>(e.Message), "Exception");
     }
     catch (Exception e)
     {
         _log.Error(e.Message + e.StackTrace);
     }
 }
Exemplo n.º 7
0
        public static IEnumerable <City> ReadCities(string filePath)
        {
            _shapeOp = new ShapeOp(filePath);
            var pFeatureClass = _shapeOp.OpenFeatureClass();

            if (!pFeatureClass.FieldExistCheck("Name") ||
                !pFeatureClass.FieldExistCheck("是否为站点"))
            {
                throw new ArgumentException("部分字段不存在");
            }
            IFeatureCursor pFeaureCursor = pFeatureClass.Search(null, false);
            IFeature       pFeature;
            int            nameIndex = pFeatureClass.Fields.FindField("Name");
            int            typeIndex = pFeatureClass.Fields.FindField("是否为站点");

            while ((pFeature = pFeaureCursor.NextFeature()) != null)
            {
                var    name  = Convert.ToString(pFeature.Value[nameIndex]);
                IPoint point = pFeature.Shape as IPoint;
                yield return(new City(point.X, point.Y, name, pFeature.Value[typeIndex].ToString().Trim()));
            }
            Marshal.ReleaseComObject(pFeaureCursor);
        }