コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JoinDialog"/> class.
 /// </summary>
 /// <param name="fs">FeatureSet to join the excel file to.</param>
 public JoinDialog(IFeatureSet fs)
 {
     InitializeComponent();
     _featureSet = fs;
     foreach (DataColumn col in fs.GetColumns())
     {
         cbLocalField.Items.Add(col.ColumnName);
     }
 }
コード例 #2
0
ファイル: FeatureSelection.cs プロジェクト: qingqibing/aa
        // The idea is that once a collection is established, its parameters don't change.
        // However sub-classes need to be able to tweak these to their choosing.

        #region IFeatureSelection Members

        /// <inheritdoc />
        public DataTable GetAttributes(int startIndex, int numRows)
        {
            int       count = 0;
            DataTable dt    = new DataTable();

            dt.Columns.AddRange(_featureSet.GetColumns());
            foreach (IFeature feature in Filter)
            {
                if (count >= startIndex && count < startIndex + numRows)
                {
                    dt.Rows.Add(feature.DataRow.ItemArray);
                }
                if (count > numRows + startIndex)
                {
                    break;
                }
                count++;
            }
            return(dt);
        }
コード例 #3
0
        // returns list of column names in layer (or blank if not opened)
        public List <String> shpFields()
        {
            if (!isOpen())
            {
                throw new Exception("No file open");
            }
            List <String> returnList = new List <string>();
            IFeatureSet   featureSet = (IFeatureSet)Layer.DataSet;

            foreach (DataColumn column in featureSet.GetColumns())
            {
                returnList.Add(column.ColumnName);
            }
            return(returnList);
        }
コード例 #4
0
ファイル: FeatureSet.cs プロジェクト: hanchao/DotSpatial
        /// <inheritdoc/>
        public void CopyFeatures(IFeatureSet source, bool copyAttributes)
        {
            ProgressMeter = new ProgressMeter(ProgressHandler, "Copying Features", ShapeIndices.Count);
            Vertex = source.Vertex.Copy();
            _shapeIndices = new List<ShapeRange>();
            foreach (ShapeRange range in source.ShapeIndices)
            {
                _shapeIndices.Add(range.Copy());
            }

            if (copyAttributes)
            {
                foreach (DataColumn dc in source.GetColumns())
                {
                    if (dc != null)
                    {
                        DataColumn outCol = new DataColumn(dc.ColumnName, dc.DataType, dc.Expression, dc.ColumnMapping);
                        Field fld = new Field(outCol);
                        DataTable.Columns.Add(fld);
                    }
                }
            }

            if (source.AttributesPopulated)
            {
                // Handle data table content directly
                if (!IndexMode)
                {
                    // If not in index mode, just handle this using features
                    Features.SuspendEvents();
                    int i = 0;
                    foreach (IFeature f in source.Features)
                    {
                        IFeature copy = AddFeature(f.BasicGeometry);
                        copy.ShapeIndex = ShapeIndices[i];
                        if (copyAttributes)
                        {
                            copy.DataRow.ItemArray = f.DataRow.ItemArray.Copy();
                        }

                        i++;
                    }

                    Features.ResumeEvents();
                }
                else
                {
                    // We need to copy the attributes, but just copy a datarow
                    if (copyAttributes)
                    {
                        foreach (DataRow row in source.DataTable.Rows)
                        {
                            DataRow result = DataTable.NewRow();
                            result.ItemArray = row.ItemArray.Copy();
                            DataTable.Rows.Add(result);
                        }
                    }
                }
            }
            else
            {
                AttributesPopulated = false;

                // Handle data table content directly
                if (!IndexMode)
                {
                    // If not in index mode, just handle this using features
                    Features.SuspendEvents();
                    int i = 0;
                    foreach (IFeature f in source.Features)
                    {
                        IFeature result = AddFeature(f.BasicGeometry);
                        result.ShapeIndex = ShapeIndices[i];
                        i++;
                    }

                    Features.ResumeEvents();
                }

                if (copyAttributes)
                {
                    // We need to copy the attributes, but use the page system
                    int maxRow = NumRows();
                    const int pageSize = 10000;
                    int numPages = (int)Math.Ceiling(maxRow / (double)pageSize);
                    for (int i = 0; i < numPages; i++)
                    {
                        int numRows = pageSize;
                        if (i == numPages - 1)
                        {
                            numRows = numPages - (pageSize * i);
                        }

                        DataTable dt = source.GetAttributes(i * pageSize, numRows);
                        SetAttributes(i * pageSize, dt);
                    }
                }
            }
        }
