public void WriteTest() { string File = @"..\..\..\TestData\WriteTest.Shp"; PointShapeWriter PSW = new PointShapeWriter(File); PSW.WritePointShape(10, 20); PSW.WritePointShape(20, 30); PSW.WritePointShape(30, 40); DataTable DT = new DataTable(); DT.Columns.Add("Name", typeof(string)); DT.Rows.Add(new object[]{"point1"}); DT.Rows.Add(new object[]{"point2"}); DT.Rows.Add(new object[]{"point3"}); PSW.Data.WriteDate(DT); PSW.Dispose(); PointShapeReader PSR = new PointShapeReader(File); double x; double y; DataTable DTread = PSR.Data.Read(); foreach (DataRow dr in DTread.Rows) { Console.WriteLine(dr[0].ToString()); PSR.ReadNext(out x, out y); Console.WriteLine(x.ToString() + " " + y.ToString()); } }
/// <summary> /// Opens a point shape /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { openFileDialog2.Filter = "Known file types (*.shp)|*.shp"; this.openFileDialog2.ShowReadOnly = true; this.openFileDialog2.Title = "Select a shape file with data for wells or intakes"; if (openFileDialog2.ShowDialog() == DialogResult.OK) { string FileName = openFileDialog2.FileName; PointShapeReader SR = new PointShapeReader(FileName); DataTable FullDataSet = SR.Data.Read(); //Launch a data selector DataSelector DS = new DataSelector(FullDataSet); if (DS.ShowDialog() == DialogResult.OK) { if (ShpConfig == null) { XmlSerializer x = new XmlSerializer(typeof(ShapeReaderConfiguration)); string InstallationPath = Path.GetDirectoryName(this.GetType().Assembly.Location); string config = Path.Combine(InstallationPath, "ShapeReaderConfig.xml"); using (FileStream fs = new FileStream(config, FileMode.Open)) { ShpConfig = (ShapeReaderConfiguration)x.Deserialize(fs); if (CheckColumn(FullDataSet, ShpConfig.WellIDHeader, config)) if (CheckColumn(FullDataSet, ShpConfig.IntakeNumber, config)) if (CheckColumn(FullDataSet, ShpConfig.XHeader, config)) if (CheckColumn(FullDataSet, ShpConfig.YHeader, config)) if (CheckColumn(FullDataSet, ShpConfig.TOPHeader, config)) if (CheckColumn(FullDataSet, ShpConfig.BOTTOMHeader, config)) { Wells = new Dictionary<string, IWell>(); if (FullDataSet.Columns.Contains(ShpConfig.PlantIDHeader)) { DPlants = new Dictionary<int, Plant>(); HeadObservations.FillInFromNovanaShape(DS.SelectedRows, ShpConfig, Wells, DPlants); } else HeadObservations.FillInFromNovanaShape(DS.SelectedRows, ShpConfig, Wells); UpdateListsAndListboxes(); } } } } SR.Dispose(); } }
public void ReadWellsFromShape() { PointShapeReader SR = new PointShapeReader(_config.WellShapeFile); DataTable _wellData = SR.Data.Read(); SR.Dispose(); foreach (DataRow dr in _wellData.Rows) { IrrigationWell IW = new IrrigationWell(dr[_config.IdHeader].ToString()); IW.X = Convert.ToDouble(dr[_config.XHeader]); IW.Y = Convert.ToDouble(dr[_config.YHeader]); IIntake I = IW.AddNewIntake(1); IW.MaxDepth = Convert.ToDouble(dr[_config.MaxDepthHeader]); IW.MaxRate = Convert.ToDouble(dr[_config.MaxRateHeader]); Screen CurrentScreen = new Screen(I); CurrentScreen.DepthToBottom = Convert.ToDouble(dr[_config.BottomHeader]); CurrentScreen.DepthToTop = Convert.ToDouble(dr[_config.TopHeader]); _wells.Add(IW); } _wellData.Dispose(); }
public void ReadInFromShapeTest() { PointShapeReader PSr = new PointShapeReader(@"..\..\..\TestData\AlbertslundExtraction.shp"); DataTable DTWells = PSr.Data.Read(); PSr.Dispose(); PSr = new PointShapeReader(@"..\..\..\TestData\AlbertslundObservation.shp"); DataTable DTWellsObs = PSr.Data.Read(); PSr.Dispose(); ShapeReaderConfiguration SRC2; XmlSerializer x = new XmlSerializer(typeof(ShapeReaderConfiguration)); using (FileStream fs = new FileStream(@"..\..\..\ThirdpartyBinaries\ShapeReaderConfig.xml", FileMode.Open)) { SRC2 = (ShapeReaderConfiguration)x.Deserialize(fs); } Dictionary<string, IWell> Wells1 = new Dictionary<string, IWell>(); HeadObservations.FillInFromNovanaShape(DTWells.Select(""), SRC2, Wells1); Assert.AreEqual(242, Wells1.Count()); Dictionary<string, IWell> Wells3 = new Dictionary<string, IWell>(); HeadObservations.FillInFromNovanaShape(DTWellsObs.Select(""), SRC2, Wells3); Assert.AreEqual(308, Wells3.Count()); SRC2.FraAArHeader="DUMMY"; Dictionary<string, IWell> Wells2 = new Dictionary<string, IWell>(); HeadObservations.FillInFromNovanaShape(DTWells.Select(""), SRC2, Wells2); }