public object[] LoadShapeFile() { //Create the dialog allowing the user to select the "*.shp" and the "*.dbf" files Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.Filter = "ESRI Shapefiles (*.shp)|*.shp"; //ofd.Multiselect = true; if (ofd.ShowDialog().Value) { //Get the file info objects for the SHP and the DBF file selected by the user FileInfo shapeFile = new FileInfo(ofd.FileName); FileInfo dbfFile = new FileInfo(ofd.FileName.ToLower().Replace(".shp", ".dbf")); if (!dbfFile.Exists) { System.Windows.MessageBox.Show("Associated DBF file not found"); return null; } foreach (string fname in ofd.FileNames) { FileInfo fi = new FileInfo(fname); if (fi.Extension.ToLower() == ".shp") { shapeFile = fi; } if (fi.Extension.ToLower() == ".dbf") { dbfFile = fi; } } //Read the SHP and DBF files into the ShapeFileReader ShapeFileReader.ShapeFile shapeFileReader = new ShapeFileReader.ShapeFile(); if (shapeFile != null && dbfFile != null) { shapeFileReader.Read(shapeFile, dbfFile); } else { System.Windows.MessageBox.Show("Please select a SP and a DBF file to proceed."); return null; } GraphicsLayer graphicsLayer = myMap.Layers[layerId.ToString()] as GraphicsLayer; if (graphicsLayer == null) { graphicsLayer = new GraphicsLayer(); graphicsLayer.ID = layerId.ToString(); myMap.Layers.Add(graphicsLayer); } int recCount = shapeFileReader.Records.Count; int rgbFactor = 255 / recCount; int counter = 0; //int minPoints = shapeFileReader.Records.Min(record => record.NumberOfPoints); //double meanPoints = shapeFileReader.Records.Average(record => record.NumberOfPoints); foreach (ShapeFileReader.ShapeFileRecord record in shapeFileReader.Records) { Graphic graphic = record.ToGraphic(); if (graphic != null) { graphic.Symbol = GetFillSymbol(new SolidColorBrush(Color.FromArgb(240, 255, 255, 255))); graphicsLayer.Graphics.Add(graphic); } counter += rgbFactor; } Envelope shapeFileExtent = shapeFileReader.GetExtent(); if (shapeFileExtent.SpatialReference == null) { myMap.Extent = shapeFileExtent; } else { if (shapeFileExtent.SpatialReference.WKID == 4326) { myMap.Extent = new Envelope(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMin, shapeFileExtent.YMin)), ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMax, shapeFileExtent.YMax))); } } graphicsLayer.RenderingMode = GraphicsLayerRenderingMode.Static; return new object[] { ofd.FileName, graphicsLayer.Graphics[0].Attributes }; } else return null; }
//private void ColorBlendCombo_SelectionChanged(object sender, SelectionChangedEventArgs e) //{ //if (ColorBlendCombo != null) //{ // _colorShadeIndex = ColorBlendCombo.SelectedIndex; // if (loadedData != null) // { // SetShapeRangeValues(); // } //} //} //private void ClassCountCombo_SelectionChanged(object sender, SelectionChangedEventArgs e) //{ //if (ClassCountCombo != null) //{ // ComboBoxItem item = ClassCountCombo.SelectedItem as ComboBoxItem; // _classCount = Convert.ToInt32(item.Content); // if (loadedData != null) // { // SetShapeRangeValues(); // } //} //} public object[] LoadShapeFile(string fileName) { if (!string.IsNullOrEmpty(fileName)) { //Get the file info objects for the SHP and the DBF file selected by the user FileInfo shapeFile = new FileInfo(fileName); FileInfo dbfFile = new FileInfo(fileName.ToLower().Replace(".shp", ".dbf")); if (!dbfFile.Exists) { System.Windows.MessageBox.Show("Associated DBF file not found"); return null; } //Read the SHP and DBF files into the ShapeFileReader ShapeFileReader.ShapeFile shapeFileReader = new ShapeFileReader.ShapeFile(); if (shapeFile != null && dbfFile != null) { shapeFileReader.Read(shapeFile, dbfFile); } else { System.Windows.MessageBox.Show("Please select a SP and a DBF file to proceed."); return null; } GraphicsLayer graphicsLayer = myMap.Layers[layerId.ToString()] as GraphicsLayer; if (graphicsLayer == null) { graphicsLayer = new GraphicsLayer(); graphicsLayer.ID = layerId.ToString(); myMap.Layers.Add(graphicsLayer); } int recCount = shapeFileReader.Records.Count; int rgbFactor = 255 / recCount; int counter = 0; foreach (ShapeFileReader.ShapeFileRecord record in shapeFileReader.Records) { Graphic graphic = record.ToGraphic(); if (graphic != null) { graphic.Symbol = GetFillSymbol(new SolidColorBrush(Color.FromArgb(240, 255, 255, 255))); graphicsLayer.Graphics.Add(graphic); } counter += rgbFactor; } if (graphicsLayer.FullExtent == null) { Envelope shapeFileExtent = shapeFileReader.GetExtent(); if (shapeFileExtent.SpatialReference == null) { myMap.Extent = shapeFileExtent; } else { if (shapeFileExtent.SpatialReference.WKID == 4326) { myMap.Extent = new Envelope(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMin, shapeFileExtent.YMin)), ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMax, shapeFileExtent.YMax))); } } } else { myMap.Extent = graphicsLayer.FullExtent; } graphicsLayer.RenderingMode = GraphicsLayerRenderingMode.Static; return new object[] { fileName, graphicsLayer.Graphics[0].Attributes }; } else return null; }
override public object[] Load(string boundrySourceLocation) { if (!string.IsNullOrEmpty(boundrySourceLocation)) { FileInfo shapeFile = new FileInfo(boundrySourceLocation); string directoryName = System.IO.Path.GetDirectoryName(boundrySourceLocation); string dbfFilename = System.IO.Path.GetFileName(boundrySourceLocation).ToLowerInvariant().Replace(".shp", ".dbf"); string dbfFullPath = System.IO.Path.Combine(directoryName, dbfFilename); FileInfo dbfFile = new FileInfo(dbfFullPath); if (!dbfFile.Exists) { System.Windows.MessageBox.Show("Associated DBF file not found"); return(null); } ShapeFileReader.ShapeFile shapeFileReader = new ShapeFileReader.ShapeFile(); if (shapeFile != null && dbfFile != null) { try { shapeFileReader.Read(shapeFile, dbfFile); } catch (NotSupportedException e) { System.Windows.MessageBox.Show(e.Message); return(null); } catch { System.Windows.MessageBox.Show(DashboardSharedStrings.DASHBOARD_MAP_N_POLYGONS_EXCEEDED); return(null); } } else { System.Windows.MessageBox.Show("Please select a SP and a DBF file to proceed."); return(null); } GraphicsLayer graphicsLayer = GetGraphicsLayer(); if (graphicsLayer == null) { graphicsLayer = new GraphicsLayer(); graphicsLayer.ID = LayerId.ToString(); ArcGIS_Map.Layers.Add(graphicsLayer); int recCount = shapeFileReader.Records.Count; int rgbFactor = 255 / recCount; int counter = 0; foreach (ShapeFileReader.ShapeFileRecord record in shapeFileReader.Records) { Graphic graphic = record.ToGraphic(); if (graphic != null) { graphic.Symbol = GetFillSymbol(new SolidColorBrush(Color.FromArgb(240, 255, 255, 255))); graphicsLayer.Graphics.Add(graphic); } counter += rgbFactor; } } if (graphicsLayer.FullExtent == null) { Envelope shapeFileExtent = shapeFileReader.GetExtent(); if (shapeFileExtent.SpatialReference == null) { ArcGIS_Map.Extent = shapeFileExtent; } else { if (shapeFileExtent.SpatialReference.WKID == 4326) { ArcGIS_Map.Extent = new Envelope( ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMin, shapeFileExtent.YMin)), ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMax, shapeFileExtent.YMax))); } } } else { ArcGIS_Map.Extent = graphicsLayer.FullExtent; } graphicsLayer.RenderingMode = GraphicsLayerRenderingMode.Static; return(new object[] { boundrySourceLocation, graphicsLayer.Graphics[0].Attributes }); } else { return(null); } }
public void RenderShape(string fileName) { this.fileName = fileName; GraphicsLayer shapeLayer = myMap.Layers[layerId.ToString()] as GraphicsLayer; if (shapeLayer != null) { myMap.Layers.Remove(shapeLayer); } shapeLayer = new GraphicsLayer(); shapeLayer.ID = layerId.ToString(); myMap.Layers.Add(shapeLayer); //Get the file info objects for the SHP and the DBF file selected by the user FileInfo shapeFile = new FileInfo(fileName); string directoryName = Path.GetDirectoryName(fileName); string dbfFilename = Path.GetFileName(fileName).ToLowerInvariant().Replace(".shp", ".dbf"); string dbfFullPath = Path.Combine(directoryName, dbfFilename); FileInfo dbfFile = new FileInfo(dbfFullPath); if (!dbfFile.Exists) { System.Windows.MessageBox.Show("Associated DBF file not found"); return; } //Read the SHP and DBF files into the ShapeFileReader ShapeFileReader.ShapeFile shapeFileReader = new ShapeFileReader.ShapeFile(); if (shapeFile != null && dbfFile != null) { try { shapeFileReader.Read(shapeFile, dbfFile); } catch (NotSupportedException e) { System.Windows.MessageBox.Show(e.Message); return; } catch { System.Windows.MessageBox.Show(DashboardSharedStrings.DASHBOARD_MAP_N_POLYGONS_EXCEEDED); return; } } else { System.Windows.MessageBox.Show("Associated DBF file not found"); return; } int recCount = shapeFileReader.Records.Count; int rgbFactor = 255 / recCount; int counter = 0; foreach (ShapeFileReader.ShapeFileRecord record in shapeFileReader.Records) { Graphic graphic = record.ToGraphic(); if (graphic != null) { graphic.Symbol = GetFillSymbol(new SolidColorBrush(Color.FromArgb(192, 255, 255, 255))); shapeLayer.Graphics.Add(graphic); } counter += rgbFactor; } Envelope shapeFileExtent = shapeFileReader.GetExtent(); if (shapeFileExtent.SpatialReference == null) { myMap.Extent = shapeFileExtent; } else { if (shapeFileExtent.SpatialReference.WKID == 4326) { myMap.Extent = new Envelope(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMin, shapeFileExtent.YMin)), ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMax, shapeFileExtent.YMax))); } } }
public void RenderShape(string fileName) { this.fileName = fileName; GraphicsLayer shapeLayer = myMap.Layers[layerId.ToString()] as GraphicsLayer; if (shapeLayer != null) { myMap.Layers.Remove(shapeLayer); } shapeLayer = new GraphicsLayer(); shapeLayer.ID = layerId.ToString(); myMap.Layers.Add(shapeLayer); //Get the file info objects for the SHP and the DBF file selected by the user FileInfo shapeFile = new FileInfo(fileName); FileInfo dbfFile = new FileInfo(fileName.ToLower().Replace(".shp", ".dbf")); if (!dbfFile.Exists) { System.Windows.MessageBox.Show("Associated DBF file not found"); return; } //Read the SHP and DBF files into the ShapeFileReader ShapeFileReader.ShapeFile shapeFileReader = new ShapeFileReader.ShapeFile(); if (shapeFile != null && dbfFile != null) { shapeFileReader.Read(shapeFile, dbfFile); } else { System.Windows.MessageBox.Show("Associated DBF file not found"); return; } int recCount = shapeFileReader.Records.Count; int rgbFactor = 255 / recCount; int counter = 0; foreach (ShapeFileReader.ShapeFileRecord record in shapeFileReader.Records) { Graphic graphic = record.ToGraphic(); if (graphic != null) { graphic.Symbol = GetFillSymbol(new SolidColorBrush(Color.FromArgb(192, 255, 255, 255))); shapeLayer.Graphics.Add(graphic); } counter += rgbFactor; } Envelope shapeFileExtent = shapeFileReader.GetExtent(); if (shapeFileExtent.SpatialReference == null) { myMap.Extent = shapeFileExtent; } else { if (shapeFileExtent.SpatialReference.WKID == 4326) { myMap.Extent = new Envelope(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMin, shapeFileExtent.YMin)), ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMax, shapeFileExtent.YMax))); } } }
public object[] LoadShapeFile() { //Create the dialog allowing the user to select the "*.shp" and the "*.dbf" files Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.Filter = "ESRI Shapefiles (*.shp)|*.shp"; //ofd.Multiselect = true; if (ofd.ShowDialog().Value) { //Get the file info objects for the SHP and the DBF file selected by the user FileInfo shapeFile = new FileInfo(ofd.FileName); string directoryName = System.IO.Path.GetDirectoryName(ofd.FileName); string dbfFilename = System.IO.Path.GetFileName(ofd.FileName).ToLowerInvariant().Replace(".shp", ".dbf"); string dbfFullPath = System.IO.Path.Combine(directoryName, dbfFilename); FileInfo dbfFile = new FileInfo(dbfFullPath); if (!dbfFile.Exists) { System.Windows.MessageBox.Show("Associated DBF file not found"); return(null); } foreach (string fname in ofd.FileNames) { FileInfo fi = new FileInfo(fname); if (fi.Extension.ToLowerInvariant() == ".shp") { shapeFile = fi; } if (fi.Extension.ToLowerInvariant() == ".dbf") { dbfFile = fi; } } //Read the SHP and DBF files into the ShapeFileReader ShapeFileReader.ShapeFile shapeFileReader = new ShapeFileReader.ShapeFile(); if (shapeFile != null && dbfFile != null) { try { shapeFileReader.Read(shapeFile, dbfFile); } catch (NotSupportedException e) { System.Windows.MessageBox.Show(e.Message); return(null); } catch { System.Windows.MessageBox.Show(DashboardSharedStrings.DASHBOARD_MAP_N_POLYGONS_EXCEEDED); return(null); } } else { System.Windows.MessageBox.Show("Please select a SP and a DBF file to proceed."); return(null); } GraphicsLayer graphicsLayer = myMap.Layers[layerId.ToString()] as GraphicsLayer; if (graphicsLayer == null) { graphicsLayer = new GraphicsLayer(); graphicsLayer.ID = layerId.ToString(); myMap.Layers.Add(graphicsLayer); } int recCount = shapeFileReader.Records.Count; int rgbFactor = 255 / recCount; int counter = 0; foreach (ShapeFileReader.ShapeFileRecord record in shapeFileReader.Records) { Graphic graphic = record.ToGraphic(); if (graphic != null) { graphic.Symbol = GetFillSymbol(new SolidColorBrush(Color.FromArgb(192, 255, 255, 255))); graphicsLayer.Graphics.Add(graphic); } counter += rgbFactor; } Envelope shapeFileExtent = shapeFileReader.GetExtent(); if (shapeFileExtent.SpatialReference == null) { myMap.Extent = shapeFileExtent; } else { if (shapeFileExtent.SpatialReference.WKID == 4326) { myMap.Extent = new Envelope(ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMin, shapeFileExtent.YMin)), ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(new MapPoint(shapeFileExtent.XMax, shapeFileExtent.YMax))); } } return(new object[] { ofd.FileName, graphicsLayer.Graphics[0].Attributes }); } else { return(null); } }