コード例 #5
0
ファイル: JoinDialog.cs プロジェクト: DIVEROVIEDO/DotSpatial
 /// <summary>
 /// Creates a new instance of JoinDialog
 /// </summary>
 public JoinDialog(IFeatureSet fs)
 {
     InitializeComponent();
     _featureSet = fs;
     foreach (DataColumn col in fs.GetColumns())
     {
         cbLocalField.Items.Add(col.ColumnName);
     }
 }
コード例 #6
0
        public static Boolean ExportToShapeUsingOgr(this IFeatureSet dataset, String outputShapefileName)
        {
            OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", "UTF-8");

            var outputFolder = Path.GetDirectoryName(outputShapefileName);

            if (File.Exists(outputShapefileName))
            {
                var exts = new List <String> {
                    ".dbf", ".shx", ".shp", ".prj"
                };
                foreach (var ext in exts)
                {
                    var fn = outputFolder + "\\" + Path.GetFileNameWithoutExtension(outputShapefileName) + ext;
                    if (File.Exists(fn))
                    {
                        File.Delete(fn);
                    }
                }
            }

            var drv = Ogr.GetDriverByName("ESRI Shapefile");

            if (drv == null)
            {
                return(false);
            }
            var ds = drv.CreateDataSource(Path.GetDirectoryName(outputShapefileName), null);

            if (ds == null)
            {
                return(false);
            }

            var fromSrs = new SpatialReference(null);

            fromSrs.ImportFromEPSG(32640);

            Utilities.LogDebug(Path.GetFileNameWithoutExtension(outputShapefileName));

            var lyr = ds.CreateLayer(Path.GetFileNameWithoutExtension(outputShapefileName), fromSrs, wkbGeometryType.wkbPolygon, null);
            var listOfFieldNames = new List <String>();
            var fieldMapping     = new Dictionary <string, string>();

            foreach (System.Data.DataColumn dc in dataset.GetColumns())
            {
                var dbfName = dc.ColumnName.Dbfify(listOfFieldNames);
                listOfFieldNames.Add(dbfName);
                fieldMapping.Add(dc.ColumnName, dbfName);
                lyr.CreateField(new FieldDefn(dbfName, dc.DataType.OgrType()), 0);
            }

            var wktWriter = new WktWriter();

            foreach (var currentFeature in dataset.Features)
            {
                var f = new OSGeo.OGR.Feature(lyr.GetLayerDefn());
                foreach (var dc2 in fieldMapping)
                {
                    var      srcGeom   = currentFeature.BasicGeometry as DotSpatial.Topology.Geometry;
                    var      wktGeom   = wktWriter.Write(srcGeom);
                    Geometry shapeGeom = Geometry.CreateFromWkt(wktGeom);
                    f.SetGeometry(shapeGeom);
                    var val = currentFeature.DataRow[dc2.Key];
                    f.SetField(dc2.Value, val.ToString());
                }
                var s = lyr.CreateFeature(f);
            }

            if (lyr == null)
            {
                return(false);
            }
            else
            {
                ds.ExecuteSQL("CREATE SPATIAL INDEX ON " + Path.GetFileNameWithoutExtension(outputShapefileName), null, "OGRSQL");
            }

            fromSrs.Dispose();
            lyr.Dispose();
            ds.Dispose();
            drv.Dispose();
            return(true);
        }
