private void CreateGridCellMatrix() { //Get the current extent since we use that to gerenate the grid. Of course this is just for //the demo and in the real world you can use any extent you like RectangleShape currentDrawingExtent = ExtentHelper.GetDrawingExtent(Map1.CurrentExtent, (float)Map1.ActualWidth, (float)Map1.ActualHeight); //Calculate the cell size based on how many rows and columns you specified double cellSize = Math.Min(currentDrawingExtent.Width / double.Parse(txtGridIsoLineCellColumnCount.Text), currentDrawingExtent.Height / Int32.Parse(txtGridIsoLineCellRowCount.Text)); //Greate the grid definition based on the extent, cell size etc. GridDefinition gridDefinition = new GridDefinition(currentDrawingExtent, cellSize, -9999, wellDepthPointData); //Generate the grid based on Inverse Distance Weighted interpolation model. You can define your own model if needed. gridCellMatrix = GridFeatureSource.GenerateGridMatrix(gridDefinition, new InverseDistanceWeightedGridInterpolationModel(2, double.MaxValue)); }
protected override void DrawCore(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers) { double resolution = GetResolutionFromScale(canvas.CurrentScale, canvas.MapUnit); double cellSize = Math.Min(cellHeightInPixel * resolution, cellWidthInPixel * resolution); GridDefinition gridDefinition = new GridDefinition(canvas.CurrentWorldExtent, cellSize, NoDataValue, wellDepthPoints); GridCell[,] gridMatrix = GridFeatureSource.GenerateGridMatrix(gridDefinition, InterpolationModel); this.GridMatrix = gridMatrix; this.FeatureSource.Close(); this.FeatureSource.Open(); base.DrawCore(canvas, labelsInAllLayers); }
private void mapView_Loaded(object sender, RoutedEventArgs e) { //Load the well depth points and depth data from a text file into the dictionary //We cache this at the class level to prevent form loading it multiple times string wellDepthPointDataFilePath = SampleHelper.Get("GrayCountyIrrigationWellDepths.csv"); Dictionary <PointShape, double> wellDepthPointData = GetWellDepthPointDataFromCSV(wellDepthPointDataFilePath); //Get the current extent since we use that to gerenate the grid. Of course this is just for //the demo and in the real world you can use any extent you like RectangleShape currentDrawingExtent = MapUtil.GetDrawingExtent(mapView.CurrentExtent, (float)mapView.ActualWidth, (float)mapView.ActualHeight); //Calculate the cell size based on how many rows and columns you specified double cellSize = Math.Min(currentDrawingExtent.Width / 4, currentDrawingExtent.Height / 4); //Greate the grid definition based on the extent, cell size etc. GridDefinition gridDefinition = new GridDefinition(currentDrawingExtent, cellSize, -9999, wellDepthPointData); //Generate the grid based on Inverse Distance Weighted interpolation model. You can define your own model if needed. GridCell[,] gridCellMatrix = GridFeatureSource.GenerateGridMatrix(gridDefinition, new InverseDistanceWeightedGridInterpolationModel(2, double.MaxValue)); //Load a new GridFeatureLayer based on the current grid file InMemoryGridFeatureLayer gridFeatureLayer = new InMemoryGridFeatureLayer(gridCellMatrix); gridFeatureLayer.Open(); var currentExtent = gridFeatureLayer.GetBoundingBox(); gridFeatureLayer.Close(); gridFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColors.Transparent, GeoColors.Black); gridFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //Add the grid layer, the grid cells, and the well points to the map LayerOverlay layerOverlay = new LayerOverlay(); layerOverlay.Layers.Add(gridFeatureLayer); mapView.ZoomLevelSet = new ThinkGeoCloudMapsZoomLevelSet(); mapView.CurrentExtent = currentExtent; mapView.MapUnit = GeographyUnit.Meter; mapView.Overlays.Add(layerOverlay); mapView.Refresh(); }
private void GenerateGrid(string filename) { //Point based shapefile used to create the GRID (sample points of pH level of a field) ShapeFileFeatureLayer pointLayer = new ShapeFileFeatureLayer(@"..\..\data\sample_ph_2.shp"); //Sets the extent of the grid based on the extent of the sample points shapefile and slightly larger. pointLayer.Open(); RectangleShape gridExtent = pointLayer.GetBoundingBox(); gridExtent.ScaleUp(5); //Gets the data (points with their pH value) to build the GRID. Collection <Feature> features = pointLayer.FeatureSource.GetAllFeatures(new string[] { "PH" }); Dictionary <PointShape, double> dataPoints = new Dictionary <PointShape, double>(); pointLayer.Close(); foreach (Feature feature in features) { PointShape pointShape = (PointShape)feature.GetShape(); double value = double.Parse(feature.ColumnValues["PH"]); dataPoints.Add(pointShape, value); } //Cell size based on the width of the extent divided by 100. double cellSize = gridExtent.Width / 100; //Sets the definition of the GRID with its extent, the cell size, the non value, and the data (point locations with their value) //For more information on GRID definition see http://en.wikipedia.org/wiki/ASCII_GRID GridDefinition definition = new GridDefinition(gridExtent, cellSize, -9999, dataPoints); //Inverse Distance Weighted (IDW) is the interpolation model used for the GRID for assigning values to unknown points //based on known neighbor points. //http://en.wikipedia.org/wiki/Inverse_distance_weighting GridInterpolationModel interpolationModel = new InverseDistanceWeightedGridInterpolationModel(); FileStream outputStream = new FileStream(filename, FileMode.Create); GridFeatureSource.GenerateGrid(definition, interpolationModel, outputStream); }