private void button3_Click(object sender, EventArgs e) { if (this.listBox1.Visible != true) { this.listBox1.Visible = true; } string sector = ""; //browse FolderBrowserDialogEx CostumFolderBrowserDialog = new FolderBrowserDialogEx(); string Titlu = "Alege Dosarul cu CGXML'uri"; CostumFolderBrowserDialog.Title = Titlu; CostumFolderBrowserDialog.StartPosition = FormStartPosition.CenterParent; DialogResult dr = CostumFolderBrowserDialog.ShowDialog(this); if (dr == DialogResult.OK) { CostumFolderBrowserDialogPath = CostumFolderBrowserDialog.SelectedPath; } string[] filez = Directory.GetFiles(CostumFolderBrowserDialogPath.ToString(), "*.cgxml", SearchOption.AllDirectories); NumericComparer ns = new NumericComparer(); System.Array.Sort(filez, ns); var files = filez.Select(x => new FileInfo(x)).ToArray(); //initial vars string futureFieldName = "ID"; string futureFieldAreaCG = "Sup Mas"; string futureFieldLegalCG = "Sup Acte"; string futurePerson = "Persoana"; int nrCGXML = 0; int intr = 0; for (int i = 0; i < (int)files.Length; i++) { nrCGXML++; } //Create a future list IList <Feature> futuresList = new List <Feature>(); //loop trough cgxml for (int i = 0; i < (int)files.Length; i++) { FileInfo fo = files[i]; CGXML fisier = new CGXML(); try { fisier.ReadXml(fo.FullName); } catch (Exception exception) { Exception ex = exception; MessageBox.Show(string.Concat(new string[] { "Eroare ", ex.GetType().ToString(), "\n", ex.Message, fo.FullName })); } //create geometry factory IGeometryFactory geomFactory = NtsGeometryServices.Instance.CreateGeometryFactory(); IGeometry[] gr = new IGeometry[nrCGXML]; foreach (CGXML.LandRow lr in fisier.Land) { var r = 0; string Person = ""; var q = 0; Coordinate[] myCoord = new Coordinate[fisier.Points.Count + 1]; string[] personArr = new string[fisier.Person.Count]; sector = lr.CADSECTOR.ToString(); foreach (CGXML.PointsRow pr in fisier.Points) { if (pr.IMMOVABLEID != 9898989) { myCoord[r++] = new Coordinate(pr.X, pr.Y); } } if (myCoord[r - 1] != myCoord[0]) { myCoord[r] = myCoord[0]; } foreach (CGXML.PersonRow pp in fisier.Person) { personArr[q++] = string.Concat(pp.FIRSTNAME, " ", pp.LASTNAME); } //create the default table with fields - alternately use DBaseField classes AttributesTable t = new AttributesTable(); t.AddAttribute(futureFieldName, lr.CADGENNO); t.AddAttribute(futureFieldAreaCG, lr.MEASUREDAREA); t.AddAttribute(futureFieldLegalCG, lr.PARCELLEGALAREA); t.AddAttribute(futurePerson, personArr[0]); //Geometry myCoord = myCoord.Where(c => c != null).ToArray(); gr[intr] = geomFactory.CreatePolygon(myCoord); futuresList.Add(new Feature(gr[intr], t)); intr++; } } //Feature list IList <Feature> features = futuresList.OfType <Feature>().ToList(); string shapefile = string.Concat(CostumFolderBrowserDialogPath, "\\", "Imobile ", sector); ShapefileDataWriter writer = new ShapefileDataWriter(shapefile) { Header = ShapefileDataWriter.GetHeader(features[0], features.Count) }; writer.Write(features); System.Diagnostics.Process.Start("explorer.exe", CostumFolderBrowserDialogPath); }
private void button1_Click(object sender, EventArgs e) { //initial vars string futureFieldSector = "Sector"; string futureFieldName = "ID"; string futureIE = "IE"; string futureFieldAreaCG = "Sup Mas"; string futureFieldLegalCG = "Sup Acte"; string futureFieldTitle = "Titlu"; string futureFieldTarla = "Tarla"; string futureFieldParcel = "Parcela"; string futurePerson = "Persoana"; string futureDead = "Decedat"; string futureIntravilan = "Intra"; string futureImprejmuit = "Ingradit"; int nrCGXML = 0; int intr = 0; //Create a future list IList <Feature> futuresList = new List <Feature>(); IList <Feature> CladirifuturesList = new List <Feature>(); //browse string filePath = textBox1.Text; string[] filez = Directory.GetFiles(filePath, "*.cgxml", SearchOption.AllDirectories); var files = filez.Select(x => new FileInfo(x)).ToArray(); for (int i = 0; i < (int)files.Length; i++) { nrCGXML++; } //loop trough cgxml for (int i = 0; i < (int)files.Length; i++) { FileInfo fo = files[i]; CGXML fisier = new CGXML(); try { fisier.ReadXml(fo.FullName); } catch (Exception exception) { Exception ex = exception; MessageBox.Show(string.Concat(new string[] { "Eroare ", ex.GetType().ToString(), "\n", ex.Message, fo.FullName })); } //create geometry factory GeometryFactory geomFactory = NtsGeometryServices.Instance.CreateGeometryFactory(); GeometryFactory fabricaGeometri = NtsGeometryServices.Instance.CreateGeometryFactory(); Geometry[] gr = new Geometry[nrCGXML]; List <Geometry> geometrieCladiri = new List <Geometry>(); Dictionary <int, List <Coordinate> > BCoordinates = new Dictionary <int, List <Coordinate> >(); foreach (CGXML.PointsRow pr in fisier.Points) { if (pr.BuildingRow == null) { continue; } if (!BCoordinates.ContainsKey(pr.BUILDINGID)) { BCoordinates.Add(pr.BUILDINGID, new List <Coordinate>()); } else { BCoordinates[pr.BUILDINGID].Add(new Coordinate(pr.X, pr.Y)); } } int indexCladire = 0; foreach (CGXML.LandRow lr in fisier.Land) { // List<Coordinate> bCoord = new List<Coordinate>(); foreach (CGXML.BuildingRow br in fisier.Building) { AttributesTable Btable = new AttributesTable(); Btable.Add(futureFieldSector, lr.CADSECTOR); Btable.Add(futureFieldName, lr.CADGENNO); Btable.Add("nrCladire", br.BUILDNO); Btable.Add("destCladire", br.BUILDINGDESTINATION); //Geometry //bCoord = bCoord.Where(c => c != null).ToArray(); if (BCoordinates[indexCladire + 1].First() != BCoordinates[indexCladire + 1].Last()) { BCoordinates[indexCladire + 1].Add(BCoordinates[indexCladire + 1].First()); } geometrieCladiri.Add(fabricaGeometri.CreatePolygon(BCoordinates[indexCladire + 1].ToArray())); //gr[indexCladire] = geomFactory.CreatePolygon( BCoordinates[indexCladire].ToArray()); CladirifuturesList.Add(new Feature(geometrieCladiri[indexCladire], Btable)); indexCladire++; } var r = 0; string Person = ""; var q = 0; int v = 0; string intratest = ""; string ie = lr.E2IDENTIFIER; string imprej = (lr.ENCLOSED ? "DA" : "NU").ToString(); int parcelCount = fisier.Parcel.Count; string[] titleNO = new string[parcelCount]; string[] landLotNO = new string[parcelCount]; string[] parcelNO = new string[parcelCount]; List <bool> intraNO = new List <bool>(); string intraString = ""; Coordinate[] myCoord = new Coordinate[fisier.Points.Count + 1]; string[] personArr = new string[fisier.Person.Count]; string[] deadPersonArr = new string[fisier.Person.Count]; string sector = lr.CADSECTOR.ToString(); foreach (CGXML.PointsRow pr in fisier.Points) { if (pr.IMMOVABLEID != 9898989) { myCoord[r++] = new Coordinate(pr.X, pr.Y); } } if (myCoord[r - 1] != myCoord[0]) { myCoord[r] = myCoord[0]; } foreach (CGXML.PersonRow pp in fisier.Person) { personArr[q] = string.Concat(pp.FIRSTNAME, " ", pp.LASTNAME); deadPersonArr[q] = (pp.DEFUNCT ? "DA" : "NU"); q++; } foreach (CGXML.ParcelRow pr in fisier.Parcel) { titleNO[v] = pr.TITLENO; landLotNO[v] = pr.LANDPLOTNO; parcelNO[v] = pr.PARCELNO; intraNO.Add(pr.INTRAVILAN); v++; } string[] titleNO2 = titleNO.Distinct().ToArray(); titleNO2 = titleNO2.Where(f => f != null).ToArray(); string[] landLotNO2 = landLotNO.Distinct().ToArray(); landLotNO2 = landLotNO2.Where(p => p != null).ToArray(); string[] parcelNo2 = parcelNO.Distinct().ToArray(); parcelNo2 = parcelNO.Where(l => l != null).ToArray(); string titleNO3 = string.Join(" , ", titleNO2); string landLotNO3 = string.Join(" , ", landLotNO2); string parcelNO3 = string.Join(" , ", parcelNo2); if (!intraNO.Contains(false) && intraNO.Contains(true)) { intraString = "Intra"; } else if (intraNO.Contains(false) && !intraNO.Contains(true)) { intraString = "Extra"; } else { intraString = "Mixt"; } string personTest = string.Join(" , ", personArr); string deadPesTest = string.Join(" , ", deadPersonArr); //create the default table with fields - alternately use DBaseField classes AttributesTable t = new AttributesTable(); t.Add(futureFieldSector, lr.CADSECTOR); t.Add(futureFieldName, lr.CADGENNO); t.Add(futureIE, lr.E2IDENTIFIER); t.Add(futureFieldAreaCG, lr.MEASUREDAREA); t.Add(futureFieldLegalCG, lr.PARCELLEGALAREA); t.Add(futurePerson, personTest); t.Add(futureDead, deadPesTest); t.Add(futureFieldTitle, titleNO3); t.Add(futureFieldTarla, landLotNO3); t.Add(futureFieldParcel, parcelNO3); t.Add(futureImprejmuit, imprej); t.Add(futureIntravilan, intraString); //Geometry myCoord = myCoord.Where(c => c != null).ToArray(); gr[intr] = geomFactory.CreatePolygon(myCoord); futuresList.Add(new Feature(gr[intr], t)); intr++; } indexCladire = 0; } //Feature list IList <Feature> features = futuresList.OfType <Feature>().ToList(); string shapefile = string.Concat(filePath, "\\", "Imobile"); ShapefileDataWriter writer = new ShapefileDataWriter(shapefile) { Header = ShapefileDataWriter.GetHeader(features[0], features.Count) }; writer.Write(features); //Cladiri Feature list IList <Feature> Cladirifeatures = CladirifuturesList.OfType <Feature>().ToList(); string Cladirishapefile = string.Concat(filePath, "\\", "Cladiri"); ShapefileDataWriter Cladiriwriter = new ShapefileDataWriter(shapefile) { Header = ShapefileDataWriter.GetHeader(Cladirifeatures[0], Cladirifeatures.Count) }; Cladiriwriter.Write(Cladirifeatures); }