private void GetLayerCount(bool bInterSect, WorldWind.GeographicBoundingBox extents, string strText, ref int iCount) { if (strText == null) { throw new ArgumentNullException("strText"); } foreach (IBuilder builder in SubList) { (builder as BuilderDirectory).GetLayerCount(bInterSect, extents, strText, ref iCount); } foreach (LayerBuilder builder in LayerBuilders) { if ((strText != string.Empty && builder.Title.IndexOf(strText, 0, StringComparison.InvariantCultureIgnoreCase) == -1) || (extents != null && bInterSect && !extents.Intersects(builder.Extents) && !extents.Contains(builder.Extents))) { continue; } iCount++; } }
/*public byte Opacity * { * get * { * return m_parentProjectedLayer.Opacity; * } * set * { * if(m_NwImageLayer != null) * { * m_NwImageLayer.Opacity = value; * } * if(m_NeImageLayer != null) * { * m_NeImageLayer.Opacity = value; * } * if(m_SwImageLayer != null) * { * m_SwImageLayer.Opacity = value; * } * if(m_SeImageLayer != null) * { * m_SeImageLayer.Opacity = value; * } * * if(m_NorthWestChild != null) * { * m_NorthWestChild.Opacity = value; * } * if(m_NorthEastChild != null) * { * m_NorthEastChild.Opacity = value; * } * if(m_SouthWestChild != null) * { * m_SouthWestChild.Opacity = value; * } * if(m_SouthEastChild != null) * { * m_SouthEastChild.Opacity = value; * } * } * }*/ private Renderable.ImageLayer CreateImageLayer(double north, double south, double west, double east, DrawArgs drawArgs, string imagePath) { Bitmap b = null; Graphics g = null; Renderable.ImageLayer imageLayer = null; GeographicBoundingBox geoBB = new GeographicBoundingBox(north, south, west, east); int numberPolygonsInTile = 0; FileInfo imageFile = new FileInfo(imagePath); if (!m_parentProjectedLayer.EnableCaching || !imageFile.Exists ) { if (m_parentProjectedLayer.LineStrings != null) { for (int i = 0; i < m_parentProjectedLayer.LineStrings.Length; i++) { if (!m_parentProjectedLayer.LineStrings[i].Visible) { continue; } GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.LineStrings[i].GetGeographicBoundingBox(); if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB)) { continue; } else { if (b == null) { b = new Bitmap( m_parentProjectedLayer.TileSize.Width, m_parentProjectedLayer.TileSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } if (g == null) { g = Graphics.FromImage(b); } drawLineString( m_parentProjectedLayer.LineStrings[i], g, geoBB, b.Size ); numberPolygonsInTile++; } } } if (m_parentProjectedLayer.Polygons != null) { for (int i = 0; i < m_parentProjectedLayer.Polygons.Length; i++) { if (!m_parentProjectedLayer.Polygons[i].Visible) { continue; } GeographicBoundingBox currentBoundingBox = m_parentProjectedLayer.Polygons[i].GetGeographicBoundingBox(); if (currentBoundingBox != null && !currentBoundingBox.Intersects(geoBB)) { continue; } else { if (b == null) { b = new Bitmap( m_parentProjectedLayer.TileSize.Width, m_parentProjectedLayer.TileSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } if (g == null) { g = Graphics.FromImage(b); } drawPolygon( m_parentProjectedLayer.Polygons[i], g, geoBB, b.Size); numberPolygonsInTile++; } } } } if (b != null) { System.Drawing.Imaging.BitmapData srcInfo = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); bool isBlank = true; unsafe { int *srcPointer = (int *)srcInfo.Scan0; for (int i = 0; i < b.Height; i++) { for (int j = 0; j < b.Width; j++) { int color = *srcPointer++; if (((color >> 24) & 0xff) > 0) { isBlank = false; break; } } srcPointer += (srcInfo.Stride >> 2) - b.Width; } } b.UnlockBits(srcInfo); if (isBlank) { numberPolygonsInTile = 0; } } // if(!m_parentProjectedLayer.EnableCaching) // { string id = System.DateTime.Now.Ticks.ToString(); if (b != null && numberPolygonsInTile > 0) { MemoryStream ms = new MemoryStream(); b.Save(ms, System.Drawing.Imaging.ImageFormat.Png); //must copy original stream into new stream, if not, error occurs, not sure why m_ImageStream = new MemoryStream(ms.GetBuffer()); imageLayer = new WorldWind.Renderable.ImageLayer( id, m_parentProjectedLayer.World, 0, m_ImageStream, System.Drawing.Color.Black.ToArgb(), (float)south, (float)north, (float)west, (float)east, 1.0f //(float)m_parentProjectedLayer.Opacity / 255.0f , m_parentProjectedLayer.World.TerrainAccessor); ms.Close(); } /* } * else if(imageFile.Exists || numberPolygonsInTile > 0) * { * string id = System.DateTime.Now.Ticks.ToString(); * * if(b != null) * { * MemoryStream ms = new MemoryStream(); * b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); * if(!imageFile.Directory.Exists) * imageFile.Directory.Create(); * * //must copy original stream into new stream, if not, error occurs, not sure why * m_ImageStream = new MemoryStream(ms.GetBuffer()); * ImageHelper.ConvertToDxt3(m_ImageStream, imageFile.FullName); * * ms.Close(); * } * * imageLayer = new WorldWind.Renderable.ImageLayer( * id, * m_parentProjectedLayer.World, * 0, * imageFile.FullName, * //System.Drawing.Color.Black.ToArgb(), * (float)south, * (float)north, * (float)west, * (float)east, * 1.0f,//(float)m_parentProjectedLayer.Opacity / 255.0f, * m_parentProjectedLayer.World.TerrainAccessor); * * imageLayer.TransparentColor = System.Drawing.Color.Black.ToArgb(); * } */ if (b != null) { b.Dispose(); } if (g != null) { g.Dispose(); } b = null; g = null; //might not be necessary //GC.Collect(); return(imageLayer); }
/// <summary> /// Write out settings for the picture dataset /// </summary> /// <param name="oDatasetElement"></param> /// <param name="strDestFolder"></param> /// <param name="bDefaultResolution"></param> /// <returns></returns> internal override ExtractSaveResult Save(System.Xml.XmlElement oDatasetElement, string strDestFolder, DownloadSettings.DownloadCoordinateSystem eCS) { System.Xml.XmlAttribute oAttr = oDatasetElement.OwnerDocument.CreateAttribute("type"); oAttr.Value = "geotiff"; oDatasetElement.Attributes.Append(oAttr); oAttr = oDatasetElement.OwnerDocument.CreateAttribute("title"); oAttr.Value = m_oNonDapBuilder.Title; oDatasetElement.Attributes.Append(oAttr); oAttr = oDatasetElement.OwnerDocument.CreateAttribute("file"); oAttr.Value = System.IO.Path.Combine(strDestFolder, System.IO.Path.ChangeExtension(Utility.FileSystem.SanitizeFilename(tbFilename.Text), TIF_EXT)); oDatasetElement.Attributes.Append(oAttr); // --- Delete all the files that OM generates, so we don't get invalid projections --- try { if (System.IO.File.Exists(oAttr.Value)) { System.IO.File.Delete(oAttr.Value); } if (System.IO.File.Exists(System.IO.Path.ChangeExtension(oAttr.Value, ".ipj"))) { System.IO.File.Delete(System.IO.Path.ChangeExtension(oAttr.Value, ".ipj")); } if (System.IO.File.Exists(System.IO.Path.ChangeExtension(oAttr.Value, ".gi"))) { System.IO.File.Delete(System.IO.Path.ChangeExtension(oAttr.Value, ".gi")); } if (System.IO.File.Exists(System.IO.Path.ChangeExtension(oAttr.Value, ".tif.xml"))) { System.IO.File.Delete(System.IO.Path.ChangeExtension(oAttr.Value, ".tif.xml")); } } catch (System.IO.IOException) { MessageBox.Show("Could not save file " + oAttr.Value + ", please choose a different filename.", "Extraction error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(ExtractSaveResult.Cancel); } if (m_oNonDapBuilder is GeorefImageLayerBuilder) { System.IO.File.Copy(((GeorefImageLayerBuilder)m_oNonDapBuilder).FileName, oAttr.Value, true); } else { if (!m_oNonDapBuilder.exportToGeoTiff(oAttr.Value)) { MessageBox.Show(this, "Could not download " + m_oNonDapBuilder.Title + ", data layer's extents do not intersect the viewed area.", "Extraction Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(ExtractSaveResult.Ignore); } } System.Xml.XmlElement oDisplayElement = oDatasetElement.OwnerDocument.CreateElement("display_options"); Options.Picture.DisplayOptions eDisplayOption = (Options.Picture.DisplayOptions)cbDisplayOptions.SelectedIndex; oDisplayElement.InnerText = eDisplayOption.ToString(); oDatasetElement.AppendChild(oDisplayElement); WorldWind.GeographicBoundingBox oViewBox = WorldWind.GeographicBoundingBox.FromQuad(MainForm.WorldWindowSingleton.CurrentAreaOfInterest); String szViewCRS = Dapple.Extract.Resolution.WGS_84; WorldWind.GeographicBoundingBox oMapBox = MainForm.MapAoi; String szMapCRS = MainForm.MapAoiCoordinateSystem; bool blNewMap; if (oMapBox == null) { blNewMap = true; } else { if (MainForm.MontajInterface.ProjectBoundingRectangle(szMapCRS, ref oMapBox.West, ref oMapBox.South, ref oMapBox.East, ref oMapBox.North, szViewCRS)) { blNewMap = (!oViewBox.Intersects(oMapBox)); } else { blNewMap = true; } } oAttr = oDatasetElement.OwnerDocument.CreateAttribute("new_map"); oAttr.Value = blNewMap.ToString(); oDatasetElement.Attributes.Append(oAttr); GeographicBoundingBox oGeoTiffBox = oViewBox.Clone() as GeographicBoundingBox; if (m_oNonDapBuilder is GeorefImageLayerBuilder) { oGeoTiffBox = GeorefImageLayerBuilder.GetExtentsFromGeotif(((GeorefImageLayerBuilder)m_oNonDapBuilder).FileName); } oAttr = oDatasetElement.OwnerDocument.CreateAttribute("minx"); oAttr.Value = oGeoTiffBox.West.ToString(CultureInfo.InvariantCulture); oDatasetElement.Attributes.Append(oAttr); oAttr = oDatasetElement.OwnerDocument.CreateAttribute("miny"); oAttr.Value = oGeoTiffBox.South.ToString(CultureInfo.InvariantCulture); oDatasetElement.Attributes.Append(oAttr); oAttr = oDatasetElement.OwnerDocument.CreateAttribute("maxx"); oAttr.Value = oGeoTiffBox.East.ToString(CultureInfo.InvariantCulture); oDatasetElement.Attributes.Append(oAttr); oAttr = oDatasetElement.OwnerDocument.CreateAttribute("maxy"); oAttr.Value = oGeoTiffBox.North.ToString(CultureInfo.InvariantCulture); oDatasetElement.Attributes.Append(oAttr); oAttr = oDatasetElement.OwnerDocument.CreateAttribute("coordinate_system"); oAttr.Value = szViewCRS; oDatasetElement.Attributes.Append(oAttr); String szDownloadType = String.Empty; String szDownloadUrl = String.Empty; String szLayerId = String.Empty; m_oNonDapBuilder.GetOMMetadata(out szDownloadType, out szDownloadUrl, out szLayerId); oAttr = oDatasetElement.OwnerDocument.CreateAttribute("download_type"); oAttr.Value = szDownloadType; oDatasetElement.Attributes.Append(oAttr); oAttr = oDatasetElement.OwnerDocument.CreateAttribute("url"); oAttr.Value = szDownloadUrl; oDatasetElement.Attributes.Append(oAttr); oAttr = oDatasetElement.OwnerDocument.CreateAttribute("id"); oAttr.Value = szLayerId; oDatasetElement.Attributes.Append(oAttr); return(ExtractSaveResult.Extract); }