コード例 #7
0
        /// <summary>
        /// 20200308 fdragons
        /// 표준레이어 매핑(RadioButton) 선택시 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnRadioButtonClick(object sender, EventArgs e)
        {
            ///상수정의
            const int BaseIx       = 50;
            const int BaseIy       = 0;
            const int LblWidth     = 100;
            const int CbxWidth     = 120;
            const int ColumnHeight = 25;
            const int IncrementIy  = 30;
            const int MsgWidth     = 256;

            ///시작위치 지정
            int ix = BaseIx;
            int iy = BaseIy;

            ///이전 컨트롤 삭제
            this.gbOutputFields.Controls.Clear();
            this.panelFieldMapping.Controls.Clear();
            this.lstMappedCols.Items.Clear();

            ///매핑 패널 컨트롤 추가
            this.gbOutputFields.Controls.Add(this.panelFieldMapping);
            this.gbOutputFields.Controls.Add(this.lstMappedCols);

            ///선택한 표준레이어 정보 설정
            _currentLayerBtn = (RadioButtonAdv)sender;

            ///선택 레이어명 생성
            _mappingMsg          = new Label();
            _mappingMsg.Name     = "_mappingMsg";
            _mappingMsg.Location = new System.Drawing.Point(20, 20);
            _mappingMsg.Text     = (_currentLayerBtn.Text == "기타")
                ? $"*** [ {_currentLayerBtn.Text} ] 레이어는 속성 매핑을 수행하지 않습니다."
                : $"*** [ {_currentLayerBtn.Text} ] ***";
            _mappingMsg.ForeColor = Color.Black;
            _mappingMsg.Size      = new System.Drawing.Size(512, 25);
            this.gbOutputFields.Controls.Add(_mappingMsg);

            if (_currentLayerBtn.Text == "기타")
            {
                return;
            }

            ///WTL 레이어 선택
            _WTLLayer = _currentLayerBtn.Tag as Core.Models2.IWTL_Layer;
            IFeatureSet stdSet = MMaker.Core.AppStatic.d_Layers[_WTLLayer];

            ///WTL 레이어가 아니면 리턴
            if (stdSet == null)
            {
                return;
            }

            ///선택된 레이어의 컬럼 리스트를 조회(콤보박스의 아이템으로 사용)
            IFeatureSet orgSet = _orgData as IFeatureSet;

            _orgCols = orgSet.GetColumns();

            ///매핑용 필드 컨트롤 생성
            Label       lbl1, lbl2, lbl3;
            ComboBoxAdv cbx;

            _stdCols = stdSet.GetColumns();
            IEnumerable <string> stdColsDesc = _WTLLayer.ColumnsDesc();

            ///매핑 카운트를 초기화
            _mappingCnts   = 0;
            _stdColumnCnts = _stdCols.Length;

            for (int i = 0; i < _stdColumnCnts; i++)
            {
                ///컬럼명 생성
                lbl1 = new Label
                {
                    Name      = "lbl" + _stdCols[i].Caption,
                    Location  = new System.Drawing.Point(ix, iy),
                    Text      = _stdCols[i].Caption + " * ",
                    Size      = new System.Drawing.Size(LblWidth, ColumnHeight),
                    TextAlign = ContentAlignment.MiddleRight,
                };

                ///매핑아이템 생성
                cbx = new ComboBoxAdv
                {
                    Name          = "cbx" + _stdCols[i].Caption,
                    Location      = new System.Drawing.Point(ix + LblWidth, iy),
                    Text          = "",
                    Size          = new System.Drawing.Size(CbxWidth, ColumnHeight),
                    DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList,
                    AllowDrop     = true,
                    Tag           = $"{_stdCols[i].Caption}"
                };
                cbx.Items.Add("*None*");
                cbx.Items.AddRange(_orgCols);
                cbx.Click += (s, args) =>
                {
                    ComboBoxAdv c = s as ComboBoxAdv;
                    c.SelectedItem   = c.SelectedItem ?? "*None*";
                    _cbxPreviousvVal = c.SelectedItem.ToString();
                };
                cbx.SelectedIndexChanged += (s, args) =>
                {
                    ComboBoxAdv c            = s as ComboBoxAdv;
                    string      selectedItem = c.SelectedItem.ToString();

                    ///선택 속성이 이전과 동일한 경우 스킵한다.
                    if (selectedItem == _cbxPreviousvVal && !selectedItem.Equals("*None*"))
                    {
                        return;
                    }

                    ///기 선택(사용)된 속성이면 취소한다.
                    if (IsFieldUsedInlstMappedCols(2, selectedItem))
                    {
                        MessageBox.Show("이미 매핑된 속성 필드입니다.", base.MmakerShell.AppTitle);
                        c.SelectedItem = _cbxPreviousvVal;
                        return;
                    }

                    ///기 존재하면 삭제후 삽입
                    int j = 0;
                    for (; j < lstMappedCols.Items.Count; j++)
                    {
                        if (lstMappedCols.Items[j].ToString().Contains(c.Tag.ToString()))
                        {
                            lstMappedCols.Items.RemoveAt(j);
                            lstMappedCols.Items.Add($"{j + 1:D3}:(*)\t^{c.Tag.ToString()}^{selectedItem}^");
                            break;
                        }
                    }
                    if (j == lstMappedCols.Items.Count)
                    {
                        if (!IsFieldUsedInlstMappedCols(1, c.Tag.ToString()))
                        {
                            _mappingCnts++;
                        }

                        lstMappedCols.Items.Add($"{_mappingCnts:D3}:(*)\t^{c.Tag.ToString()}^{selectedItem}^");
                        DisplayMappingResults();
                    }

                    ///변경사항 유효성 검토
                    bool   b   = true;
                    string sz  = "Skip";
                    bool   ret = false;
                    try
                    {
                        if (!c.SelectedItem.Equals("*None*"))
                        {
                            ret = CheckValidation(c, j, out b, out sz);
                            sz  = $"return :{ret}, validate :{b.ToString()}, description :{sz}";
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    ///유효성 검증 결과 표시
                    string    lblName           = "vdt" + c.Tag.ToString();
                    Control[] _allLabelControls = panelFieldMapping.GetAllControls(typeof(Label));
                    Label     lbl = _allLabelControls.Where(x => x.Name == lblName).First() as Label;
                    lbl.ForeColor = (b) ? Color.Blue : Color.Red;
                    lbl.Text      = sz;

                    ///재정렬
                    SortMappedCols();
                };

                ///한글 컬럼명 라벨 생성
                lbl2 = new Label
                {
                    Name     = "dsc" + _stdCols[i].Caption,
                    Location = new System.Drawing.Point(ix + LblWidth + CbxWidth, iy),
                    Text     = $" * {_WTLLayer.ColumnsDesc().ElementAt(i)}",
                    Size     = new System.Drawing.Size(LblWidth, ColumnHeight)
                };

                ///유효성 결과 표시 라벨 생성
                lbl3 = new Label
                {
                    Name     = "vdt" + _stdCols[i].Caption,
                    Location = new System.Drawing.Point(ix + LblWidth + CbxWidth + LblWidth, iy),
                    Size     = new System.Drawing.Size(MsgWidth, ColumnHeight),
                    AutoSize = true,
                };

                if (!CheckValidation(cbx, i, out bool bValidate, out string szValidation))
                {
                    continue;
                }

                lbl3.ForeColor = (bValidate) ? Color.Blue : Color.Red;
                lbl3.Text      = szValidation;

                this.panelFieldMapping.Controls.Add(lbl1);  ///컬럼명 추가
                this.panelFieldMapping.Controls.Add(cbx);   ///매핑아이템 추가
                this.panelFieldMapping.Controls.Add(lbl2);  ///컬럼설명 추가
                this.panelFieldMapping.Controls.Add(lbl3);  ///유효성 검토결과

                ///표시위치 설정
                iy += IncrementIy;
            }

            ///매핑 결과 표시
            DisplayMappingResults();
        }