//Execute private void button2_Click(object sender, EventArgs e) { string OutputString = this.textBox1.Text.Trim(); string InputString = this.comboBox1.Text.Trim(); //The input is null if ((InputString == "") || (OutputString == "")) { MessageBox.Show("The parameters are not complete.", "Admin", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (File.Exists(OutputString)) { MessageBox.Show("The output file has existed.", "Admin", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int selectIndex = this.comboBox1.SelectedIndex; if ((selectIndex < 0) && (InputString != "")) //Input data by selecting from folder { RasterSymbolizer RasterSymbol = new RasterSymbolizer(); IRasterSymbolizer IRasterSymbol = RasterSymbol; MapRasterLayer RasterLayer = new MapRasterLayer(InputString, RasterSymbol); //Open the raster layer IRaster Raster = RasterLayer.DataSet; } else if (selectIndex >= 0) //Input data by selecting from combox { IMapRasterLayer[] RasterArr = MainMap.GetRasterLayers(); IMapRasterLayer RasterLayer = RasterArr[selectIndex]; IRaster Raster = RasterLayer.DataSet; } }
private static Layer GetGridLayer(dynamic layer) { var symbolizer = new RasterSymbolizer(); Layer mapLayer = new MapRasterLayer(layer["Path"], symbolizer); // DeserializeLayer not implemented. return(mapLayer); }
private RasterSymbolizer MakeSnowSymbolizer() { RasterSymbolizer sym = new RasterSymbolizer(); ColorScheme scheme = new ColorScheme(); ColorCategory c1 = new ColorCategory(1, 100, Color.LightBlue, Color.LightBlue); c1.LegendText = "0 - 100"; scheme.AddCategory(c1); ColorCategory c2 = new ColorCategory(100, 10000, Color.DarkBlue, Color.DarkBlue); c2.LegendText = "> 100"; scheme.AddCategory(c2); sym.Scheme = scheme; return(sym); }
/// <summary> /// Creates a new instance of a Raster layer, and will create a "FallLeaves" image based on the /// raster values. /// </summary> /// <param name="raster">The raster to use</param> public MapRasterLayer(IRaster raster) : base(raster) { base.LegendText = Path.GetFileNameWithoutExtension(raster.Filename); // string imageFile = Path.ChangeExtension(raster.Filename, ".png"); // if (File.Exists(imageFile)) File.Delete(imageFile); IRasterSymbolizer rs = new RasterSymbolizer { Raster = raster }; if (raster.NumRows * raster.NumColumns > 8000 * 8000) { // For huge images, assume that GDAL or something was needed anyway, // and we would rather avoid having to re-create the pyramids if there is any chance // that the old values will work ok. string pyrFile = Path.ChangeExtension(raster.Filename, ".mwi"); if (File.Exists(pyrFile) && File.Exists(Path.ChangeExtension(pyrFile, ".mwh"))) { BitmapGetter = new PyramidImage(pyrFile); base.LegendText = Path.GetFileNameWithoutExtension(raster.Filename); } else { BitmapGetter = CreatePyramidImage(pyrFile, DataManager.DefaultDataManager.ProgressHandler); } } else { // Ensure smaller images match the scheme. rs.Scheme.ApplyScheme(ColorSchemeType.FallLeaves, raster); Bitmap bmp = new Bitmap(raster.NumColumns, raster.NumRows); raster.PaintColorSchemeToBitmap(rs, bmp, raster.ProgressHandler); InRamImage id = new InRamImage(bmp); id.Bounds.AffineCoefficients = raster.Bounds.AffineCoefficients; BitmapGetter = id; } }
private void btnInternet_Click(object sender, EventArgs e) { bool masked = true; lblProgress.Text = "Downloading snow data..."; DataFetcher fetcher = new DataFetcher(); string snowDataFile = null; DateTime selectedDate = dtpTime.Value; try { snowDataFile = fetcher.FetchSnow(selectedDate, masked); lblProgress.Text = "Snow data downloaded: " + snowDataFile; } catch (System.Net.WebException ex) { MessageBox.Show(ex.Message); return; } lblProgress.Text = "Reading binary grid.."; string snowBgdFile = snowDataFile.Replace(".dat", ".bgd"); IRaster snowRaster = fetcher.MakeSnowRaster(snowDataFile, snowBgdFile); lblProgress.Text = "Created snow raster: " + snowBgdFile; //finally, we add the snow raster to our map with proper color scheme RasterSymbolizer sym = MakeSnowSymbolizer(); MapRasterLayer snowLayer = new MapRasterLayer(snowRaster); snowLayer.Symbolizer = sym; MainMap.Layers.Add(snowLayer); snowLayer.WriteBitmap(); //set the date label on main map and close the form DateLabel.Text = "SWE (mm) " + selectedDate.Date.ToString(); this.Close(); }
private RasterSymbolizer CreateRasterSymbolizer(NodePropertyValue[] properties) { RasterSymbolizer symRaster = new RasterSymbolizer(); NodePropertyValue pv = null; try { int nProps = properties.Length; for (int i = 0; i < nProps; i++) { pv = properties[i]; switch (pv.Name) { case "raster-opacity": symRaster.Opacity = Convert.ToSingle(pv.Value); break; case "raster-filter-factor": UnsupportedProperty(pv); break; case "raster-scaling": symRaster.InterpolationMode = ToImageResamplingMode(pv.Value); break; case "raster-mesh-size": UnsupportedProperty(pv); break; case "raster-comp-op": symRaster.CompositingMode = ToCompositingMode(pv.Value); break; case "raster-colorizer-default-mode": symRaster.ColorMap.DefaultMode = ToColorMapMode(pv.Value); break; case "raster-colorizer-default-color": symRaster.ColorMap.DefaultColor = ColorUtility.FromHtml(pv.Value); break; case "raster-colorizer-epsilon": symRaster.ColorMap.Epsilon = Convert.ToSingle(pv.Value); break; case "raster-colorizer-stops": MatchCollection stopsMatch = m_colorMapStops.Matches(pv.Value.ToLower()); if (stopsMatch.Count > 0) { symRaster.ShadedRelief.ShaderType = ShaderType.Custom; foreach (Match match in stopsMatch) { ColorMapEntry entry = new ColorMapEntry(); MatchCollection args = m_regexFuncParams.Matches(match.Groups[2].Value.Trim(new char[] { '(', ')' })); for (int a = 0; a < args.Count; a++) { Match arg = args[a]; string av = arg.Value.Trim(); if (a == 0) entry.Quantity = Convert.ToDouble(av); else if (a == 1) entry.Color = ColorUtility.FromHtml(av); else if (a == 2) entry.Mode = ToColorMapMode(av); } symRaster.ColorMap.Entries.Add(entry); } } break; } } } catch (Exception ex) { ThrowParsingException(ex, pv); } return symRaster; }
public void ExerciseWmcFromCodeTest() { ViewContext context = new ViewContext(); // Context -> General context.General.Window.Width = 500; context.General.Window.Height = 300; context.General.BoundingBox.SRS = "EPSG:4326"; context.General.BoundingBox.MinX = -180; context.General.BoundingBox.MinY = -90; context.General.BoundingBox.MaxX = 180; context.General.BoundingBox.MaxY = 90; context.General.Title = "EOS Data Gateways"; context.General.KeywordList.Add("EOS"); context.General.KeywordList.Add("EOSDIS"); context.General.KeywordList.Add("NASA"); context.General.KeywordList.Add("CCRS"); context.General.KeywordList.Add("CEOS"); context.General.KeywordList.Add("OGC"); context.General.Abstract = "Map View of EOSDIS partners locations"; context.General.LogoURL.Width = 130; context.General.LogoURL.Height = 74; context.General.LogoURL.Format = "image/gif"; context.General.LogoURL.OnlineResource.Type = "simple"; context.General.LogoURL.OnlineResource.Href = "http://redhook.gsfc.nasa.gov/~imswww/pub/icons/logo.gif"; context.General.DescriptionURL.Format = "text/html"; context.General.DescriptionURL.OnlineResource.Type = "simple"; context.General.DescriptionURL.OnlineResource.Href = "http://eos.nasa.gov/imswelcome"; context.General.ContactInformation.ContactPersonPrimary.ContactPerson = "Tom Kralidis"; context.General.ContactInformation.ContactPersonPrimary.ContactOrganisation = "Canada Centre for Remote Sensing"; context.General.ContactInformation.ContactPosition = "Systems Scientist"; context.General.ContactInformation.ContactAddress.AddressType = "postal"; context.General.ContactInformation.ContactAddress.Address = "615 Booth Street, room 650"; context.General.ContactInformation.ContactAddress.City = "Ottawa"; context.General.ContactInformation.ContactAddress.StateOrProvince = "Ontario"; context.General.ContactInformation.ContactAddress.Country = "Canada"; context.General.ContactInformation.ContactVoiceTelephone = "+01 613 947 1828"; context.General.ContactInformation.ContactFacsimileTelephone = "+01 613 947 2410"; context.General.ContactInformation.ContactElectronicMailAddress = "*****@*****.**"; context.Version = "1.0"; context.Id = "TEST"; // Context -> Layer Layer layer = new Layer(); layer.Queryable = 1; layer.Hidden = 0; layer.Server.Service = GeospatialServices.Ogc.Common.ServiceNames.WMS; layer.Server.Version = "1.0.7"; layer.Title = "The GLOBE Program Visualization Server"; layer.Server.OnlineResource.Type = "simple"; layer.Server.OnlineResource.Href = "http://globe.digitalearth.gov/viz-bin/wmt.cgi"; layer.Name = "NATIONAL"; layer.Title = "National Boundaries"; layer.Abstract = "Context layer: National Boundaries"; layer.SRS = "EPSG:4326"; // Context -> Layer -> Format layer.FormatList.Add(new Format("GIF", 1)); // Context -> Layer -> Style Style style1 = new Style(); style1.Current = 1; style1.Name = "default"; style1.LegendURL.Width = 16; style1.LegendURL.Height = 16; style1.LegendURL.Format = "image/gif"; style1.LegendURL.OnlineResource.Type = "simple"; style1.LegendURL.OnlineResource.Href = "http://mapserv2.esrin.esa.it/cubestor/cubeserv.cgi?VERSION=1.1.0&REQUEST=GetLegendIcon&LAYER=WORLD_MODIS_1KM:MapAdmin&SPATIAL_TYPE=RASTER&STYLE=default&FORMAT=image//gif"; // Context -> Layer -> Style -> Named Layer NamedLayer namedLayer = new NamedLayer(); namedLayer.Name = "Roads"; // Context -> Layer -> Style -> Named Layer -> Named Styles namedLayer.NamedStyles.Add(new NamedStyle("Casing")); namedLayer.NamedStyles.Add(new NamedStyle("Centerline")); // Context -> Layer -> Style -> Named Layer -> User Style UserStyle userStyle1 = new UserStyle(); // Context -> Layer -> Style -> Named Layer -> User Style -> FeatureTypeStyle FeatureTypeStyle featureTypeStyle1 = new FeatureTypeStyle(); Rule rule1 = new Rule(); // Context -> Layer -> Style -> Named Layer -> User Style -> FeatureTypeStyle -> Rule -> Symbolizers BaseSymbolizer[] symbolizers = new BaseSymbolizer[6]; SymbolizerTypes[] symbolizerSelections = new SymbolizerTypes[6]; // Line Symbolizer LineSymbolizer lineSymbolizer = new LineSymbolizer(); lineSymbolizer.Geometry.PropertyName = "center-line"; lineSymbolizer.Stroke.SvgParameters.Add(new SvgParameter("stroke", "#0000ff")); lineSymbolizer.Stroke.SvgParameters.Add(new SvgParameter("stroke-width", "2")); symbolizers[0] = lineSymbolizer; symbolizerSelections[0] = SymbolizerTypes.LineSymbolizer; // Polygon Symbolizer PolygonSymbolizer polygonSymbolizer = new PolygonSymbolizer(); polygonSymbolizer.Geometry.PropertyName = "the_area"; polygonSymbolizer.Fill.SvgParameters.Add(new SvgParameter("fill", "#aaaaff")); polygonSymbolizer.Stroke.SvgParameters.Add(new SvgParameter("stroke", "#0000aa")); symbolizers[1] = polygonSymbolizer; symbolizerSelections[1] = SymbolizerTypes.PolygonSymbolizer; // Point Symbolizer PointSymbolizer pointSymbolizer = new PointSymbolizer(); // Point Symbolizer - > External Graphic 1 ExternalGraphic externalGraphic1 = new ExternalGraphic(); externalGraphic1.OnlineResource.Type = "simple"; externalGraphic1.OnlineResource.Href = "http://www.vendor.com/geosym/2267.svg"; externalGraphic1.Format = "image/svg+xml"; pointSymbolizer.Graphic.ExternalGraphics.Add(externalGraphic1); // Point Symbolizer - > External Graphic 2 ExternalGraphic externalGraphic2 = new ExternalGraphic(); externalGraphic2.OnlineResource.Type = "simple"; externalGraphic2.OnlineResource.Href = "http://www.vendor.com/geosym/2267.png"; externalGraphic2.Format = "image/png"; pointSymbolizer.Graphic.ExternalGraphics.Add(externalGraphic2); pointSymbolizer.Graphic.Size = 15.0; symbolizers[2] = pointSymbolizer; symbolizerSelections[2] = SymbolizerTypes.PointSymbolizer; // Text Symbolizer TextSymbolizer textSymbolizer = new TextSymbolizer(); textSymbolizer.Geometry.PropertyName = "locatedAt"; textSymbolizer.Label = @"ogc:PropertyName[hospitalName]"; textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-family", "Arial")); textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-family", "Sans-Serif")); textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-style", "italic")); textSymbolizer.Font.SvgParameters.Add(new SvgParameter("font-size", "10")); textSymbolizer.Fill.SvgParameters.Add(new SvgParameter("fill", "#000000")); textSymbolizer.LabelPlacement.PointPlacement = new PointPlacement(); textSymbolizer.LabelPlacement.PointPlacement.AnchorPoint.AnchorPointX = 456; textSymbolizer.LabelPlacement.PointPlacement.AnchorPoint.AnchorPointY = 123; textSymbolizer.LabelPlacement.PointPlacement.Rotation = 180; textSymbolizer.LabelPlacement.PointPlacement.Displacement.DisplacementX = 111; textSymbolizer.LabelPlacement.PointPlacement.Displacement.DisplacementY = 222; textSymbolizer.LabelPlacement.LinePlacement = new LinePlacement(); textSymbolizer.LabelPlacement.LinePlacement.Gap = 12; textSymbolizer.LabelPlacement.LinePlacement.GeneraliseLine = 3; textSymbolizer.LabelPlacement.LinePlacement.InitialGap = 3; textSymbolizer.LabelPlacement.LinePlacement.IsAligned = 0; textSymbolizer.LabelPlacement.LinePlacement.IsRepeated = 1; textSymbolizer.LabelPlacement.LinePlacement.PerpendicularOffset = 5; textSymbolizer.Halo.Fill = new Fill(); textSymbolizer.Halo.Fill.SvgParameters.Add(new SvgParameter("fill", "#000000")); textSymbolizer.Halo.Radius = 3; symbolizers[3] = textSymbolizer; symbolizerSelections[3] = SymbolizerTypes.TextSymbolizer; // Raster Symbolizer 1 RasterSymbolizer rasterSymbolizer1 = new RasterSymbolizer(); rasterSymbolizer1.Opacity = 1.0; rasterSymbolizer1.OverlapBehaviour = OverlapBehaviourTypes.Average; rasterSymbolizer1.ColourMap.Categorize.LookupValue = "Rasterdata"; rasterSymbolizer1.ColourMap.Categorize.Values.Add("#00ff00"); rasterSymbolizer1.ColourMap.Categorize.Thresholds.Add(-417); rasterSymbolizer1.ColourMap.Categorize.Values.Add("#00fa00"); rasterSymbolizer1.ColourMap.Categorize.Thresholds.Add(-333); symbolizers[4] = rasterSymbolizer1; symbolizerSelections[4] = SymbolizerTypes.RasterSymbolizer; // Raster Symbolizer 2 RasterSymbolizer rasterSymbolizer2 = new RasterSymbolizer(); rasterSymbolizer2.Opacity = 1.0; rasterSymbolizer2.OverlapBehaviour = OverlapBehaviourTypes.LatestOnTop; rasterSymbolizer2.ChannelSelection.RedChannel.SourceChannelName = "1"; rasterSymbolizer2.ChannelSelection.GreenChannel.SourceChannelName = "2"; rasterSymbolizer2.ChannelSelection.GreenChannel.ContrastEnhancement.GammaValue = 2.5; rasterSymbolizer2.ChannelSelection.BlueChannel.SourceChannelName = "3"; rasterSymbolizer2.ColourMap.Interpolate.FallBackValue = "#dddddd"; rasterSymbolizer2.ColourMap.Interpolate.LookupValue = "Rasterdata"; rasterSymbolizer2.ColourMap.Interpolate.InterpolationPoints.Add(new InterpolationPoint(0, "#000000")); rasterSymbolizer2.ColourMap.Interpolate.InterpolationPoints.Add(new InterpolationPoint(255, "#ffffff")); rasterSymbolizer2.ContrastEnhancement.GammaValue = 1; rasterSymbolizer2.Geometry.PropertyName = "Coastlines"; symbolizers[5] = rasterSymbolizer2; symbolizerSelections[5] = SymbolizerTypes.RasterSymbolizer; rule1.SymbolizerSelections = symbolizerSelections; rule1.Symbolizers = symbolizers; featureTypeStyle1.Rules.Add(rule1); Rule rule2 = new Rule(); rule2.ElseFilter = new ElseFilter(); featureTypeStyle1.Rules.Add(rule2); Rule rule3 = new Rule(); GeospatialServices.Ogc.Wmc.PropertyIsEqualTo propEqualTo = new PropertyIsEqualTo(); propEqualTo.Literal.Value = "NEW YORK"; propEqualTo.PropertyName = "SALES_AREA"; //BaseComparisonOps ComparisonOps[] = new BaseComparisonOps[2]; rule3.Filter.FilterExpression = propEqualTo; featureTypeStyle1.Rules.Add(rule3); userStyle1.FeatureTypeStyles.Add(featureTypeStyle1); namedLayer.UserStyles.Add(userStyle1); // Context - > Layer -> Style -> User Layer UserLayer userLayer = new UserLayer(); userLayer.Name = "Lakes and Rivers"; UserStyle userStyle = new UserStyle("Default"); userStyle.FeatureTypeStyles.Add(featureTypeStyle1); userLayer.UserStyles = new List <UserStyle>(); userLayer.UserStyles.Add(userStyle); style1.SLD.StyledLayerDescriptor.NamedLayers.Add(namedLayer); style1.SLD.StyledLayerDescriptor.UserLayers.Add(userLayer); layer.StyleList.Add(style1); context.Layers.Add(layer); }