public DialogResult ShowDialog(ref OverrideInformation enabledInformation) { if (enabledInformation.PointChecked) { this.checkPoint.Checked = false; this.checkPoint.Enabled = true; } else { this.checkPoint.Checked = true; this.checkPoint.Enabled = false; } if (enabledInformation.PolylineChecked) { this.checkPolyline.Checked = false; this.checkPolyline.Enabled = true; } else { this.checkPolyline.Checked = true; this.checkPolyline.Enabled = false; } if (enabledInformation.PolygonChecked) { this.checkPolygon.Checked = false; this.checkPolygon.Enabled = true; } else { this.checkPolygon.Checked = true; this.checkPolygon.Enabled = false; } return(base.ShowDialog()); }
public DialogResult ShowDialog(ref OverrideInformation enabledInformation) { if (enabledInformation.PointChecked) { this.checkPoint.Checked = false; this.checkPoint.Enabled = true; } else { this.checkPoint.Checked = true; this.checkPoint.Enabled = false; } if (enabledInformation.PolylineChecked) { this.checkPolyline.Checked = false; this.checkPolyline.Enabled = true; } else { this.checkPolyline.Checked = true; this.checkPolyline.Enabled = false; } if (enabledInformation.PolygonChecked) { this.checkPolygon.Checked = false; this.checkPolygon.Enabled = true; } else { this.checkPolygon.Checked = true; this.checkPolygon.Enabled = false; } return base.ShowDialog(); }
public OverrideInformation showOverrideDialog(OverrideInformation enabledInformation) { string tempName; if (overrideDialog == null) overrideDialog = new OverrideDialog(mainForm.VisibleDesktop, this); if (overrideDialog.ShowDialog(ref enabledInformation) == DialogResult.OK) { try { OverrideInformation overrideInfo = overrideDialog.WhatToOverride; if (overrideInfo.PointChecked) { tempName = Path.ChangeExtension(config.ExPntLayerFile, "shp"); if (File.Exists(tempName)) File.Delete(tempName); tempName = Path.ChangeExtension(tempName,"shx"); if (File.Exists(tempName)) File.Delete(tempName); tempName = Path.ChangeExtension(tempName, "dbf"); if (File.Exists(tempName)) File.Delete(tempName); } if (overrideInfo.PolylineChecked) { tempName = Path.ChangeExtension(config.ExPLineLayerFile, "shp"); if (File.Exists(tempName)) System.IO.File.Delete(tempName); tempName = Path.ChangeExtension(tempName, "shx"); if (File.Exists(tempName)) System.IO.File.Delete(tempName); tempName = Path.ChangeExtension(tempName, "dbf"); if (File.Exists(tempName)) System.IO.File.Delete(tempName); } if (overrideInfo.PolygonChecked) { tempName = Path.ChangeExtension(config.ExPGonLayerFile, "shp"); if (File.Exists(tempName)) System.IO.File.Delete(tempName); tempName = Path.ChangeExtension(tempName, "shx"); if (File.Exists(tempName)) System.IO.File.Delete(tempName); tempName = Path.ChangeExtension(tempName, "dbf"); if (File.Exists(tempName)) System.IO.File.Delete(tempName); } return overrideInfo; } catch (Exception) { MessageBox.Show("Fehler beim Überschreiben. - Vorgang abgebrochen!"); return new OverrideInformation(false, false, false, DialogResult.Abort); } } return new OverrideInformation(false, false, false, DialogResult.Cancel); }
public void saveTransPortLayers() { GravurGIS.GUI.Dialogs.OverrideInformation result = new GravurGIS.GUI.Dialogs.OverrideInformation( false, false, false, DialogResult.Cancel); // check if directories exist and create them if neccecary if (!Directory.Exists(Path.GetDirectoryName(Path.ChangeExtension(config.ExPntLayerFile, "shp")))) { Directory.CreateDirectory( Path.GetDirectoryName(Path.ChangeExtension(config.ExPntLayerFile, "shp"))); } if (!Directory.Exists(Path.GetDirectoryName(Path.ChangeExtension(config.ExPLineLayerFile, "shp")))) { Directory.CreateDirectory( Path.GetDirectoryName(Path.ChangeExtension(config.ExPLineLayerFile, "shp"))); } if (!Directory.Exists(Path.GetDirectoryName(Path.ChangeExtension(config.ExPGonLayerFile, "shp")))) { Directory.CreateDirectory( Path.GetDirectoryName(Path.ChangeExtension(config.ExPGonLayerFile, "shp"))); } // check if the files do already exist if (System.IO.File.Exists(Path.ChangeExtension(config.ExPntLayerFile, "shp"))) result.PointChecked = true; if (System.IO.File.Exists(Path.ChangeExtension(config.ExPLineLayerFile, "shp"))) result.PolylineChecked = true; if (System.IO.File.Exists(Path.ChangeExtension(config.ExPGonLayerFile, "shp"))) result.PolygonChecked = true; if (result.PointChecked || result.PolylineChecked || result.PolygonChecked) result = mainControler.showOverrideDialog(result); else result = new GravurGIS.GUI.Dialogs.OverrideInformation(true, true, true, DialogResult.OK); if (result.dialogResult == DialogResult.OK) { // overwrite all and everything :) // start with Points ShapeLib.ShapeType shpType; IntPtr hShp, hDbf; int nVertices, nShapes; double[] xCoord; double[] yCoord; string fileName; IntPtr pshpObj; PointD pnt; int iRet, iCommentField, iCategoryField, iIDField; StringBuilder saveString = new StringBuilder("") ; int maxCommentLength = 1; // find the longest category name int maxCatNameLength = 1; for (int i = 0; i < config.CategoryList.Count; i++) maxCatNameLength = Math.Max(maxCatNameLength, config.CategoryList[i].Length); if (result.PointChecked) { /////////////////// // Multipoint layer /////////////////// shpType = ShapeLib.ShapeType.MultiPoint; nShapes = transportPointLayer.Count; if (nShapes == 0) // actually we do not have any points createNullShape(config.ExPntLayerFile); else { ////////////////////////// // .shp & .shx & .dbf file ////////////////////////// // create a new shapefile hShp = ShapeLib.SHPCreateW(config.ExPntLayerFile, shpType); hDbf = ShapeLib.DBFCreateW(config.ExPntLayerFile); fileName = Path.GetFileNameWithoutExtension(config.ExPntLayerFile); if (hShp.Equals(IntPtr.Zero)) { MessageBox.Show("0x2001 - Fehler beim Schreiben der Punktlayer Datei!"); return; } if (hDbf.Equals(IntPtr.Zero)) { MessageBox.Show("0x2011 - Fehler beim Schreiben der Punktlayer dbf-Datei!"); return; } // find the maximum comment length for (int i = 0; i < nShapes; i++) maxCommentLength = Math.Max(maxCommentLength, transportPointLayer.getShape(i).Commment.Length); // create new ID Field iIDField = ShapeLib.DBFAddFieldW(hDbf, "ID", ShapeLib.DBFFieldType.FTInteger, 11, 0); // create new comment field - String, Max width: 30 iCommentField = ShapeLib.DBFAddFieldW(hDbf, config.ExPntLayerDBFCommentFieldName, ShapeLib.DBFFieldType.FTString, maxCommentLength, 0); // create new category field - String, Max width: 30 iCategoryField = ShapeLib.DBFAddFieldW(hDbf, "Category", ShapeLib.DBFFieldType.FTString, maxCatNameLength, 0); if (iCommentField == -1 || iCategoryField == -1 || iIDField == -1) { MessageBox.Show("0x2021 - Fehler beim Schreiben der DBF-Datei für Punktlayer!"); return; } // Generate point arrays xCoord = new double[1]; yCoord = new double[1]; int count = 0; for (int i = 0; i < nShapes; i++) { if (transportPointLayer.getShape(i).Visible) { count++; pnt = transportPointLayer.getPoint(i); xCoord[0] = pnt.x; yCoord[0] = -pnt.y; pshpObj = ShapeLib.SHPCreateSimpleObject(shpType, 1, xCoord, yCoord, new double[1]); iRet = ShapeLib.SHPWriteObject(hShp, -1, pshpObj); ShapeLib.SHPDestroyObject(pshpObj); // write out ID ShapeLib.DBFWriteIntegerAttribute(hDbf, iRet, iIDField, i); // write out comments if (String.IsNullOrEmpty(transportPointLayer.getComment(i))) ShapeLib.DBFWriteNULLAttribute(hDbf, iRet, iCommentField); else ShapeLib.DBFWriteStringAttributeW(hDbf, iRet, iCommentField, transportPointLayer.getComment(i)); // write out categories if (String.IsNullOrEmpty(transportPointLayer.getShape(i).Category)) ShapeLib.DBFWriteNULLAttribute(hDbf, iRet, iCategoryField); else ShapeLib.DBFWriteStringAttributeW(hDbf, iRet, iCategoryField, transportPointLayer.getShape(i).Category); } } ShapeLib.SHPClose(hShp); ShapeLib.DBFClose(hDbf); if (count == 0) createNullShape(Path.ChangeExtension(config.ExPntLayerFile, "shp")); } saveString.Append("Punkt-, "); } if (result.PolylineChecked) { ///////////////// // Polyline layer ///////////////// shpType = ShapeLib.ShapeType.PolyLine; nShapes = transportPolylineLayer.Count; if (nShapes == 0) // actually we do not have any points createNullShape(config.ExPLineLayerFile); else { hShp = ShapeLib.SHPCreateW(config.ExPLineLayerFile, shpType); hDbf = ShapeLib.DBFCreateW(config.ExPLineLayerFile); fileName = Path.GetFileNameWithoutExtension(config.ExPLineLayerFile); if (hShp.Equals(IntPtr.Zero)) { MessageBox.Show("0x2002 - Fehler beim Schreiben der Polyline Datei!"); return; } // find the maximum comment length for (int i = 0; i < nShapes; i++) maxCommentLength = Math.Max(maxCommentLength, transportPolylineLayer.getShape(i).Commment.Length); // create new ID Field iIDField = ShapeLib.DBFAddFieldW(hDbf, "ID", ShapeLib.DBFFieldType.FTInteger, 11, 0); // create comment field in the DBF iCommentField = ShapeLib.DBFAddFieldW(hDbf, config.ExPLineLayerDBFCommentFieldName, ShapeLib.DBFFieldType.FTString, maxCommentLength, 0); // create new category field - String, Max width: 30 iCategoryField = ShapeLib.DBFAddFieldW(hDbf, "Category", ShapeLib.DBFFieldType.FTString, maxCatNameLength, 0); if (iCommentField == -1 || iCategoryField == -1 || iIDField == -1) { MessageBox.Show("0x2021 - Fehler beim Schreiben der DBF-Datei für Punktlayer!"); return; } int count = 0; for (int i = 0; i < nShapes; i++) { if (transportPolylineLayer.getShape(i).Visible) { count++; xCoord = transportPolylineLayer.getXListOfPolyLine(i); yCoord = transportPolylineLayer.getYListOfPolyLine(i); nVertices = transportPolylineLayer.getVerticeCountOfPolyLine(i); pshpObj = ShapeLib.SHPCreateSimpleObject(shpType, nVertices, xCoord, yCoord, new double[nVertices]); iRet = ShapeLib.SHPWriteObject(hShp, -1, pshpObj); ShapeLib.SHPDestroyObject(pshpObj); // write out ID ShapeLib.DBFWriteIntegerAttribute(hDbf, iRet, iIDField, i); // write out comment if (transportPolylineLayer.getComment(i).Equals("")) ShapeLib.DBFWriteNULLAttribute(hDbf, iRet, iCommentField); else ShapeLib.DBFWriteStringAttributeW(hDbf, iRet, iCommentField, transportPolylineLayer.getComment(i)); // write out categories if (String.IsNullOrEmpty(transportPolylineLayer.getShape(i).Category)) ShapeLib.DBFWriteNULLAttribute(hDbf, iRet, iCategoryField); else ShapeLib.DBFWriteStringAttributeW(hDbf, iRet, iCategoryField, transportPolylineLayer.getShape(i).Category); } } ShapeLib.SHPClose(hShp); ShapeLib.DBFClose(hDbf); if (count == 0) createNullShape(config.ExPLineLayerFile); } saveString.Append("Linienzug-, "); } if (result.PolygonChecked) { ///////////////// // Polygon layer ///////////////// shpType = ShapeLib.ShapeType.Polygon; nShapes = transportPolygonLayer.Count; if (nShapes == 0) // actually we do not have any points createNullShape(config.ExPGonLayerFile); else { hShp = ShapeLib.SHPCreateW(config.ExPGonLayerFile, shpType); hDbf = ShapeLib.DBFCreateW(config.ExPGonLayerFile); fileName = Path.GetFileNameWithoutExtension(config.ExPGonLayerFile); if (hShp.Equals(IntPtr.Zero)) { MessageBox.Show("0x2003 - Fehler beim Schreiben der Polygon Datei!"); return; } if (hDbf.Equals(IntPtr.Zero)) { MessageBox.Show("0x2013 - Fehler beim Schreiben der Polygon dbf-Datei!"); return; } // find the maximum comment length for (int i = 0; i < nShapes; i++) maxCommentLength = Math.Max(maxCommentLength, transportPolygonLayer.getShape(i).Commment.Length); // create new ID Field iIDField = ShapeLib.DBFAddFieldW(hDbf, "ID", ShapeLib.DBFFieldType.FTInteger, 11, 0); // create a new field in the DBF iCommentField = ShapeLib.DBFAddFieldW(hDbf, config.ExPGonLayerDBFCommentFieldName, ShapeLib.DBFFieldType.FTString, maxCommentLength, 0); // create new category field - String, Max width: 30 iCategoryField = ShapeLib.DBFAddFieldW(hDbf, "Category", ShapeLib.DBFFieldType.FTString, maxCatNameLength, 0); if (iCommentField == -1 || iCategoryField == -1 || iIDField == -1) { MessageBox.Show("0x2021 - Fehler beim Schreiben der DBF-Datei für Punktlayer!"); return; } int count = 0; for (int i = 0; i < nShapes; i++) { if (transportPolygonLayer.getShape(i).Visible) { count++; xCoord = transportPolygonLayer.getXListOfPolygon(i); yCoord = transportPolygonLayer.getYListOfPolygon(i); nVertices = transportPolygonLayer.getVerticeCountOfPolygon(i); pshpObj = ShapeLib.SHPCreateSimpleObject(shpType, nVertices, xCoord, yCoord, new double[nVertices]); iRet = ShapeLib.SHPWriteObject(hShp, -1, pshpObj); // write out ID ShapeLib.DBFWriteIntegerAttribute(hDbf, iRet, iIDField, i); ShapeLib.SHPDestroyObject(pshpObj); if (transportPolygonLayer.getComment(i).Equals("")) ShapeLib.DBFWriteNULLAttribute(hDbf, iRet, iCommentField); else ShapeLib.DBFWriteStringAttributeW(hDbf, iRet, iCommentField, transportPolygonLayer.getComment(i)); // write out categories if (String.IsNullOrEmpty(transportPolygonLayer.getShape(i).Category)) ShapeLib.DBFWriteNULLAttribute(hDbf, iRet, iCategoryField); else ShapeLib.DBFWriteStringAttributeW(hDbf, iRet, iCategoryField, transportPolygonLayer.getShape(i).Category); } } ShapeLib.SHPClose(hShp); ShapeLib.DBFClose(hDbf); if (count == 0) createNullShape(config.ExPGonLayerFile); saveString.Append("Polygon-, "); } saveString.Append("Polygon-, "); } if (saveString.ToString().Equals("")) mainControler.setStatusTimed("Achtung: Es wurden keine Daten gespeichert!", 3000); else { saveString.Remove(saveString.Length - 2, 2); mainControler.setStatusTimed(saveString.ToString() + "Layer gespeichert!", 3000); } } else mainControler.setStatusTimed("Achtung: Es wurden keine Daten gespeichert!", 3000); }