public static SearchRequest SearchRequest(string requestXML) { XmlDocument requestDocument = new XmlDocument(); requestDocument.LoadXml(requestXML); string version = requestDocument.SelectSingleNode("/geosoft_xml/search_request/@version").Value; string handle = requestDocument.SelectSingleNode("/geosoft_xml/search_request/@handle").Value; int maxCount = int.Parse(requestDocument.SelectSingleNode("/geosoft_xml/search_request/@maxcount").Value); int offset = int.Parse(requestDocument.SelectSingleNode("/geosoft_xml/search_request/@offset").Value); BoundingBox aoiFilter = null; XmlElement boundingBoxElement = requestDocument.SelectSingleNode("/geosoft_xml/search_request/bounding_box") as XmlElement; if (boundingBoxElement != null) { aoiFilter = new BoundingBox(double.Parse(boundingBoxElement.GetAttribute("maxx")), double.Parse(boundingBoxElement.GetAttribute("maxy")), double.Parse(boundingBoxElement.GetAttribute("minx")), double.Parse(boundingBoxElement.GetAttribute("miny"))); } string textFilter = null; XmlElement textFilterElement = requestDocument.SelectSingleNode("/geosoft_xml/search_request/text_filter") as XmlElement; if (textFilterElement != null) { textFilter = textFilterElement.InnerText; } return new SearchRequest(version, handle, offset, maxCount, aoiFilter, textFilter); }
public Stream GenerateSingleImage(string strServerType, string strServer, string strLayer, string strBBox, double dMinX, double dMinY, double dMaxX, double dMaxY) { strServerType = HttpUtility.UrlDecode(strServerType); strServer = HttpUtility.UrlDecode(strServer); strLayer = HttpUtility.UrlDecode(strLayer); BoundingBox oViewBounds; BoundingBox oLayerBounds = new BoundingBox(dMaxX, dMaxY, dMinX, dMinY); System.Diagnostics.Debug.Assert(oLayerBounds.MaxX >= oLayerBounds.MinX); System.Diagnostics.Debug.Assert(oLayerBounds.MaxY >= oLayerBounds.MinY); LayerInfo oLayer = new LayerInfo(strServerType, strServer, strLayer); #region // Input checking oViewBounds = ParseBBoxToken(strBBox); if (oViewBounds == null) { ReportStatusCode(HttpStatusCode.BadRequest); return null; } System.Diagnostics.Debug.Assert(oViewBounds.MaxX >= oViewBounds.MinX); System.Diagnostics.Debug.Assert(oViewBounds.MaxY >= oViewBounds.MinY); #endregion byte[] oImage = oLayer.GetCompositeImage(oLayerBounds, oViewBounds); if (oImage != null) { return new MemoryStream(oImage); } else { ReportStatusCode(HttpStatusCode.NotFound); return null; } }
/// <summary> /// Get the list of datasets for a particular path /// </summary> /// <param name="oServer"></param> /// <param name="strHierarchy"></param> /// <param name="iTimestamp"></param> /// <param name="oBounds"></param> /// <param name="bAOIFilter"></param> /// <param name="bTextFilter"></param> /// <param name="strSearchString"></param> /// <returns>true if server's cache version changed or some other error occured</returns> internal bool bGetDatasetList(Server oServer, string strHierarchy, int iTimestamp, BoundingBox oBounds, bool bAOIFilter, bool bTextFilter, string strSearchString) { string strEdition; System.Xml.XmlDocument oDoc = null; string strKey = oServer.Url + ':' + strHierarchy; if (!bAOIFilter && !bTextFilter) oDoc = oServer.Command.GetCatalog(strHierarchy, 1, 0, 0, null, null, null); else if (!bAOIFilter && bTextFilter) oDoc = oServer.Command.GetCatalog(strHierarchy, 1, 0, 0, strSearchString, null, null); else if (bAOIFilter && !bTextFilter) oDoc = oServer.Command.GetCatalog(strHierarchy, 1, 0, 0, null, oBounds, null); else if (bAOIFilter && bTextFilter) oDoc = oServer.Command.GetCatalog(strHierarchy, 1, 0, 0, strSearchString, oBounds, null); if (bTextFilter) strKey += "_" + strSearchString; if (bAOIFilter) strKey += "_" + oBounds.GetHashCode().ToString(CultureInfo.InvariantCulture); string strFile = Path.Combine(oServer.CacheDir, strKey.GetHashCode().ToString(CultureInfo.InvariantCulture) + ".dap_datasetlist.gz"); FolderDatasetList oDataset = FolderDatasetList.Parse(oServer, strKey, iTimestamp, oDoc, out strEdition); if (strEdition != oServer.CacheVersion) { oServer.UpdateConfiguration(); return false; } if (oDataset != null) { try { if (File.Exists(strFile)) File.Delete(strFile); // --- Use SOAP formatting and GZip compression to disk --- // --- This way we have a nice human readable format and --- // --- we may later move caching to database based. --- SoapFormatter formatter = new SoapFormatter(); using (Stream stream = new FileStream(strFile, FileMode.Create, FileAccess.Write, FileShare.None)) { using (GZipStream compStream = new GZipStream(stream, CompressionMode.Compress, true)) { formatter.Serialize(compStream, oDataset); compStream.Close(); stream.Close(); } } } catch { } } return true; }
public SearchRequest(string version, string handle, int offset, int maxCount, BoundingBox aoiFilter, string textFilter) { Version = version; Handle = handle; Offset = offset; MaxCount = maxCount; AoIFilter = aoiFilter; TextFilter = textFilter; }
public Stream GenerateTileKml(String strServerType, String strServer, String strLayer, int iLevel, int iCol, int iRow, double dMinX, double dMinY, double dMaxX, double dMaxY) { strServerType = HttpUtility.UrlDecode(strServerType); strServer = HttpUtility.UrlDecode(strServer); strLayer = HttpUtility.UrlDecode(strLayer); TileInfo oTile = new TileInfo(iLevel, iCol, iRow); BoundingBox oLayerBounds = new BoundingBox(dMaxX, dMaxY, dMinX, dMinY); System.Diagnostics.Debug.Assert(oLayerBounds.MaxX >= oLayerBounds.MinX); System.Diagnostics.Debug.Assert(oLayerBounds.MaxY >= oLayerBounds.MinY); WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml"; return TileKmlGenerator.GenerateTileKml(strServerType, strServer, strLayer, oTile, oLayerBounds); }
public static Uri BindTileKmlUriTemplate(Uri oBaseAddress, String strServerType, String strServer, String strLayer, TileInfo oTile, BoundingBox oLayerBounds) { UriTemplate oTemplate = new UriTemplate(TileKmlUriTemplate); NameValueCollection oParameters = new NameValueCollection(); oParameters.Add("serverType", HttpUtility.UrlEncode(strServerType)); oParameters.Add("server", HttpUtility.UrlEncode(strServer)); oParameters.Add("layer", HttpUtility.UrlEncode(strLayer)); oParameters.Add("level", oTile.Level.ToString(CultureInfo.InvariantCulture)); oParameters.Add("col", oTile.Column.ToString(CultureInfo.InvariantCulture)); oParameters.Add("row", oTile.Row.ToString(CultureInfo.InvariantCulture)); oParameters.Add("minx", oLayerBounds.MinX.ToString(CultureInfo.InvariantCulture)); oParameters.Add("miny", oLayerBounds.MinY.ToString(CultureInfo.InvariantCulture)); oParameters.Add("maxx", oLayerBounds.MaxX.ToString(CultureInfo.InvariantCulture)); oParameters.Add("maxy", oLayerBounds.MaxY.ToString(CultureInfo.InvariantCulture)); return oTemplate.BindByName(oBaseAddress, oParameters); }
/// <summary> /// Default construct /// </summary> public DataSet() { m_hBoundingBox = new BoundingBox(); m_szUrl = String.Empty; }
/// <summary> /// Encode the request to translate a bounding box from one coordinate system to another /// </summary> /// <param name="szHandle">The handle which uniquly identifies this request/response pair</param> /// <param name="hBoundingBox">The bounding box to translate</param> /// <param name="hOutputCoordinateSystem">The destination coordinate system</param> /// <param name="dResolution">The current resolution that you wish to have translated to the new coordinate system</param> /// <returns>The GeosoftXML request</returns> public System.Xml.XmlDocument TranslateBoundingBox(string szHandle, BoundingBox hBoundingBox, CoordinateSystem hOutputCoordinateSystem, double dResolution) { // --- Create required Nodes --- System.Xml.XmlAttribute hAttr; System.Xml.XmlElement hTranslateBoundingBoxNode = CreateRequest(szHandle, Constant.Tag.TRANSLATE_BOUNDING_BOX_TAG); System.Xml.XmlNode hBoundingBoxNode; // --- Setup hierchy --- hBoundingBoxNode = AddBoundingBox(hTranslateBoundingBoxNode, hBoundingBox); AddCoordinateSystem(hBoundingBoxNode, hBoundingBox.CoordinateSystem); AddCoordinateSystem(hTranslateBoundingBoxNode, hOutputCoordinateSystem); // --- Add attributes --- if (dResolution != 0) { System.Xml.XmlElement hResolutionNode = hTranslateBoundingBoxNode.OwnerDocument.CreateElement(Constant.Tag.RESOLUTION_TAG); hAttr = hTranslateBoundingBoxNode.OwnerDocument.CreateAttribute(Constant.Attribute.VALUE_ATTR); hAttr.Value = dResolution.ToString(System.Globalization.CultureInfo.InvariantCulture); hResolutionNode.SetAttributeNode(hAttr); hTranslateBoundingBoxNode.AppendChild(hResolutionNode); } return hTranslateBoundingBoxNode.OwnerDocument; }
/// <summary> /// Encode the request to translate a bounding box from one coordinate system to another /// </summary> /// <param name="szHandle">The handle which uniquly identifies this request/response pair</param> /// <param name="hBoundingBox">The bounding box to translate</param> /// <param name="hOutputCoordinateSystem">The destination coordinate system</param> /// <returns>The GeosoftXML request</returns> public System.Xml.XmlDocument TranslateBoundingBox(string szHandle, BoundingBox hBoundingBox, CoordinateSystem hOutputCoordinateSystem) { return TranslateBoundingBox(szHandle, hBoundingBox, hOutputCoordinateSystem, 0); }
/// <summary> /// Encode the request to get an image of a list of datasets /// </summary> /// <param name="szHandle">The handle which uniquly identifies this request/response pair</param> /// <param name="hFormat">The format of the image</param> /// <param name="hBoundingBox">The area of the iamge</param> /// <param name="hResolution">The hieght and width of the image</param> /// <param name="bBaseMap">Draw the base map</param> /// <param name="bIndexMap">Draw the index map</param> /// <param name="hItems">The list of unique dataset names to draw</param> /// <returns>The GeosoftXML request</returns> public System.Xml.XmlDocument Image(string szHandle, Format hFormat, BoundingBox hBoundingBox, Resolution hResolution, bool bBaseMap, bool bIndexMap, ArrayList hItems) { // --- Create required nodes --- System.Xml.XmlAttribute hAttr; System.Xml.XmlElement hGetImageNode = CreateRequest(szHandle, Constant.Tag.IMAGE_TAG); System.Xml.XmlElement hFormatNode = hGetImageNode.OwnerDocument.CreateElement(Constant.Tag.FORMAT_TAG); System.Xml.XmlElement hResolutionNode = hGetImageNode.OwnerDocument.CreateElement(Constant.Tag.RESOLUTION_TAG); System.Xml.XmlElement hLayersNode = hGetImageNode.OwnerDocument.CreateElement(Constant.Tag.LAYERS_TAG); System.Xml.XmlNode hBoundingBoxNode; // --- Setup hierchy --- hGetImageNode.AppendChild(hFormatNode); hGetImageNode.AppendChild(hResolutionNode); hGetImageNode.AppendChild(hLayersNode); hBoundingBoxNode = AddBoundingBox(hGetImageNode, hBoundingBox); AddCoordinateSystem(hBoundingBoxNode, hBoundingBox.CoordinateSystem); if (hFormat.Type != null && hFormat.Type.Length != 0) { hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.TYPE_ATTR); hAttr.Value = hFormat.Type; hFormatNode.SetAttributeNode(hAttr); } if (hFormat.Transparent) { hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.TRANSPARENT_ATTR); hAttr.Value = "TRUE"; hFormatNode.SetAttributeNode(hAttr); } if (hFormat.Background != null && hFormat.Background.Length != 0) { hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.BACKGROUND_ATTR); hAttr.Value = hFormat.Background; hFormatNode.SetAttributeNode(hAttr); } hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.WIDTH_ATTR); hAttr.Value = hResolution.Width.ToString(); hResolutionNode.SetAttributeNode(hAttr); hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.HEIGHT_ATTR); hAttr.Value = hResolution.Height.ToString(); hResolutionNode.SetAttributeNode(hAttr); hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.BASE_MAP_ATTR); hAttr.Value = bBaseMap.ToString(); hLayersNode.SetAttributeNode(hAttr); hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.INDEX_MAP_ATTR); hAttr.Value = bIndexMap.ToString(); hLayersNode.SetAttributeNode(hAttr); foreach (Object item in hItems) { System.Xml.XmlElement hDataSetNode = hGetImageNode.OwnerDocument.CreateElement(Constant.Tag.DATASET_TAG); hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.NAME_ATTR); hAttr.Value = item.ToString(); hDataSetNode.SetAttributeNode(hAttr); hLayersNode.AppendChild(hDataSetNode); } return hGetImageNode.OwnerDocument; }
/// <summary> /// Get a list of all the datasets stored by the dap server /// Note: No hierarchy information is retained /// </summary> /// <param name="szPath">A path to filter the result set by. Eg. /folder1/folder2/@datasetname</param> /// <param name="iDepth">Number of levels to recurse down. Only valid if szPath is used</param> /// <param name="iStartIndex">The index of the first dataset to return</param> /// <param name="iMaxResults">The maximum number of datasets to return</param> /// <param name="szKeywords">Filter results based on these keywords. NOTE: Each keyword is seperated by a space</param> /// <param name="hBoundingBox">Filter results based on this bounding box</param> /// <param name="hDataSets">The list of datasets</param> /// <param name="progressCallBack">Progress handler (may be null)</param> public void GetCatalog(string szPath, int iDepth, int iStartIndex, int iMaxResults, string szKeywords, BoundingBox hBoundingBox, out System.Collections.ArrayList hDataSets, UpdateProgessCallback progressCallBack) { string szUrl; System.Xml.XmlDocument hRequestDocument; System.Xml.XmlDocument hResponseDocument; try { m_oLock.AcquireReaderLock(-1); szUrl = CreateUrl(Constant.Request.CATALOG); hRequestDocument = m_hEncodeRequest.Catalog(null, false, szPath, iDepth, iStartIndex, iMaxResults, szKeywords, hBoundingBox); hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack); m_hParse.Catalog(hResponseDocument, out hDataSets); } finally { m_oLock.ReleaseReaderLock(); } }
/// <summary> /// Refresh the catalog based on the new aoi /// </summary> internal void FilterChanged(SearchModeEnum eMode, BoundingBox searchExtents, string strSearch, bool bAOIFilter, bool bTextFilter) { bool bChanged = false; // --- the catalog filter changed, do we need to do something --- if (m_bAOIFilter && m_oCatalogBoundingBox != searchExtents) { m_oCatalogBoundingBox = new Geosoft.Dap.Common.BoundingBox(searchExtents); bChanged = true; } if (m_bTextFilter && (m_strSearchString != m_strCurSearchString || m_eMode != m_ePrevMode)) { m_strSearchString = m_strCurSearchString; m_ePrevMode = m_eMode; bChanged = true; } if (bChanged || m_bAOIFilter != m_bPrevAOIFilter || m_bTextFilter != m_bPrevTextFilter) { ClearCatalog(); GetCatalogHierarchy(); m_bPrevAOIFilter = m_bAOIFilter; m_bPrevTextFilter = m_bTextFilter; } }
/// <summary> /// Invalidate drawing area until we get the results back /// </summary> internal void SetupCatalog(BoundingBox searchExtents) { if (m_oCurServer.MajorVersion < 6 || (m_oCurServer.MajorVersion == 6 && m_oCurServer.MinorVersion < 3)) m_bEntireCatalogMode = true; else m_bEntireCatalogMode = false; ClearCatalog(); if (searchExtents != null) m_oCatalogBoundingBox = new Geosoft.Dap.Common.BoundingBox(searchExtents); EnqueueRequest(AsyncRequestType.GetCatalogHierarchy); }
/// <summary> /// Extended constructor /// </summary> /// <param name="hBox">Bounding Box to copy</param> public BoundingBox(BoundingBox hBox) { m_dMaxX = hBox.m_dMaxX; m_dMaxY = hBox.m_dMaxY; m_dMaxZ = hBox.m_dMaxZ; m_dMinX = hBox.m_dMinX; m_dMinY = hBox.m_dMinY; m_dMinZ = hBox.m_dMinZ; // --- set the default coordinate system to WGS 84 --- m_hCoordinateSystem = new CoordinateSystem(hBox.CoordinateSystem); }
public Layer(float releavance, string serverTitle, string layerTitle, string serverDescription, int dappleSearchLayerID, string url, BoundingBox bounds) { Relevance = releavance; ServerTitle = serverTitle; LayerTitle = layerTitle; ServerDescription = serverDescription; DappleSearchLayerID = dappleSearchLayerID; Url = url; BoundingBox = bounds; }
public static Uri PartialBindSingleImageUriTemplate(Uri oBaseAddress, String strServerType, String strServer, String strLayer, BoundingBox oLayerBounds) { UriTemplate oTemplate = new UriTemplate(SingleImageUriTemplate); NameValueCollection oParameters = new NameValueCollection(); oParameters.Add("serverType", HttpUtility.UrlEncode(strServerType)); oParameters.Add("server", HttpUtility.UrlEncode(strServer)); oParameters.Add("layer", HttpUtility.UrlEncode(strLayer)); oParameters.Add("minx", oLayerBounds.MinX.ToString(CultureInfo.InvariantCulture)); oParameters.Add("miny", oLayerBounds.MinY.ToString(CultureInfo.InvariantCulture)); oParameters.Add("maxx", oLayerBounds.MaxX.ToString(CultureInfo.InvariantCulture)); oParameters.Add("maxy", oLayerBounds.MaxY.ToString(CultureInfo.InvariantCulture)); return oTemplate.BindByName(oBaseAddress, oParameters); }
/// <summary> /// Parse the translate bounding box response. /// </summary> /// <param name="hDocument">The GeosoftXML response</param> /// <param name="hBoundingBox">The translated bounding box coordinates</param> /// <param name="dResolution">The translated resolution</param> public void TranslateBoundingBox(System.Xml.XmlDocument hDocument, out BoundingBox hBoundingBox, out Double dResolution) { System.Xml.XmlNode hNode; System.Xml.XmlNode hAttr; hBoundingBox = null; dResolution = 0; try { // --- find the boundingbox element located anywhere in the document --- hNode = hDocument.SelectSingleNode("//" + Constant.Tag.BOUNDING_BOX_TAG); if (hNode == null) throw new DapException("No bounding box found in translate bounding box"); this.BoundingBox(hNode, out hBoundingBox); // --- find the resolution element located anywhere in the document ---- hNode = hDocument.SelectSingleNode("//" + Constant.Tag.RESOLUTION_TAG); if (hNode != null) { hAttr = hNode.Attributes.GetNamedItem(Constant.Attribute.VALUE_ATTR); if (hAttr != null) dResolution = Double.Parse(hAttr.Value, System.Globalization.CultureInfo.InvariantCulture); } } catch (Exception e) { throw new DapException("Error translating bounding box", e); } }
internal FolderDatasetList GetDatasets(Server oServer, CatalogFolder oFolder, BoundingBox oBounds, bool bAOIFilter, bool bTextFilter, string strSearchString) { FolderDatasetList oRet = null; string strKey = oServer.Url + ':' + oFolder.Hierarchy; if (bTextFilter) strKey += "_" + strSearchString; if (bAOIFilter) strKey += "_" + oBounds.GetHashCode().ToString(CultureInfo.InvariantCulture); string strFile = Path.Combine(oServer.CacheDir, strKey.GetHashCode().ToString(CultureInfo.InvariantCulture) + ".dap_datasetlist.gz"); if (File.Exists(strFile)) { try { // --- Use SOAP formatting and GZip compression to disk --- // --- This way we have a nice human readable format and --- // --- we may later move caching to database based. --- SoapFormatter formatter = new SoapFormatter(); formatter.Binder = new FolderDatasetListDeserializationBinder(); using (Stream stream = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (GZipStream compStream = new GZipStream(stream, CompressionMode.Decompress)) { oRet = (FolderDatasetList)formatter.Deserialize(compStream); compStream.Close(); stream.Close(); } } } catch { oRet = null; try { if (File.Exists(strFile)) File.Delete(strFile); } catch (IOException) { } // Bug report where this delete failed; suppress failed deletions. } } if (oRet != null && oRet.Timestamp == oFolder.Timestamp && strKey == oRet.Key) return oRet; return null; }
/// <summary> /// Get the root catalog hierarchy for a particular path /// </summary> /// <param name="oServer"></param> /// <param name="oBounds"></param> /// <param name="bAOIFilter"></param> /// <param name="bTextFilter"></param> /// <param name="strSearchString"></param> /// <returns>The hierarchy as a CatalogFolder</returns> internal CatalogFolder GetCatalogHierarchyRoot(Server oServer, BoundingBox oBounds, bool bAOIFilter, bool bTextFilter, string strSearchString, out bool bEntireCatalogMode, out string strEdition) { XmlDocument oDoc = null; strEdition = ""; bEntireCatalogMode = false; string strKey = oServer.Url; if (bTextFilter) strKey += "_" + strSearchString; if (bAOIFilter) strKey += "_" + oBounds.GetHashCode().ToString(CultureInfo.InvariantCulture); string strFile = Path.Combine(oServer.CacheDir, strKey.GetHashCode().ToString(CultureInfo.InvariantCulture) + ".dap_cataloghierarchy.gz"); if (File.Exists(strFile)) { try { // --- Use GZip compression to disk --- using (Stream stream = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (GZipStream compStream = new GZipStream(stream, CompressionMode.Decompress)) { oDoc = new XmlDocument(); oDoc.Load(compStream); compStream.Close(); stream.Close(); CatalogFolder oCatalogFolder = CatalogFolder.Parse(oDoc, out strEdition); if (oCatalogFolder != null && strEdition == oServer.CacheVersion) return oCatalogFolder; oDoc = null; } } } catch { oDoc = null; if (File.Exists(strFile)) File.Delete(strFile); } } if (oDoc == null) { try { if (!bAOIFilter && !bTextFilter) oDoc = oServer.Command.GetCatalogHierarchy(); else if (!bAOIFilter && bTextFilter) oDoc = oServer.Command.GetCatalogHierarchy(strSearchString); else if (bAOIFilter && !bTextFilter) oDoc = oServer.Command.GetCatalogHierarchy(oBounds); else if (bAOIFilter && bTextFilter) oDoc = oServer.Command.GetCatalogHierarchy(strSearchString, oBounds); } catch (DapException) { // Assume the server is older bEntireCatalogMode = true; return null; } catch { oDoc = null; } if (oDoc == null) { // --- do something to disable server --- #if !DAPPLE m_oServerTree.NoResponseError(); #else if (m_oServerTree != null) m_oServerTree.NoResponseError(oServer); #endif return null; } #if DAPPLE // --- Looks like the server is online now --- if (m_oServerTree != null) m_oServerTree.ReenableServer(oServer); #endif CatalogFolder oCatalogFolder = CatalogFolder.Parse(oDoc, out strEdition); if (oCatalogFolder == null) { // --- check to see if this is an unknown request --- System.Xml.XmlNodeList oNodeList; System.Xml.XmlNode oNode; oNodeList = oDoc.SelectNodes("//" + Geosoft.Dap.Xml.Common.Constant.Tag.ERROR_TAG); if (oNodeList != null && oNodeList.Count > 0) { oNode = oNodeList[0]; if (oNode != null && oNode.InnerText.ToLower() == "unknown request.") bEntireCatalogMode = true; } } else { if (strEdition != oServer.CacheVersion) { oServer.UpdateConfiguration(); return null; } try { if (File.Exists(strFile)) File.Delete(strFile); // --- Use GZip compression to disk --- using (Stream stream = new FileStream(strFile, FileMode.Create, FileAccess.Write, FileShare.None)) { using (GZipStream compStream = new GZipStream(stream, CompressionMode.Compress, true)) { XmlWriter writer = XmlWriter.Create(compStream); oDoc.Save(writer); compStream.Close(); stream.Close(); } } } catch { } return oCatalogFolder; } } return null; }
/// <summary> /// Transform the bounding box xml element to its corresponding structure. /// </summary> /// <param name="hBoundingBoxNode">The GeosoftXML Bounding Box node</param> /// <param name="hBoundingBox">The bounding box structure to populate</param> public void BoundingBox(System.Xml.XmlNode hBoundingBoxNode, out BoundingBox hBoundingBox) { // --- initialize the coordinates to the boundarys of the world in WGS 84 --- double dMaxX = 180; double dMaxY = 90; double dMinX = -180; double dMinY = -90; hBoundingBox = new BoundingBox(dMaxX, dMaxY, dMinX, dMinY); // --- if it is null, then just default to the world --- if (hBoundingBoxNode == null) return; // --- bad tag given, generate an error --- if (hBoundingBoxNode.Name != Xml.Common.Constant.Tag.BOUNDING_BOX_TAG) { throw new DapException("Invalid format found in bounding box element."); } System.Xml.XmlNode hMaxX = hBoundingBoxNode.Attributes.GetNamedItem(Constant.Attribute.MAX_X_ATTR); System.Xml.XmlNode hMaxY = hBoundingBoxNode.Attributes.GetNamedItem(Constant.Attribute.MAX_Y_ATTR); System.Xml.XmlNode hMinX = hBoundingBoxNode.Attributes.GetNamedItem(Constant.Attribute.MIN_X_ATTR); System.Xml.XmlNode hMinY = hBoundingBoxNode.Attributes.GetNamedItem(Constant.Attribute.MIN_Y_ATTR); if (hMaxX != null) hBoundingBox.MaxX = Double.Parse(hMaxX.Value, System.Globalization.CultureInfo.InvariantCulture); if (hMaxY != null) hBoundingBox.MaxY = Double.Parse(hMaxY.Value, System.Globalization.CultureInfo.InvariantCulture); if (hMinX != null) hBoundingBox.MinX = Double.Parse(hMinX.Value, System.Globalization.CultureInfo.InvariantCulture); if (hMinY != null) hBoundingBox.MinY = Double.Parse(hMinY.Value, System.Globalization.CultureInfo.InvariantCulture); }
/// <summary> /// Check to see if two BoundingBoxes intersect. /// </summary> /// <param name="other">The BoundingBox to test against this one.</param> /// <returns>True if there is some overlap of the two BoundingBoxes, false otherwise.</returns> public bool Intersects(BoundingBox other) { if (other.MinY >= this.MaxY || other.MaxY <= this.MinY || other.MinX >= this.MaxX || other.MaxX <= this.MinX) { return false; } else { return true; } }
/// <summary> /// Encode the request for the catalog from a Dap server /// </summary> /// <param name="szHandle">The handle which uniquly identifies this request/response pair</param> /// <param name="bCount">Wether to return the catalog or just the number of items that match this query</param> /// <param name="szPath">An xpath string to limit the returned catalog</param> /// <param name="iDepth">Number of levels to recurse down. Only valid if szPath is used</param> /// <param name="iStartIndex">The start index of the first dataset you wish returned</param> /// <param name="iMaxResults">The maximum number of datasets you wish returned</param> /// <param name="szKeywords">The keywords to filter datasets by.</param> /// <param name="hBoundingBox">The area that must intersect a dataset bounding box in order for it to be returned</param> /// <returns>The GeosoftXML request</returns> public System.Xml.XmlDocument Catalog(string szHandle, bool bCount, string szPath, int iDepth, int iStartIndex, int iMaxResults, string szKeywords, BoundingBox hBoundingBox) { // --- Create required nodes --- System.Xml.XmlAttribute hAttr; System.Xml.XmlElement hGetCatalogNode = CreateRequest(szHandle, Constant.Tag.CATALOG_TAG); // --- Add attributes --- hAttr = hGetCatalogNode.OwnerDocument.CreateAttribute(Constant.Attribute.COUNT_ATTR); hAttr.Value = bCount.ToString(); hGetCatalogNode.SetAttributeNode(hAttr); if (iStartIndex >= 0) { hAttr = hGetCatalogNode.OwnerDocument.CreateAttribute(Constant.Attribute.INDEX_ATTR); hAttr.Value = iStartIndex.ToString(); hGetCatalogNode.SetAttributeNode(hAttr); } if (iMaxResults > 0) { hAttr = hGetCatalogNode.OwnerDocument.CreateAttribute(Constant.Attribute.MAX_RESULTS_ATTR); hAttr.Value = iMaxResults.ToString(); hGetCatalogNode.SetAttributeNode(hAttr); } if (szKeywords != null && szKeywords.Length > 0) { hAttr = hGetCatalogNode.OwnerDocument.CreateAttribute(Constant.Attribute.KEYWORDS_ATTR); hAttr.Value = szKeywords; hGetCatalogNode.SetAttributeNode(hAttr); } if (hBoundingBox != null) { System.Xml.XmlNode hBoundingBoxNode = AddBoundingBox(hGetCatalogNode, hBoundingBox); AddCoordinateSystem(hBoundingBoxNode, hBoundingBox.CoordinateSystem); } if (szPath != null) { System.Xml.XmlElement hCatalogNode = hGetCatalogNode.OwnerDocument.CreateElement(Constant.Tag.FILTER_TAG); hAttr = hGetCatalogNode.OwnerDocument.CreateAttribute(Constant.Attribute.PATH_ATTR); hAttr.Value = szPath; hCatalogNode.SetAttributeNode(hAttr); hAttr = hGetCatalogNode.OwnerDocument.CreateAttribute(Constant.Attribute.DEPTH_ATTR); hAttr.Value = iDepth.ToString(); hCatalogNode.SetAttributeNode(hAttr); hGetCatalogNode.AppendChild(hCatalogNode); } return hGetCatalogNode.OwnerDocument; }
/// <summary> /// Refresh the catalog based on the new aoi /// </summary> internal virtual void AsyncFilterChanged(SearchModeEnum eMode, BoundingBox searchExtents, string strSearch, bool bAOIFilter, bool bTextFilter) { m_eMode = eMode; m_bAOIFilter = bAOIFilter; m_bTextFilter = bTextFilter; CreateSearchString(strSearch); EnqueueRequest(ServerTree.AsyncRequestType.FilterChanged, (object)ServerTree.SearchModeEnum.All, (object)searchExtents, (object)strSearch, (object)bAOIFilter, (object)bTextFilter); }
/// <summary> /// Encode BOUNDING_BOX element /// </summary> /// <param name="oParent">The parent node</param> /// <param name="hBoundingBox">The bounding box to encode</param> /// <returns>BOUNDNG_BOX element</returns> private System.Xml.XmlNode AddBoundingBox(System.Xml.XmlElement oParent, BoundingBox hBoundingBox) { System.Xml.XmlAttribute hAttr; System.Xml.XmlElement hNode = oParent.OwnerDocument.CreateElement(Constant.Tag.BOUNDING_BOX_TAG); hAttr = oParent.OwnerDocument.CreateAttribute(Constant.Attribute.MAX_X_ATTR); hAttr.Value = hBoundingBox.MaxX.ToString(System.Globalization.CultureInfo.InvariantCulture); hNode.SetAttributeNode(hAttr); hAttr = oParent.OwnerDocument.CreateAttribute(Constant.Attribute.MAX_Y_ATTR); hAttr.Value = hBoundingBox.MaxY.ToString(System.Globalization.CultureInfo.InvariantCulture); hNode.SetAttributeNode(hAttr); hAttr = oParent.OwnerDocument.CreateAttribute(Constant.Attribute.MIN_X_ATTR); hAttr.Value = hBoundingBox.MinX.ToString(System.Globalization.CultureInfo.InvariantCulture); hNode.SetAttributeNode(hAttr); hAttr = oParent.OwnerDocument.CreateAttribute(Constant.Attribute.MIN_Y_ATTR); hAttr.Value = hBoundingBox.MinY.ToString(System.Globalization.CultureInfo.InvariantCulture); hNode.SetAttributeNode(hAttr); oParent.AppendChild(hNode); return hNode; }
/// <summary> /// Log the user into the current server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> internal bool Login(BoundingBox searchExtents) { bool bRet = true; if (m_oCurServer == null) return false; // --- ensure we only attempt to login 1 at a time --- lock (m_oLoginLock) { // --- Set the Server Token --- m_oCurServer.SetServerToken(); // --- if we are successfully logged in, then get the data from the dap server --- if (bRet) { // Show all servers in Dapple, there is no other way to manage the list of servers SelectServer(m_oFullServerList[m_oCurServer.Url]); SetupCatalog(searchExtents); } OnServerLoggedIn(m_oCurServer); } return bRet; }
/// <summary> /// Encode the request for the catalog hierarchy from a Dap server /// </summary> /// <param name="szHandle">The handle which uniquly identifies this request/response pair</param> /// <param name="oBox">The bounding are to filter the hierarchy on</param> /// <param name="strQueryString">The query string to filter the hierarchy on</param> /// <returns>The GeosoftXML request</returns> public System.Xml.XmlDocument CatalogHierarchy(string szHandle, string strQueryString, BoundingBox oBox) { // --- Create required nodes --- System.Xml.XmlElement hGetCatalogNode = CreateRequest(szHandle, Constant.Tag.CATALOG_HIERARCHY_TAG); System.Xml.XmlAttribute hAttr; if (strQueryString != null && strQueryString.Length > 0) { hAttr = hGetCatalogNode.OwnerDocument.CreateAttribute(Constant.Attribute.KEYWORDS_ATTR); hAttr.Value = strQueryString; hGetCatalogNode.SetAttributeNode(hAttr); } if (oBox != null) { System.Xml.XmlNode hBoundingBoxNode = AddBoundingBox(hGetCatalogNode, oBox); AddCoordinateSystem(hBoundingBoxNode, oBox.CoordinateSystem); } return hGetCatalogNode.OwnerDocument; }
public static MemoryStream GenerateTileKml(String strServerType, String strServer, String strLayer, TileInfo oTile, BoundingBox oLayerBounds) { BoundingBox oBoundsForThisFile = oTile.Bounds; MemoryStream result = new MemoryStream(); XmlWriter oOutputWriter = XmlWriter.Create(result); oOutputWriter.WriteStartElement("kml", "http://www.opengis.net/kml/2.2"); oOutputWriter.WriteStartElement("Document"); oOutputWriter.WriteElementString("name", String.Format(CultureInfo.CurrentCulture, "Level {0}, Column {1}, Row {2}", oTile.Level, oTile.Column, oTile.Row)); oOutputWriter.WriteStartElement("Region"); oOutputWriter.WriteStartElement("LatLonAltBox"); oOutputWriter.WriteElementString("north", oBoundsForThisFile.MaxY.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteElementString("south", oBoundsForThisFile.MinY.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteElementString("east", oBoundsForThisFile.MaxX.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteElementString("west", oBoundsForThisFile.MinX.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteEndElement(); //LatLonAltBox oOutputWriter.WriteStartElement("Lod"); oOutputWriter.WriteElementString("minLodPixels", "256"); oOutputWriter.WriteElementString("maxLodPixels", "-1"); oOutputWriter.WriteEndElement(); //Lod oOutputWriter.WriteEndElement(); //Region bool blIntersecion = false; for (int iDRow = 0; iDRow <= 1; iDRow++) { for (int iDCol = 0; iDCol <= 1; iDCol++) { TileInfo oSubTile = new TileInfo(oTile.Level + 1, oTile.Column * 2 + iDCol, oTile.Row * 2 + iDRow); BoundingBox oBoundsForSubTile = oSubTile.Bounds; if (oBoundsForSubTile.Intersects(oLayerBounds)) { blIntersecion = true; oOutputWriter.WriteStartElement("NetworkLink"); oOutputWriter.WriteElementString("name", String.Format(CultureInfo.InvariantCulture, "{0}{1} SubTile", iDRow == 0 ? "S" : "N", iDCol == 0 ? "W" : "E")); oOutputWriter.WriteElementString("open", "1"); oOutputWriter.WriteStartElement("Region"); oOutputWriter.WriteStartElement("LatLonAltBox"); oOutputWriter.WriteElementString("north", oBoundsForSubTile.MaxY.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteElementString("south", oBoundsForSubTile.MinY.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteElementString("east", oBoundsForSubTile.MaxX.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteElementString("west", oBoundsForSubTile.MinX.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteEndElement(); //LatLonAltBox oOutputWriter.WriteStartElement("Lod"); oOutputWriter.WriteElementString("minLodPixels", "256"); oOutputWriter.WriteElementString("maxLodPixels", "-1"); oOutputWriter.WriteEndElement(); //Lod oOutputWriter.WriteEndElement(); //Region oOutputWriter.WriteStartElement("Link"); oOutputWriter.WriteElementString("href", ContractHelper.BindTileKmlUriTemplate(ControlPanel.BaseAddress, strServerType, strServer, strLayer, oSubTile, oLayerBounds).ToString()); oOutputWriter.WriteElementString("viewRefreshMode", "onRegion"); oOutputWriter.WriteEndElement(); //Link oOutputWriter.WriteEndElement(); //NetworkLink } } } if (blIntersecion) { oOutputWriter.WriteStartElement("GroundOverlay"); oOutputWriter.WriteElementString("drawOrder", (oTile.Level + 1).ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteStartElement("Icon"); oOutputWriter.WriteElementString("href", ContractHelper.BindImageCacheUriTemplate(ControlPanel.BaseAddress, strServerType, strServer, strLayer, oTile).ToString()); oOutputWriter.WriteEndElement(); //Icon oOutputWriter.WriteStartElement("LatLonAltBox"); oOutputWriter.WriteElementString("north", oBoundsForThisFile.MaxY.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteElementString("south", oBoundsForThisFile.MinY.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteElementString("east", oBoundsForThisFile.MaxX.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteElementString("west", oBoundsForThisFile.MinX.ToString(CultureInfo.InvariantCulture)); oOutputWriter.WriteEndElement(); //LatLonAltBox oOutputWriter.WriteEndElement(); //GroundOverlay } oOutputWriter.WriteEndElement(); //Document oOutputWriter.WriteEndElement(); //kml oOutputWriter.Close(); result.Seek(0, SeekOrigin.Begin); return result; }
/// <summary> /// Encode the request to get the default resolution to extract a dataset at /// </summary> /// <param name="szHandle">The handle which uniquly identifies this request/response pair</param> /// <param name="szType">The dataset type</param> /// <param name="hBoundingBox">The bounding box to get the default resolution for</param> /// <returns>The GeosoftXML request</returns> public System.Xml.XmlDocument DefaultResolution(string szHandle, string szType, BoundingBox hBoundingBox) { // --- Create required Nodes --- System.Xml.XmlAttribute hAttr; System.Xml.XmlElement hGetDefaultResolutionNode = CreateRequest(szHandle, Constant.Tag.DEFAULT_RESOLUTION_TAG); AddBoundingBox(hGetDefaultResolutionNode, hBoundingBox); // --- Add attributes --- if (szType != null && szType.Length != 0) { hAttr = hGetDefaultResolutionNode.OwnerDocument.CreateAttribute(Constant.Attribute.TYPE_ATTR); hAttr.Value = szType; hGetDefaultResolutionNode.SetAttributeNode(hAttr); } return hGetDefaultResolutionNode.OwnerDocument; }
/// <summary> /// Encode the request to extract a dataset from a Dap server /// </summary> /// <param name="szHandle">The handle which uniquly identifies this request/response pair</param> /// <param name="hDataSetList">List of datasets to extract</param> /// <param name="hBoundingBox">The bounding region to limit the size of the extraction</param> /// <param name="bNative">Save datasets in native coordinate system or that of the bounding box</param> /// <returns>The GeosoftXML request</returns> public System.Xml.XmlDocument Extract(string szHandle, ArrayList hDataSetList, BoundingBox hBoundingBox, bool bNative) { System.Xml.XmlAttribute hAttr; System.Xml.XmlElement hExtractNode = CreateRequest(szHandle, Constant.Tag.EXTRACT_TAG); System.Xml.XmlElement hNativeNode = hExtractNode.OwnerDocument.CreateElement(Constant.Tag.NATIVE_TAG); System.Xml.XmlElement hDataSetsNode = hExtractNode.OwnerDocument.CreateElement(Constant.Tag.DATASETS_TAG); System.Xml.XmlNode hBoundingBoxNode; hExtractNode.AppendChild(hDataSetsNode); hBoundingBoxNode = AddBoundingBox(hExtractNode, hBoundingBox); AddCoordinateSystem(hBoundingBoxNode, hBoundingBox.CoordinateSystem); // --- Add attributes --- foreach (ExtractDataSet hDataSet in hDataSetList) { System.Xml.XmlElement hDataSetNode = hExtractNode.OwnerDocument.CreateElement(Constant.Tag.DATASET_TAG); hAttr = hExtractNode.OwnerDocument.CreateAttribute(Constant.Attribute.NAME_ATTR); hAttr.Value = hDataSet.DataSet.Name; hDataSetNode.SetAttributeNode(hAttr); hAttr = hExtractNode.OwnerDocument.CreateAttribute(Constant.Attribute.FORMAT_ATTR); hAttr.Value = hDataSet.Format; hDataSetNode.SetAttributeNode(hAttr); hAttr = hExtractNode.OwnerDocument.CreateAttribute(Constant.Attribute.RESOLUTION_ATTR); hAttr.Value = hDataSet.Resolution.ToString(System.Globalization.CultureInfo.InvariantCulture); hDataSetNode.SetAttributeNode(hAttr); hDataSetsNode.AppendChild(hDataSetNode); } hAttr = hExtractNode.OwnerDocument.CreateAttribute(Constant.Attribute.VALUE_ATTR); hAttr.Value = bNative.ToString(); hNativeNode.SetAttributeNode(hAttr); return hExtractNode.OwnerDocument; }
/// <summary> /// Get a list of all the datasets stored by the dap server /// Note: No hierarchy information is retained /// </summary> /// <param name="szPath">A path to filter the result set by. Eg. /folder1/folder2/@datasetname</param> /// <param name="iDepth">Number of levels to recurse down. Only valid if szPath is used</param> /// <param name="iStartIndex">The index of the first dataset to return</param> /// <param name="iMaxResults">The maximum number of datasets to return</param> /// <param name="szKeywords">Filter results based on these keywords. NOTE: Each keyword is seperated by a space</param> /// <param name="hBoundingBox">Filter results based on this bounding box</param> /// <param name="hDataSets">The list of datasets</param> public void GetCatalog(string szPath, int iDepth, int iStartIndex, int iMaxResults, string szKeywords, BoundingBox hBoundingBox, out System.Collections.ArrayList hDataSets) { GetCatalog(szPath, iDepth, iStartIndex, iMaxResults, szKeywords, hBoundingBox, out hDataSets, null); }