QueryByGeometry() public method

在指定的地图上,查询与指定的几何对象符合某种空间关系和查询条件的几何对象。
public QueryByGeometry ( string mapName, Geometry geometry, SpatialQueryMode spatialQueryMode, QueryParameterSet queryParameterSet ) : QueryResult
mapName string 地图名称。
geometry Geometry 几何对象。
spatialQueryMode SpatialQueryMode 空间几何对象间的查询模式 /// 空间几何对象间的查询模式定义了一些几何对象之间的空间位置关系,根据这些空间关系来构建过滤条件执行查询。 /// 例如:查询可被包含在面对象中的空间对象,与面有相离或者相邻关系的空间对象等。 ///
queryParameterSet SuperMap.Connector.Utility.QueryParameterSet 查询参数集。可对某个地图的多个图层进行查询,单个图层的查询参数在queryParameters.queryParams[i]中进行设置。
return SuperMap.Connector.Utility.QueryResult
        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 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);
        }
Beispiel #3
0
 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");
 }
Beispiel #4
0
 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");
     }
 }
Beispiel #5
0
 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);
 }