/// <summary> /// Resolves resolution in degrees /// </summary> /// <returns>resolution in degrees</returns> public static double GetResolution(System.Xml.XmlDocument oMeta, DataSet oDataset) { try { System.Xml.XmlNode oNodeRes = oMeta.SelectSingleNode("//meta/CLASS/CLASS/ATTRIBUTE[@name='SpatialResolution']"); if (oNodeRes != null) { int dX, dY; double dSpatRes = Convert.ToDouble(oNodeRes.Attributes["value"].Value, System.Globalization.CultureInfo.InvariantCulture); double dMinX = Convert.ToDouble(oMeta.SelectSingleNode("//meta/CLASS/CLASS/ATTRIBUTE[@name='BoundingMinX']").Attributes["value"].Value, System.Globalization.CultureInfo.InvariantCulture); double dMinY = Convert.ToDouble(oMeta.SelectSingleNode("//meta/CLASS/CLASS/ATTRIBUTE[@name='BoundingMinY']").Attributes["value"].Value, System.Globalization.CultureInfo.InvariantCulture); double dMaxX = Convert.ToDouble(oMeta.SelectSingleNode("//meta/CLASS/CLASS/ATTRIBUTE[@name='BoundingMaxX']").Attributes["value"].Value, System.Globalization.CultureInfo.InvariantCulture); double dMaxY = Convert.ToDouble(oMeta.SelectSingleNode("//meta/CLASS/CLASS/ATTRIBUTE[@name='BoundingMaxY']").Attributes["value"].Value, System.Globalization.CultureInfo.InvariantCulture); dX = (int)Math.Round((dMaxX - dMinX) / dSpatRes); dY = (int)Math.Round((dMaxY - dMinY) / dSpatRes); return Math.Min((oDataset.Boundary.MaxX - oDataset.Boundary.MinX) / dX, (oDataset.Boundary.MaxY - oDataset.Boundary.MinY) / dY); } } catch { return 0.0; } return 0.0; }
/// <summary> /// Resolves resolution in degrees /// </summary> /// <returns>resolution in degrees</returns> public static double GetResolution(Command oDapCommand, DataSet oDataset) { try { System.Xml.XmlDocument oMeta = oDapCommand.GetMetaData(oDataset); return (GetResolution(oMeta, oDataset)); } catch { return 0.0; } }
public DAPLayer(DataSet data) : base(1.0f, "[Servertitle]", data.Title, "[ServerDescription]", int.Parse(data.Name), new Uri(data.Url).Host, data.Boundary) { DAPDatasetName = data.Name; DAPHeight = 0; DAPSize = TileInfo.TileSizePixels; DAPType = data.Type; DAPEdition = data.Edition; DAPHierarchy = data.Hierarchy; DAPLevels = 15; DAPLevelZeroTilesize = 22.5; DAPLayerDescription = "[LayerDescription]"; }
/// <summary> /// Calculate the default number of levels for this dataset /// </summary> /// <returns></returns> public static int Levels(System.Xml.XmlDocument oMeta, DataSet oDataset) { int iLevels = 15; // Determine the needed levels (function of tile size and resolution if available) double dRes = GetResolution(oMeta, oDataset); if (dRes > 0) { double dTileSize = LevelZeroTileSize(oDataset); iLevels = 1; while ((double)dTileSize / Convert.ToDouble(256) > dRes / 4.0) { iLevels++; dTileSize /= 2; } } return iLevels; }
/// <summary> /// Get xml meta information for a particular dataset /// </summary> /// <param name="hDataSet">The dataset to retrieve meta information for</param> /// <param name="progressCallBack">Progress handler (may be null)</param> /// <returns>The meta response in GeosoftXML</returns> public System.Xml.XmlDocument GetXMLMetaData(DataSet hDataSet, UpdateProgessCallback progressCallBack) { // --- check to make sure that the dataset is located on the server this command is connected to --- if (hDataSet.Url != Url) throw new DapException("The dataset is not located on this server."); return GetXMLMetaData(hDataSet.Name, progressCallBack); }
/// <summary> /// Encode the request to get a tile for a dataset /// </summary> /// <param name="szHandle">The handle which uniquly identifies this request/response pair</param> /// <param name="iColumn"></param> /// <param name="iLevel"></param> /// <param name="iRow"></param> /// <param name="oDataset"></param> /// <returns>The GeosoftXML request</returns> public System.Xml.XmlDocument GetTile(string szHandle, DataSet oDataset, int iLevel, int iRow, int iColumn) { // --- Create required nodes --- System.Xml.XmlAttribute hAttr; System.Xml.XmlElement oGetTileNode = CreateRequest(szHandle, Constant.Tag.GET_TILE_TAG); hAttr = oGetTileNode.OwnerDocument.CreateAttribute(Constant.Attribute.LAYER_ATTR); hAttr.Value = oDataset.Name; oGetTileNode.SetAttributeNode(hAttr); hAttr = oGetTileNode.OwnerDocument.CreateAttribute(Constant.Attribute.LEVEL_ATTR); hAttr.Value = iLevel.ToString(); oGetTileNode.SetAttributeNode(hAttr); hAttr = oGetTileNode.OwnerDocument.CreateAttribute(Constant.Attribute.ROW_ATTR); hAttr.Value = iRow.ToString(); oGetTileNode.SetAttributeNode(hAttr); hAttr = oGetTileNode.OwnerDocument.CreateAttribute(Constant.Attribute.COLUMN_ATTR); hAttr.Value = iColumn.ToString(); oGetTileNode.SetAttributeNode(hAttr); return oGetTileNode.OwnerDocument; }
/// <summary> /// Get the disclaimer data /// </summary> /// <param name="hDataSet"></param> /// <param name="strTempFile"></param> /// <param name="progressCallBack">Progress handler (may be null)</param> /// <returns>The exact data response in GeosoftXML</returns> public System.Xml.XmlReader GetDisclaimerEx(DataSet hDataSet, string strTempFile, UpdateProgessCallback progressCallBack) { string szUrl; System.Xml.XmlDocument hRequestDocument; System.Xml.XmlReader hResponseReader; try { m_oLock.AcquireReaderLock(-1); szUrl = CreateUrl(Constant.Request.DISCLAIMER); hRequestDocument = m_hEncodeRequest.Disclaimer(null, hDataSet.Name); hResponseReader = m_oCommunication.SendEx(szUrl, hRequestDocument, strTempFile, progressCallBack); } finally { m_oLock.ReleaseReaderLock(); } return hResponseReader; }
internal override object CloneSpecific() { DataSet hDSCopy = new DataSet(); hDSCopy.Edition = m_hDataSet.Edition; hDSCopy.Boundary = m_hDataSet.Boundary; hDSCopy.Hierarchy = m_hDataSet.Hierarchy; hDSCopy.Name = m_hDataSet.Name; hDSCopy.Title = m_hDataSet.Title; hDSCopy.Type = m_hDataSet.Type; hDSCopy.Url = m_hDataSet.Url; return new DAPQuadLayerBuilder(hDSCopy, m_oWorldWindow, m_oServer, m_Parent, m_iHeight, m_iTextureSizePixels, this.LevelZeroTileSize, m_iLevels); }
internal DAPQuadLayerBuilder(DataSet dataSet, WorldWindow worldWindow, Server server, IBuilder parent) : this(dataSet, worldWindow, server, parent, 0, 256, 0, 0) { }
/// <summary> /// Calculate the default number of levels for this dataset using the tiling system, which implies that the level zero tilesize is /// always 22.5 degrees. /// </summary> /// <param name="oDapCommand"></param> /// <param name="oDataset"></param> /// <returns></returns> public static int TileLevels(Command oDapCommand, DataSet oDataset) { int iLevels = 15; // Determine the needed levels (function of tile size and resolution if available) double dRes = GetResolution(oDapCommand, oDataset); if (dRes > 0) { double dTileSize = 22.5; iLevels = 1; while ((double)dTileSize / Convert.ToDouble(256) > dRes / 4.0) { iLevels++; dTileSize /= 2; } } return iLevels; }
/// <summary> /// Get an image from a dataset /// </summary> /// <param name="hDataSet">The dataset to get an image for</param> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hResolution">The resolution to retrieve the image at</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImage(DataSet hDataSet, Format hFormat, Resolution hResolution) { return GetImage(hDataSet, hFormat, hResolution, null); }
/// <summary> /// Get xml meta information for a particular dataset /// </summary> /// <param name="hDataSet">The dataset to retrieve meta information for</param> /// <returns>The meta response in GeosoftXML</returns> public System.Xml.XmlDocument GetXMLMetaData(DataSet hDataSet) { return GetXMLMetaData(hDataSet, null); }
/// <summary> /// Update the contents of the tree, as a result has been (de)selected from a different screen /// </summary> internal void UpdateResults(DataSet hDataSet, bool bAdded) { if (bAdded) { if (!m_hSelectedDataSets.ContainsKey(hDataSet.UniqueName)) m_hSelectedDataSets.Add(hDataSet.UniqueName, hDataSet); } else { m_hSelectedDataSets.Remove(hDataSet.UniqueName); } RefreshResults(); }
/// <summary> /// Generate a tile download request XML. /// </summary> /// <param name="szHandle">A unique identifier for the request/response pair.</param> /// <param name="oDataSet">The dataset name to download.</param> /// <param name="iLevel">The level of the tile.</param> /// <param name="iRow">The tile row.</param> /// <param name="iColumn">The tile column.</param> /// <param name="szUrl">The address to send the request to.</param> /// <returns></returns> public System.Xml.XmlDocument GetTileRequestDocument(String szHandle, DataSet oDataSet, int iLevel, int iRow, int iColumn, out String szUrl) { System.Xml.XmlDocument hRequestDocument = null; try { m_oLock.AcquireReaderLock(-1); szUrl = CreateUrl(Constant.Request.IMAGE); hRequestDocument = m_hEncodeRequest.GetTile(szHandle, oDataSet, iLevel, iRow, iColumn); } catch (Exception e) { m_oLock.ReleaseReaderLock(); hRequestDocument = null; throw e; } return hRequestDocument; }
/// <summary> /// Generate a tile download request XML. /// </summary> /// <param name="oDataSet">The dataset name to download.</param> /// <param name="iLevel">The level of the tile.</param> /// <param name="iRow">The tile row.</param> /// <param name="iColumn">The tile column.</param> /// <param name="szUrl">The address to send the request to.</param> /// <returns></returns> public System.Xml.XmlDocument GetTileRequestDocument(DataSet oDataSet, int iLevel, int iRow, int iColumn, out String szUrl) { return GetTileRequestDocument(null, oDataSet, iLevel, iRow, iColumn, out szUrl); }
/// <summary> /// Get a tile for this dataset from the dap server /// </summary> /// <param name="oDataSet"></param> /// <param name="iLevel"></param> /// <param name="iRow"></param> /// <param name="iColumn"></param> /// <param name="progressCallBack"></param> /// <returns>The tile</returns> public System.Drawing.Bitmap GetTile(DataSet oDataSet, int iLevel, int iRow, int iColumn, UpdateProgessCallback progressCallBack) { string szUrl; System.Xml.XmlDocument oRequestDocument; System.Xml.XmlDocument oResponse = null; System.Drawing.Bitmap oBitmap = null; try { m_oLock.AcquireReaderLock(-1); szUrl = CreateUrl(Constant.Request.IMAGE); oRequestDocument = m_hEncodeRequest.GetTile(null, oDataSet, iLevel, iRow, iColumn); oResponse = m_oCommunication.Send(szUrl, oRequestDocument, progressCallBack); if (oResponse != null) m_hParse.Tile(oResponse, out oBitmap); } finally { m_oLock.ReleaseReaderLock(); } return oBitmap; }
/// <summary> /// Get a legend for this dataset from the dap server /// </summary> /// <param name="oDataSet"></param> /// <param name="progressCallBack"></param> /// <returns>The tile</returns> public System.Drawing.Bitmap GetLegend(DataSet oDataSet, UpdateProgessCallback progressCallBack) { string szUrl; System.Xml.XmlDocument oRequestDocument; System.Xml.XmlReader oResponse = null; System.Drawing.Bitmap oBitmap = null; try { m_oLock.AcquireReaderLock(-1); szUrl = CreateUrl(Constant.Request.IMAGE); oRequestDocument = m_hEncodeRequest.GetLegend(null, oDataSet); oResponse = m_oCommunication.SendHttpEx(szUrl, oRequestDocument, progressCallBack); if (oResponse != null) m_hParse.Legend(oResponse, out oBitmap); } finally { if (oResponse != null) oResponse.Close(); m_oLock.ReleaseReaderLock(); } return oBitmap; }
/// <summary> /// Get an image from a dataset /// </summary> /// <param name="hDataSet">The dataset to get an image for</param> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hResolution">The resolution to retrieve the image at</param> /// <param name="progressCallBack">Progress handler (may be null)</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImage(DataSet hDataSet, Format hFormat, Resolution hResolution, UpdateProgessCallback progressCallBack) { // --- check to make sure that the dataset is located on the server this command is connected to --- if (hDataSet.Url != Url) throw new DapException("The dataset is not located on this server."); System.Collections.ArrayList hArrayList = new System.Collections.ArrayList(); hArrayList.Add(hDataSet.Name); return GetImage(hFormat, hDataSet.Boundary, hResolution, hArrayList, progressCallBack); }
/// <summary> /// Calculate the default level zero tile size /// </summary> /// <param name="oDataset"></param> /// <returns>default level zero tile size</returns> public static double LevelZeroTileSize(DataSet oDataset) { // Round to ceiling of four decimals (>~ 10 meter resolution) // Empirically determined as pretty good tile size choice for small data sets double dLevelZero = (Math.Ceiling(10000.0 * Math.Max(oDataset.Boundary.MaxY - oDataset.Boundary.MinY, oDataset.Boundary.MaxX - oDataset.Boundary.MinX)) / 10000.0); // Optimum tile alignment when this is 180/(2^n), the first value is 180/2^3 double dRet = 22.5; while (dLevelZero < dRet) dRet /= 2; return dRet; }
/// <summary> /// Transform the item element, found in the catalog response, to its corresponding structure. /// </summary> /// <param name="oCatalog">The GeosoftXML catalog</param> /// <param name="strDataSetName">The server name of the dataset</param> /// <param name="oDataSet">The Dataset structure that will be populated</param> public void DataSet(System.Xml.XmlDocument oCatalog, string strDataSetName, out DataSet oDataSet) { System.Xml.XmlNodeList hItemList; try { // --- find all the item elements located anywhere in the document --- string szPath = "//" + Geosoft.Dap.Xml.Common.Constant.Tag.ITEM_TAG + "[@" + Geosoft.Dap.Xml.Common.Constant.Attribute.NAME_ATTR + "=\"" + strDataSetName + "\"]"; hItemList = oCatalog.SelectNodes(szPath); if (hItemList == null || hItemList.Count == 0) throw new DapException("No dataset node found with name " + strDataSetName); DataSet(hItemList[0], out oDataSet); } catch (System.Xml.XmlException e) { throw new DapException("Error retrieve dataset node " + strDataSetName, e); } }
/// <summary> /// Transform the item element, found in the catalog response, to its corresponding structure. /// </summary> /// <param name="hDataSetNode">The GeosoftXML item element</param> /// <param name="hDataSet">The dataset structure to populate</param> public void DataSet(System.Xml.XmlNode hDataSetNode, out DataSet hDataSet) { hDataSet = null; if (hDataSetNode == null || hDataSetNode.Name != Xml.Common.Constant.Tag.ITEM_TAG) { throw new DapException("Invalid format found in item element."); } System.Xml.XmlNode hName = hDataSetNode.Attributes.GetNamedItem(Constant.Attribute.NAME_ATTR); System.Xml.XmlNode hTitle = hDataSetNode.Attributes.GetNamedItem(Constant.Attribute.TITLE_ATTR); System.Xml.XmlNode hType = hDataSetNode.Attributes.GetNamedItem(Constant.Attribute.TYPE_ATTR); System.Xml.XmlNode hEdition = hDataSetNode.Attributes.GetNamedItem(Constant.Attribute.EDITION_ATTR); System.Xml.XmlNode hStylesheet = hDataSetNode.Attributes.GetNamedItem(Constant.Attribute.STYLESHEET_ATTR); String szHierarchy = ""; System.Xml.XmlNode hParent = hDataSetNode.ParentNode; while (hParent != null && hParent.Name != Constant.Tag.CATALOG_TAG) { System.Xml.XmlNode hFolderName = hParent.Attributes.GetNamedItem(Constant.Attribute.NAME_ATTR); szHierarchy = hFolderName.Value + "/" + szHierarchy; hParent = hParent.ParentNode; } hDataSet = new DataSet(); hDataSet.Url = m_szUrl; if (hDataSetNode.HasChildNodes) { BoundingBox oBB; BoundingBox(hDataSetNode.FirstChild, out oBB); hDataSet.Boundary = oBB; } if (hName != null) hDataSet.Name = hName.Value; if (hTitle != null) hDataSet.Title = hTitle.Value; if (hType != null) hDataSet.Type = hType.Value; if (hEdition != null) hDataSet.Edition = hEdition.Value; if (szHierarchy != null) hDataSet.Hierarchy = szHierarchy; if (hStylesheet != null) hDataSet.Stylesheet = hStylesheet.Value; }
/// <summary> /// Encode the request to get a legend for a dataset /// </summary> /// <param name="szHandle">The handle which uniquly identifies this request/response pair</param> /// <param name="oDataset"></param> /// <returns>The GeosoftXML request</returns> public System.Xml.XmlDocument GetLegend(string szHandle, DataSet oDataset) { // --- Create required nodes --- System.Xml.XmlAttribute hAttr; System.Xml.XmlElement oLegendNode = CreateRequest(szHandle, Constant.Tag.LEGEND_TAG); System.Xml.XmlElement oDatasetNode = oLegendNode.OwnerDocument.CreateElement(Constant.Tag.DATASET_TAG); hAttr = oLegendNode.OwnerDocument.CreateAttribute(Constant.Attribute.NAME_ATTR); hAttr.Value = oDataset.Name; oDatasetNode.SetAttributeNode(hAttr); oLegendNode.AppendChild(oDatasetNode); return oLegendNode.OwnerDocument; }
/// <summary> /// Default constructor /// </summary> /// <param name="hDataSet"></param> public DataSetArgs(DataSet hDataSet) { DataSet = hDataSet; }
internal override LayerBuilder getBuilder(DappleModel oModel) { DataSet hDataSet = new DataSet(); hDataSet.Name = getAttribute("datasetname"); hDataSet.Url = m_oServer.ToBaseUri(); hDataSet.Type = getAttribute("type"); hDataSet.Title = getAttribute("title"); hDataSet.Edition = getAttribute("edition"); hDataSet.Hierarchy = getAttribute("hierarchy"); if (hasAttribute("stylesheet")) hDataSet.Stylesheet = getAttribute("stylesheet"); double minX, minY, maxX, maxY; if (!Double.TryParse(getAttribute("west"), NumberStyles.Any, CultureInfo.InvariantCulture, out minX)) return null; if (!Double.TryParse(getAttribute("south"), NumberStyles.Any, CultureInfo.InvariantCulture, out minY)) return null; if (!Double.TryParse(getAttribute("east"), NumberStyles.Any, CultureInfo.InvariantCulture, out maxX)) return null; if (!Double.TryParse(getAttribute("north"), NumberStyles.Any, CultureInfo.InvariantCulture, out maxY)) return null; hDataSet.Boundary = new Geosoft.Dap.Common.BoundingBox(maxX, maxY, minX, minY); int height, size, levels; double lvl0tilesize; if (!Int32.TryParse(getAttribute("height"), NumberStyles.Any, CultureInfo.InvariantCulture, out height)) return null; if (!Int32.TryParse(getAttribute("size"), NumberStyles.Any, CultureInfo.InvariantCulture, out size)) return null; if (!Int32.TryParse(getAttribute("levels"), NumberStyles.Any, CultureInfo.InvariantCulture, out levels)) return null; if (!Double.TryParse(getAttribute("lvl0tilesize"), NumberStyles.Any, CultureInfo.InvariantCulture, out lvl0tilesize)) return null; DapServerModelNode oServerMN = oModel.AddDAPServer(m_oServer as DapServerUri, true, false, false) as DapServerModelNode; oServerMN.WaitForLoad(); if (oServerMN.LoadState == LoadState.LoadFailed) return null; Geosoft.GX.DAPGetData.Server oServer = oServerMN.Server; return new DAPQuadLayerBuilder(hDataSet, MainForm.WorldWindowSingleton, oServer, null, height, size, lvl0tilesize, levels); }
/// <summary> /// Get the disclaimer data /// </summary> /// <param name="hDataSet"></param> /// <param name="strTempFile"></param> /// <returns>The exact data response in GeosoftXML</returns> public System.Xml.XmlReader GetDisclaimerEx(DataSet hDataSet, string strTempFile) { return GetDisclaimerEx(hDataSet, strTempFile, null); }
/// <summary> /// Default constructor /// </summary> /// <param name="hDataSet">dataset</param> /// <param name="szFormat">Format to extract the dataset to</param> /// <param name="dResolution">Resolution of the dataset</param> public ExtractDataSet(DataSet hDataSet, string szFormat, double dResolution) { m_hDataSet = hDataSet; m_szFormat = szFormat; m_dResolution = dResolution; }
/// <summary> /// Default constructor /// </summary> public ExtractDataSet() { m_hDataSet = null; m_szFormat = null; m_dResolution = 0; }
internal DapDatasetModelNode(DappleModel oModel, DataSet oDataSet) : base(oModel) { m_oDataSet = oDataSet; MarkLoaded(); }
/// <summary> /// Calculate the default number of levels for this dataset /// </summary> /// <returns></returns> public static int Levels(Command oDapCommand, DataSet oDataset) { try { System.Xml.XmlDocument oMeta = oDapCommand.GetMetaData(oDataset); return (Levels(oMeta, oDataset)); } catch { return 1; } }
internal DAPQuadLayerBuilder(DataSet dataSet, WorldWindow worldWindow, Server server, IBuilder parent, int height, int size, double lvl0tilesize, int levels) : base(dataSet.Title, worldWindow, parent) { m_hDataSet = dataSet; m_oServer = server; m_iHeight = height; m_iTextureSizePixels = size; this.LevelZeroTileSize = lvl0tilesize; m_iLevels = levels; m_blUseXMLMeta = !String.IsNullOrEmpty(m_hDataSet.Stylesheet); }