/// <summary> /// 进行SQL查询 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnQuery_Click(object sender, EventArgs e) { try { m_listField = QueryFieldsCount(m_listField); QueryParameterSet queryParameterSet = new QueryParameterSet(); if (rdoAttribute.Checked) { queryParameterSet.QueryOption = QueryOption.ATTRIBUTE; } else { queryParameterSet.QueryOption = QueryOption.ATTRIBUTEANDGEOMETRY; } queryParameterSet.QueryParams = new QueryParameter[1]; queryParameterSet.QueryParams[0] = new QueryParameter(); queryParameterSet.QueryParams[0].Name = treeDataSet.SelectedNode.Text; if (m_listField != null) queryParameterSet.QueryParams[0].Fields = m_listField.ToArray(); queryParameterSet.QueryParams[0].AttributeFilter = txtQueryCondition.Text; queryParameterSet.ReturnContent = true; queryParameterSet.ExpectCount = Convert.ToInt32(sqlExpectCount.Text); QueryResult m_resultSet = _map.QueryBySQL(_mapName, queryParameterSet); if (m_resultSet.Recordsets == null)//查询结果为空时提示 { MessageBox.Show("结果为空", "警告", MessageBoxButtons.OK); } else { if (publicResultForm != null) publicResultForm.Close(); publicResultForm = new PublicResultForm(m_resultSet, m_mainForm); publicResultForm.Show(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void QueryTextLayerTest() { Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest"); QueryParameterSet queryParameterSet = new QueryParameterSet(); queryParameterSet.QueryOption = QueryOption.ATTRIBUTEANDGEOMETRY; queryParameterSet.QueryParams = new QueryParameter[1]; queryParameterSet.QueryParams[0] = new QueryParameter("ContinentLabel@World"); queryParameterSet.QueryParams[0].AttributeFilter = "SmID<20"; queryParameterSet.ReturnContent = true; QueryResult qr = map.QueryBySQL("世界地图", queryParameterSet); Assert.IsTrue(qr != null); }
/// <summary> /// 在指定的地图上,查找距离指定几何对象一定距离容限内最近的对象。 /// </summary> /// <param name="mapName">地图名。</param> /// <param name="geometry">几何对象。</param> /// <param name="maxDistance">容限距离。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在queryParameters.queryParams[i]中进行设置。 </param> /// <returns>查询结果对象。</returns> public QueryResult FindNearest(string mapName, Geometry geometry, double maxDistance, QueryParameterSet queryParameterSet) { if (string.IsNullOrEmpty(mapName)) throw new ArgumentNullException("mapName", Resources.ArgumentIsNotNull); QueryResource qrResource = new QueryResource(); if (queryParameterSet != null && queryParameterSet.QueryParams != null) { qrResource.QueryParameters = queryParameterSet; } else { throw new ArgumentNullException("queryParameterSet", Resources.ArgumentIsNotNull); } if (maxDistance > 0) { qrResource.Distance = maxDistance; } else { throw new ArgumentNullException("maxDistance", Resources.ArgumentMoreThanZero); } qrResource.QueryMode = "FindNearest"; qrResource.Geometry = geometry; return QueryInternal(mapName, qrResource); }
/// <summary> /// 在指定的地图上,查询与指定的几何对象符合某种空间关系和查询条件的几何对象。 /// </summary> /// <param name="mapName">地图名。</param> /// <param name="geometry">几何对象。</param> /// <param name="spatialQueryMode">空间几何对象间的查询模式 /// <para>空间几何对象间的查询模式定义了一些几何对象之间的空间位置关系,根据这些空间关系来构建过滤条件执行查询。</para> /// <example>查询可被包含在面对象中的空间对象,与面有相离或者相邻关系的空间对象等。</example> /// </param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在queryParameters.queryParams[i]中进行设置。 </param> /// <returns>查询结果集。</returns> public QueryResult QueryByGeometry(string mapName, Geometry geometry, SpatialQueryMode spatialQueryMode, QueryParameterSet queryParameterSet) { if (string.IsNullOrEmpty(mapName)) throw new ArgumentNullException("mapName", Resources.ArgumentIsNotNull); QueryResource qrResource = new QueryResource(); if (geometry != null) { qrResource.Geometry = geometry; } else { throw new ArgumentNullException("geometry", Resources.ArgumentIsNotNull); } if (queryParameterSet != null && queryParameterSet.QueryParams != null) { qrResource.QueryParameters = queryParameterSet; } else { throw new ArgumentNullException("queryParameterSet", Resources.ArgumentIsNotNull); } qrResource.QueryMode = "SpatialQuery"; qrResource.SpatialQueryMode = spatialQueryMode.ToString(); return QueryInternal(mapName, qrResource); }
/// <summary> /// 在指定的地图上,查询距离指定几何对象一定范围内的几何对象。 /// </summary> /// <param name="mapName">地图名。</param> /// <param name="geometry">几何对象。</param> /// <param name="distance">查询的距离范围。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在 queryParameters.queryParams[i] 中进行设置。 /// </param> /// <returns>查询结果集。</returns> /// <remarks>到指定几何对象的一定距离范围,实际是以指定几何对象为中心的一个圆,在这个圆内以及与圆相交的几何对象都能够被查询出来。 /// </remarks> public QueryResult QueryByDistance(string mapName, Geometry geometry, double distance, QueryParameterSet queryParameterSet) { if (string.IsNullOrEmpty(mapName)) throw new ArgumentNullException("mapName", Resources.ArgumentIsNotNull); QueryResource qrResource = new QueryResource(); if (geometry != null) { qrResource.Geometry = geometry; } else { throw new ArgumentNullException("geometry", Resources.ArgumentIsNotNull); } if (distance > 0) { qrResource.Distance = distance; } else { throw new ArgumentOutOfRangeException("distance", Resources.ArgumentMoreThanZero); } if (queryParameterSet != null && queryParameterSet.QueryParams != null) { qrResource.QueryParameters = queryParameterSet; } else { throw new ArgumentNullException("queryParameterSet", Resources.ArgumentIsNotNull); } qrResource.QueryMode = "DistanceQuery"; return QueryInternal(mapName, qrResource); }
/// <summary> /// 在指定的地图上,查询与指定的矩形范围以及符合某种空间关系和查询条件的几何对象。 /// </summary> /// <param name="mapName">地图名。</param> /// <param name="bounds">矩形范围。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在 queryParameters.queryParams[i] 中进行设置。 </param> /// <returns>查询结果集。</returns> public QueryResult QueryByBounds(string mapName, Rectangle2D bounds, QueryParameterSet queryParameterSet) { if (string.IsNullOrEmpty(mapName)) throw new ArgumentNullException("mapName", Resources.ArgumentIsNotNull); QueryResource qrResource = new QueryResource(); if (queryParameterSet != null && queryParameterSet.QueryParams != null) { qrResource.QueryParameters = queryParameterSet; } else { throw new ArgumentNullException("queryParameterSet", Resources.ArgumentIsNotNull); } qrResource.QueryMode = "BoundsQuery"; if (bounds != null) { qrResource.Bounds = bounds; } else { throw new ArgumentNullException("bounds", Resources.ArgumentIsNotNull); } return QueryInternal(mapName, qrResource); }
/// <summary> /// 在指定的地图上,执行 SQL 查询。 /// </summary> /// <param name="mapName">地图名。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在queryParameters.queryParams[i]中进行设置。 </param> /// <returns>查询结果集。</returns> public QueryResult QueryBySQL(string mapName, QueryParameterSet queryParameterSet) { if (string.IsNullOrEmpty(mapName)) throw new ArgumentNullException("mapName", Resources.ArgumentIsNotNull); QueryResource qrResource = new QueryResource(); if (queryParameterSet != null && queryParameterSet.QueryParams != null) { qrResource.QueryParameters = queryParameterSet; } else { throw new ArgumentNullException("queryParameterSet", Resources.ArgumentIsNotNull); } qrResource.QueryMode = "SqlQuery"; return QueryInternal(mapName, qrResource); }
/// <summary> /// 在指定的地图上,查询距离指定几何对象一定范围内的几何对象。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="geometry">几何对象。</param> /// <param name="distance">查询的距离范围。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在 queryParameters.queryParams[i] 中进行设置。 /// </param> /// <returns>查询结果集。</returns> /// <remarks>到指定几何对象的一定距离范围,实际是以指定几何对象为中心的一个圆,在这个圆内以及与圆相交的几何对象都能够被查询出来。 /// </remarks> public QueryResult QueryByDistance(string mapName, Geometry geometry, double distance, QueryParameterSet queryParameterSet) { return _mapProvider.QueryByDistance(mapName, geometry, distance, queryParameterSet); }
/// <summary> /// 使用异步的方式查询一定范围内的几何对象。此方法不会阻止调用线程。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="geometry">几何对象</param> /// <param name="distance">查询的距离范围。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在 queryParameters.queryParams[i] 中进行设置。</param> /// <param name="completed">在服务端查询完成后时执行的方法。</param> /// <param name="failed">在进行查询时发生异常后执行的方法。</param> public void QueryByDistance(string mapName, Geometry geometry, double distance, QueryParameterSet queryParameterSet, EventHandler<QueryEventArgs> completed, EventHandler<FailedEventArgs> failed) { if (string.IsNullOrEmpty(mapName)) { if (failed != null) failed(this, new FailedEventArgs(new ArgumentNullException("mapName", Resources.ArgumentIsNotNull))); return; } if (queryParameterSet == null) { if (failed != null) { failed(this, new FailedEventArgs(new ArgumentNullException("queryParameterSet", Resources.ArgumentIsNotNull))); } return; } if (geometry == null) { if (failed != null) failed(this, new FailedEventArgs(new ArgumentNullException("geometry", Resources.ArgumentIsNotNull))); return; } if (distance <= 0.0) { if (failed != null) failed(this, new FailedEventArgs(new ArgumentOutOfRangeException("distance", Resources.ArgumentMoreThanZero))); return; } _mapProvider.QueryByDistance(mapName, geometry, distance, queryParameterSet, completed, failed); }
/// <summary> /// 在指定的地图上,查询与指定的矩形范围以及符合某种空间关系和查询条件的几何对象。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="bounds">矩形范围。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在 queryParameters.queryParams[i] 中进行设置。 </param> /// <returns>查询结果集。</returns> public QueryResult QueryByBounds(string mapName, Rectangle2D bounds, QueryParameterSet queryParameterSet) { return _mapProvider.QueryByBounds(mapName, bounds, queryParameterSet); }
/// <summary> /// 使用异步的方式,在指定的地图上,查询与指定的矩形范围以及符合某种空间关系和查询条件的几何对象。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="bounds">矩形范围。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在 queryParameters.queryParams[i] 中进行设置。 </param> /// <param name="completed"><see cref="EventHandler<QueryEventArgs>"/>委托,它表示在服务端查询完成后执行的方法。</param> /// <param name="failed"><see cref="EventHandler<FailedEventArgs>"/>类型委托,它表示在进行查询时发生异常后执行的方法。</param> public void QueryByBounds(string mapName, Rectangle2D bounds, QueryParameterSet queryParameterSet, EventHandler<QueryEventArgs> completed, EventHandler<FailedEventArgs> failed) { if (string.IsNullOrEmpty(mapName)) { if (failed != null) failed(this, new FailedEventArgs(new ArgumentNullException("mapName", Resources.ArgumentIsNotNull))); return; } if (queryParameterSet == null) { if (failed != null) { failed(this, new FailedEventArgs(new ArgumentNullException("queryParameterSet", Resources.ArgumentIsNotNull))); } return; } if (bounds == null) { if (failed != null) { failed(this, new FailedEventArgs(new ArgumentNullException("bounds", Resources.ArgumentIsNotNull))); } return; } _mapProvider.QueryByBounds(mapName, bounds, queryParameterSet, completed, failed); }
public override void OnMapMouseDoubleClick(object sender, MouseEventArgs e) { if (!_start) return; PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y); double mercatorX, mercatorY; Helper.LonLat2Mercator(currentPoint.Lng, currentPoint.Lat, out mercatorX, out mercatorY); Point2D point2D = new Point2D(mercatorX, mercatorY); _point2Ds.Add(point2D); Map map = new Map(_mapUrl); QueryParameterSet queryParameterSet = new QueryParameterSet(); queryParameterSet.ReturnContent = true; queryParameterSet.QueryOption = QueryOption; queryParameterSet.ExpectCount = this.ExceptionCount; queryParameterSet.QueryParams = new QueryParameter[this.clbLayers.CheckedItems.Count]; for (int i = 0; i < this.clbLayers.CheckedItems.Count; i++) { queryParameterSet.QueryParams[i] = new QueryParameter(); queryParameterSet.QueryParams[i].Name = (this.clbLayers.CheckedItems[i] as LayerItem).Name; } Geometry geo = new Geometry(); geo.Parts = new int[1] { 1 }; geo.Points = _point2Ds.ToArray(); QueryResult queryResult = null; try { queryResult = map.QueryByGeometry(_mapName, geo, SpatialQueryMode.INTERSECT, queryParameterSet); } catch (ServiceException serviceException) { MessageBox.Show(serviceException.Message); } ShowResultSet(queryResult); _gMapOverlay.Polygons.Clear(); _points.Clear(); _point2Ds.Clear(); flag = false; _start = false; base.OnMapMouseDoubleClick(sender, e); }
public void QueryByGeometryTest_ErrorGeometryIsNull() { Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest"); QueryParameterSet queryParameterSet = new QueryParameterSet(); queryParameterSet.QueryOption = QueryOption.ATTRIBUTE; queryParameterSet.QueryParams = new QueryParameter[1]; queryParameterSet.QueryParams[0] = new QueryParameter("CountryLabel@World"); queryParameterSet.ReturnContent = true; queryParameterSet.StartRecord = 0; queryParameterSet.ExpectCount = 20; QueryResult qr = null; try { qr = map.QueryByGeometry("世界地图", null, SpatialQueryMode.INTERSECT, queryParameterSet); } catch (ArgumentNullException e) { Assert.AreEqual(e.Message, "参数不能为空。\r\n参数名: geometry"); } }
public void QueryByGeometryTest() { Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest"); QueryParameterSet queryParameterSet = new QueryParameterSet(); queryParameterSet.QueryOption = QueryOption.ATTRIBUTE; Geometry geometry = new Geometry(); geometry.Parts = new int[1] { 5 }; geometry.Points = new Point2D[5]; geometry.Points[0] = new Point2D(-90, -45); geometry.Points[1] = new Point2D(90, -45); geometry.Points[2] = new Point2D(90, 45); geometry.Points[3] = new Point2D(-90, 45); geometry.Points[4] = new Point2D(-90, -45); geometry.Type = GeometryType.REGION; queryParameterSet.QueryParams = new QueryParameter[1]; queryParameterSet.QueryParams[0] = new QueryParameter("CountryLabel@World"); queryParameterSet.ReturnContent = true; queryParameterSet.StartRecord = 0; queryParameterSet.ExpectCount = 20; QueryResult qr = map.QueryByGeometry("世界地图", geometry, SpatialQueryMode.INTERSECT, queryParameterSet); Assert.AreEqual(qr.CurrentCount, 20); Assert.AreEqual(qr.TotalCount, 119); Assert.AreEqual(qr.Recordsets[0].Features[3].FieldValues[0], "10"); Assert.IsNull(qr.Recordsets[0].Features[1].Geometry); Assert.AreEqual(qr.Recordsets[0].DatasetName, "CountryLabel@World"); }
/// <summary> /// 初始化窗体 /// </summary> private void InitializeSQL() { treeDataSet.Nodes.Clear(); List<Layer> layers = null; if (defaultMapParameter != null) { layers = defaultMapParameter.Layers; treeDataSet.Nodes.Add(this._mapName); for (int i = 0; i < layers.Count; i++) { //if(layers[i].Queryable){ treeDataSet.Nodes[0].Nodes.Add(layers[i].Name); treeDataSet.Nodes[0].Nodes[i].Tag = "Field"; //} } } ////初始化时展开treeDataSet和lstFields treeDataSet.Nodes[0].Expand(); lstFields.Items.Clear(); lstFields.Columns[0].ListView.Items.Add("*"); lstFields.Columns[0].ListView.Items[0].SubItems.Add("All"); //m_dataSet = m_map.GetDatasetInfo(m_workspace.Datasources[0], m_workspace.Datasources[0].Datasets[0]); QueryParameterSet queryParameterSet = new QueryParameterSet(); queryParameterSet.ExpectCount = 1; queryParameterSet.QueryOption = QueryOption.ATTRIBUTE; queryParameterSet.QueryParams = new QueryParameter[1]; queryParameterSet.QueryParams[0] = new QueryParameter(); queryParameterSet.QueryParams[0].Name = layers[0].Name; queryParameterSet.ReturnContent = true; QueryResult queryResult = _map.QueryBySQL(_mapName, queryParameterSet); for (int i = 0; i < queryResult.Recordsets[0].Fields.Length; i++) { lstFields.Columns[0].ListView.Items.Add(queryResult.Recordsets[0].Fields[i]); lstFields.Columns[0].ListView.Items[i + 1].SubItems.Add(queryResult.Recordsets[0].FieldTypes[i].ToString()); } m_queryFieldFocus = true; }
/// <summary> /// 在指定的地图上,查询与指定的几何对象符合某种空间关系和查询条件的几何对象。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="geometry">几何对象。</param> /// <param name="spatialQueryMode">空间几何对象间的查询模式 /// <para>空间几何对象间的查询模式定义了一些几何对象之间的空间位置关系,根据这些空间关系来构建过滤条件执行查询。 /// 例如:查询可被包含在面对象中的空间对象,与面有相离或者相邻关系的空间对象等。</para> /// </param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在queryParameters.queryParams[i]中进行设置。 </param> /// <returns>查询结果集。</returns> public QueryResult QueryByGeometry(string mapName, Geometry geometry, SpatialQueryMode spatialQueryMode, QueryParameterSet queryParameterSet) { return _mapProvider.QueryByGeometry(mapName, geometry, spatialQueryMode, queryParameterSet); }
/// <summary> /// 选择查询字段 /// </summary> private void treeDataSet_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { lstFields.Items.Clear(); if ((string)e.Node.Tag == "Field") { lstFields.Items.Clear(); lstFields.Columns[0].ListView.Items.Add("*"); lstFields.Columns[0].ListView.Items[0].SubItems.Add("All"); //m_dataSet = m_map.GetDatasetInfo(m_workspace.Datasources[0], m_workspace.Datasources[0].Datasets[0]); QueryParameterSet queryParameterSet = new QueryParameterSet(); queryParameterSet.ExpectCount = 1; queryParameterSet.QueryOption = QueryOption.ATTRIBUTE; queryParameterSet.QueryParams = new QueryParameter[1]; queryParameterSet.QueryParams[0] = new QueryParameter(); queryParameterSet.QueryParams[0].Name = e.Node.Text; queryParameterSet.ReturnContent = true; QueryResult queryResult = _map.QueryBySQL(_mapName, queryParameterSet); if (queryResult != null && queryResult.Recordsets != null) { for (int i = 0; i < queryResult.Recordsets[0].Fields.Length; i++) { lstFields.Columns[0].ListView.Items.Add(queryResult.Recordsets[0].Fields[i]); lstFields.Columns[0].ListView.Items[i + 1].SubItems.Add(queryResult.Recordsets[0].FieldTypes[i].ToString()); } } } txtQuerySentence.Text = "Select * from " + e.Node.Text; }
/// <summary> /// 在指定的地图上,执行 SQL 查询。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在queryParameters.queryParams[i]中进行设置。 </param> /// <returns>查询结果集。</returns> public QueryResult QueryBySQL(string mapName, QueryParameterSet queryParameterSet) { return _mapProvider.QueryBySQL(mapName, queryParameterSet); }
void Map_Hold(object sender, GestureEventArgs e) { ClearQuery(); Point2D point = myMap.ScreenToMap(e.GetPosition(myMap)); double radius = 100000;//Map.Resolution * 10; Utility.Point2D p = new Utility.Point2D(point.X, point.Y); Utility.Geometry geometry = new Utility.Geometry(); geometry.Type = Utility.GeometryType.POINT; geometry.Parts = new int[] { 1 }; geometry.Points = new Utility.Point2D[1] { p }; Utility.QueryParameterSet query = new Utility.QueryParameterSet(); query.ReturnContent = true; query.ExpectCount = 1; query.QueryOption = Utility.QueryOption.ATTRIBUTEANDGEOMETRY; query.QueryParams = new Utility.QueryParameter[] { new Utility.QueryParameter("China_PreCenCity_P_Label@China400") }; _queryMap.FindNearest(mapName, geometry, radius, query, new EventHandler<Utility.QueryEventArgs>(Query_Completed), new EventHandler<Utility.FailedEventArgs>(Query_Failed)); }
/// <summary> /// 使用异步的方式,在指定的地图上,执行 SQL 查询。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在queryParameters.queryParams[i]中进行设置。 </param> /// <param name="completed">在服务端查询完成后时执行的方法。</param> /// <param name="failed">在进行查询时发生异常后执行的方法。</param> public void QueryBySQL(string mapName, QueryParameterSet queryParameterSet, EventHandler<QueryEventArgs> completed, EventHandler<FailedEventArgs> failed) { if (string.IsNullOrEmpty(mapName)) { if (failed != null) failed(this, new FailedEventArgs(new ArgumentNullException("mapName", Resources.ArgumentIsNotNull))); return; } if (queryParameterSet == null) { if (failed != null) { failed(this, new FailedEventArgs(new ArgumentNullException("queryParameterSet", Resources.ArgumentIsNotNull))); } return; } EventHandler<QueryEventArgs> callback = (sender, e) => { if (completed != null) { completed(this, e); } }; _mapProvider.QueryBySQL(mapName, queryParameterSet, callback, failed); }
public void QueryBySQL(string mapName, QueryParameterSet queryParameterSet, EventHandler<QueryEventArgs> completed, EventHandler<FailedEventArgs> failed) { QueryResource qr = BuildQueryResource(null, null, queryParameterSet, "SqlQuery", null, null); QueryInternal(mapName, qr, completed, failed); }
/// <summary> /// 在指定的地图上,查找距离指定几何对象一定距离容限内最近的对象。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="geometry">几何对象。</param> /// <param name="maxDistance">容限距离。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在queryParameters.queryParams[i]中进行设置。当查询类型为最近地物查询时,查询起始记录位置QueryParameterSet.StartRecord参数不支持。 </param> /// <returns>查询结果对象。</returns> public QueryResult FindNearest(string mapName, Geometry geometry, double maxDistance, QueryParameterSet queryParameterSet) { return _mapProvider.FindNearest(mapName, geometry, maxDistance, queryParameterSet); }
public void QueryByBounds(string mapName, Rectangle2D bounds, QueryParameterSet queryParameterSet, EventHandler<QueryEventArgs> completed, EventHandler<FailedEventArgs> failed) { QueryResource qr = BuildQueryResource(null, null, queryParameterSet, "BoundsQuery", null, bounds); QueryInternal(mapName, qr, completed, failed); }
/// <summary> /// 使用异步的方式,在指定的地图上,查找距离指定几何对象一定距离容限内最近的对象。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="geometry">几何对象。</param> /// <param name="maxDistance">容限距离。</param> /// <param name="queryParameterSet">查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在queryParameters.queryParams[i]中进行设置。当查询类型为最近地物查询时,查询起始记录位置QueryParameterSet.StartRecord参数不支持。 </param> /// <param name="completed">在服务端查询完成后时执行的方法。</param> /// <param name="failed">在进行查询时发生异常后执行的方法。</param> public void FindNearest(string mapName, Geometry geometry, double maxDistance, QueryParameterSet queryParameterSet, EventHandler<QueryEventArgs> completed, EventHandler<FailedEventArgs> failed) { if (string.IsNullOrEmpty(mapName)) { if (failed != null) { failed(this, new FailedEventArgs(new ArgumentNullException("mapName", Resources.ArgumentIsNotNull))); } return; } if (queryParameterSet == null || queryParameterSet.QueryParams == null) { if (failed != null) { failed(this, new FailedEventArgs(new ArgumentNullException("queryParameterSet", Resources.ArgumentIsNotNull))); } return; } if (maxDistance <= 0) { if (failed != null) { failed(this, new FailedEventArgs(new ArgumentNullException("maxDistance", Resources.ArgumentMoreThanZero))); } return; } EventHandler<QueryEventArgs> callback = (sender, e) => { if (completed != null) { completed(this, e); } }; _mapProvider.FindNearest(mapName, geometry, maxDistance, queryParameterSet, callback, failed); }
private QueryResource BuildQueryResource(Geometry geometry, double? distance, QueryParameterSet queryParameterSet, string queryMode, string spatialQueryMode, Rectangle2D bounds) { QueryResource qrResource = new QueryResource(); qrResource.Geometry = geometry; if (distance != null && distance > 0.0) { qrResource.Distance = distance; } qrResource.QueryParameters = queryParameterSet; qrResource.SpatialQueryMode = spatialQueryMode; qrResource.Bounds = bounds; qrResource.QueryMode = queryMode; return qrResource; }
public override void OnMapMouseUp(object sender, MouseEventArgs e) { if (!_start) return; this._gMapOverlay.Polygons.Clear(); PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y); double mecatorStartX = 0, mecatorStartY = 0; double mecatorEndX = 0, mecatorEndY = 0; Helper.LonLat2Mercator(_startPoint.Lng, _startPoint.Lat, out mecatorStartX, out mecatorStartY); Helper.LonLat2Mercator(currentPoint.Lng, currentPoint.Lat, out mecatorEndX, out mecatorEndY); double left = mecatorStartX > mecatorEndX ? mecatorEndX : mecatorStartX; double bottom = mecatorStartY > mecatorEndY ? mecatorEndY : mecatorStartY; double right = mecatorStartX > mecatorEndX ? mecatorStartX : mecatorEndX; double top = mecatorStartY > mecatorEndY ? mecatorStartY : mecatorEndY; Rectangle2D rect = new Rectangle2D(left, bottom, right, top); Geometry geo = new Geometry(rect); geo.Type = GeometryType.REGION; //MessageBox.Show(string.Format("left:{0};bottom:{1};right:{2};top{3}", left, bottom, right, top)); //List<PointLatLng> test = new List<PointLatLng>(); //double lat1, lng1; //Helper.Mercator2LonLat(rect.LeftBottom.X, rect.LeftBottom.Y, out lng1, out lat1); //test.Add(new PointLatLng(lat1, lng1)); //Helper.Mercator2LonLat(rect.LeftBottom.X, rect.RightTop.Y, out lng1, out lat1); //test.Add(new PointLatLng(lat1, lng1)); //Helper.Mercator2LonLat(rect.RightTop.X, rect.RightTop.Y, out lng1, out lat1); //test.Add(new PointLatLng(lat1, lng1)); //Helper.Mercator2LonLat(rect.RightTop.X, rect.LeftBottom.Y, out lng1, out lat1); //test.Add(new PointLatLng(lat1, lng1)); //GMapPolygonExtension testgp = new GMapPolygonExtension("", test, 2.0F, // System.Drawing.Color.FromArgb(100, 0, 0, 255), System.Drawing.Color.FromArgb(255, 255, 0, 0)); //this._gMapOverlay.Polygons.Add(testgp); QueryParameterSet queryParameterSet = new QueryParameterSet(); queryParameterSet.ReturnContent = true; queryParameterSet.QueryOption = QuerySetting.QueryOption; queryParameterSet.ExpectCount = QuerySetting.ExceptionCount; queryParameterSet.QueryParams = new QueryParameter[QuerySetting.LayerNames.Count]; for (int i = 0; i < QuerySetting.LayerNames.Count; i++) { queryParameterSet.QueryParams[i] = new QueryParameter(); queryParameterSet.QueryParams[i].Name = QuerySetting.LayerNames[i]; } QueryResult queryResult = null; try { queryResult = _map.QueryByGeometry(_mapName, geo, SpatialQueryMode.INTERSECT, queryParameterSet); } catch (ServiceException serviceException) { MessageBox.Show(serviceException.Message); } if (queryResult != null && queryResult.Recordsets != null && queryResult.Recordsets.Length > 0) { for (int i = 0; i < queryResult.Recordsets.Length; i++) { if (queryResult.Recordsets[i] != null && queryResult.Recordsets[i].Features != null && queryResult.Recordsets[i].Features.Length > 0) { for (int j = 0; j < queryResult.Recordsets[i].Features.Length; j++) { if (queryResult.Recordsets[i].Features[j].Geometry != null && ( queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.POINT || queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.TEXT)) { double lat, lng; Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[0].X, queryResult.Recordsets[i].Features[j].Geometry.Points[0].Y, out lng, out lat); PointLatLng pointLatLng = new PointLatLng(lat, lng); GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(pointLatLng); _highLightOverlay.Markers.Add(marker); } else if (queryResult.Recordsets[i].Features[j].Geometry != null && (queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.REGION || queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.RECTANGLE)) { if (queryResult.Recordsets[i].Features[j].Geometry.Parts != null) //queryResult.Recordsets[i].Features[j].Geometry.Parts.Length > 1) { int startIndex = 0; for (int k = 0; k < queryResult.Recordsets[i].Features[j].Geometry.Parts.Length; k++) { List<PointLatLng> regionClient = new List<PointLatLng>(); for (int n = startIndex; n < startIndex + queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; n++) { double lat, lng; Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[n].X, queryResult.Recordsets[i].Features[j].Geometry.Points[n].Y, out lng, out lat); regionClient.Add(new PointLatLng(lat, lng)); } GMapPolygonExtension hight = new GMapPolygonExtension("", regionClient, 2.0F, System.Drawing.Color.FromArgb(125, 255, 0, 0), System.Drawing.Color.FromArgb(50, 255, 0, 0)); _highLightOverlay.Polygons.Add(hight); startIndex += queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; } } } else if (queryResult.Recordsets[i].Features[j].Geometry != null && (queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.LINE)) { int startIndex = 0; for (int k = 0; k < queryResult.Recordsets[i].Features[j].Geometry.Parts.Length; k++) { List<PointLatLng> regionClient = new List<PointLatLng>(); for (int n = startIndex; n < queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; n++) { double lat, lng; Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[n].X, queryResult.Recordsets[i].Features[j].Geometry.Points[n].Y, out lng, out lat); regionClient.Add(new PointLatLng(lat, lng)); } GMapRouteExtension hight = new GMapRouteExtension("", regionClient, System.Drawing.Color.FromArgb(125, 255, 0, 0), 5.0F, false); _highLightOverlay.Routes.Add(hight); startIndex += queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; } } } } } } _start = false; base.OnMapMouseUp(sender, e); }
public void QueryByGeometry(string mapName, Geometry geometry, SpatialQueryMode spatialQueryMode, QueryParameterSet queryParameterSet, EventHandler<QueryEventArgs> completed, EventHandler<FailedEventArgs> failed) { QueryResource qr = BuildQueryResource(geometry, null, queryParameterSet, "SpatialQuery", spatialQueryMode.ToString(), null); QueryInternal(mapName, qr, completed, failed); }
public override void OnMapMouseDoubleClick(object sender, MouseEventArgs e) { if (!_start) return; PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y); double mercatorX, mercatorY; Helper.LonLat2Mercator(currentPoint.Lng, currentPoint.Lat, out mercatorX, out mercatorY); Point2D point2D = new Point2D(mercatorX, mercatorY); _point2Ds.Add(point2D); Map map = new Map(_mapUrl); QueryParameterSet queryParameterSet = new QueryParameterSet(); queryParameterSet.ReturnContent = true; queryParameterSet.QueryOption = QuerySetting.QueryOption; queryParameterSet.ExpectCount = QuerySetting.ExceptionCount; queryParameterSet.QueryParams = new QueryParameter[QuerySetting.LayerNames.Count]; for (int i = 0; i < QuerySetting.LayerNames.Count; i++) { queryParameterSet.QueryParams[i] = new QueryParameter(); queryParameterSet.QueryParams[i].Name = QuerySetting.LayerNames[i]; } Geometry geo = new Geometry(); geo.Parts = new int[1] { _point2Ds.Count }; geo.Points = _point2Ds.ToArray(); geo.Type = GeometryType.REGION; QueryResult queryResult = null; try { queryResult = map.QueryByGeometry(_mapName, geo, SpatialQueryMode.INTERSECT, queryParameterSet); } catch (ServiceException serviceException) { MessageBox.Show(serviceException.Message); } //高亮显示查询结果。 if (queryResult != null && queryResult.Recordsets != null && queryResult.Recordsets.Length > 0) { for (int i = 0; i < queryResult.Recordsets.Length; i++) { if (queryResult.Recordsets[i] != null && queryResult.Recordsets[i].Features != null && queryResult.Recordsets[i].Features.Length > 0) { for (int j = 0; j < queryResult.Recordsets[i].Features.Length; j++) { if (queryResult.Recordsets[i].Features[j].Geometry != null && ( queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.POINT || queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.TEXT)) { double lat, lng; Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[0].X, queryResult.Recordsets[i].Features[j].Geometry.Points[0].Y, out lng, out lat); PointLatLng pointLatLng = new PointLatLng(lat, lng); GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(pointLatLng); _highLightOverlay.Markers.Add(marker); } else if (queryResult.Recordsets[i].Features[j].Geometry != null && (queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.REGION || queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.RECTANGLE)) { if (queryResult.Recordsets[i].Features[j].Geometry.Parts != null) //queryResult.Recordsets[i].Features[j].Geometry.Parts.Length > 1) { int startIndex = 0; for (int k = 0; k < queryResult.Recordsets[i].Features[j].Geometry.Parts.Length; k++) { List<PointLatLng> regionClient = new List<PointLatLng>(); for (int n = startIndex; n < queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; n++) { double lat, lng; Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[n].X, queryResult.Recordsets[i].Features[j].Geometry.Points[n].Y, out lng, out lat); regionClient.Add(new PointLatLng(lat, lng)); } GMapPolygonExtension hight = new GMapPolygonExtension("", regionClient, 2.0F, System.Drawing.Color.FromArgb(125, 255, 0, 0), System.Drawing.Color.FromArgb(50, 255, 0, 0)); _highLightOverlay.Polygons.Add(hight); startIndex += queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; } } } else if (queryResult.Recordsets[i].Features[j].Geometry != null && (queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.LINE)) { int startIndex = 0; for (int k = 0; k < queryResult.Recordsets[i].Features[j].Geometry.Parts.Length; k++) { List<PointLatLng> regionClient = new List<PointLatLng>(); for (int n = startIndex; n < startIndex + queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; n++) { double lat, lng; Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[n].X, queryResult.Recordsets[i].Features[j].Geometry.Points[n].Y, out lng, out lat); regionClient.Add(new PointLatLng(lat, lng)); } GMapRouteExtension hight = new GMapRouteExtension("", regionClient, System.Drawing.Color.FromArgb(125, 255, 0, 0), 5.0F, false); _highLightOverlay.Routes.Add(hight); startIndex += queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; } } } } } } _gMapOverlay.Polygons.Clear(); _points.Clear(); _point2Ds.Clear(); flag = false; _start = false; base.OnMapMouseDoubleClick(sender, e); }
public void FindNearest(string mapName, Geometry geometry, double maxDistance, QueryParameterSet queryParameterSet, EventHandler<QueryEventArgs> completed, EventHandler<FailedEventArgs> failed) { QueryResource qr = BuildQueryResource(geometry, maxDistance, queryParameterSet, "FindNearest", null, null); QueryInternal(mapName, qr, completed, failed); }
public void QueryByGeometryTest_Default() { Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest"); QueryParameterSet queryParameterSet = new QueryParameterSet(); queryParameterSet.QueryOption = QueryOption.ATTRIBUTE; Geometry geometry = new Geometry(); geometry.Parts = new int[1] { 5 }; geometry.Points = new Point2D[5]; geometry.Points[0] = new Point2D(-45, -90); geometry.Points[1] = new Point2D(-45, 90); geometry.Points[2] = new Point2D(45, 90); geometry.Points[3] = new Point2D(45, -90); geometry.Points[4] = new Point2D(-45, -90); geometry.Type = GeometryType.REGION; queryParameterSet.QueryParams = new QueryParameter[1]; queryParameterSet.QueryParams[0] = new QueryParameter("CountryLabel@World"); QueryResult qr = map.QueryByGeometry("世界地图", geometry, SpatialQueryMode.CONTAIN, queryParameterSet); Assert.IsNull(qr.Recordsets); Assert.IsTrue(qr.ResourceInfo.Succeed); Assert.IsNotNull(qr.ResourceInfo.NewResourceID); Assert.IsNull(qr.ResourceInfo.Bounds); Assert.IsNotNull(qr.ResourceInfo.NewResourceLocation); Assert.AreEqual(qr.TotalCount, 0); }