Example #1
0
        // 分块请求 POI
        private int requestBlockPoi(int rowNum, int colNum)
        {
            // 获取对应矢量
            int      fid      = Convert.ToInt32(city.Id);
            Geometry geometry = GisUtil.GetGeometry(fid);

            // 获取间隔
            Envelope envelope = new Envelope();

            geometry.GetEnvelope(envelope);
            double xInterval = (envelope.MaxX - envelope.MinX) / colNum;
            double yInterval = (envelope.MaxY - envelope.MinY) / rowNum;

            // 逐分块请求
            double minX;
            double minY;
            double maxX;
            double maxY;

            minY = envelope.MinY;
            for (int i = 0; i < rowNum; i++)
            {
                maxY = minY + yInterval;
                minX = envelope.MinX;
                for (int j = 0; j < colNum; j++)
                {
                    maxX = minX + xInterval;

                    int subType = GisUtil.GetEnvelopeRelationship(geometry, minX, maxX, minY, maxY);
                    if (subType > 0)
                    {
                        string   bounds = string.Format("{0},{1},{2},{3}", minY, minX, maxY, maxX);
                        Geometry geo    = null; // 不做相交判断
                        if (subType == 1)       // geometry 与子块相交
                        {
                            geo = geometry;     // 需要做相交判断
                        }
                        int page     = 0;
                        int stopFlag = 0;
                        while (stopFlag == 0)
                        {
                            stopFlag = handler.GetBoundsPageData(bounds, page, geo);
                            page++;
                        }
                        if (stopFlag < 0) // 返回错误
                        {
                            return(stopFlag);
                        }
                    }

                    minX = maxX;
                }
                minY = maxY;
            }

            return(0);
        }
Example #2
0
        public async void Work(object obj)
        {
            _map.ClearGraphic("Highlight");
            if (Once)
            {
                IsObsolete = true;
            }
            var message = "";
            var args    = obj as MapViewInputEventArgs;

            if (args != null)
            {
                var e = args;


                message = "<Document TaskGuid=\"" + Map.TaskGuid + "\" DataGuid = \"数据标识\" DataType=\"Identify\">";

                var util = new GisUtil(_map);

                if (Identifys != null)
                {
                    foreach (SingleIdentify si in Identifys)
                    {
                        var result = await util.DoIdentify(si.Service, si.Layer, e.Location);

                        if (result == null)
                        {
                            continue;
                        }

                        if (result.Results != null && result.Results.Count > 0)
                        {
                            message += "<Service ID=\"" + si.Service + "\">";
                            foreach (IdentifyItem item in result.Results)
                            {
                                _map.AddGraphic(new Graphic(item.Feature.Geometry, item.Feature.Attributes), "Highlight");

                                message += "<Item LayerID=\"" + item.LayerID + "\" LayerName=\"" + item.LayerName + "\">";
                                foreach (KeyValuePair <string, object> kv in item.Feature.Attributes)
                                {
                                    message += string.Format("<{0}>{1}</{0}>", kv.Key, kv.Value);
                                }
                                message += "</Item>";
                            }
                            message += "</Service>";
                        }
                        //break;
                    }
                }

                message += "</Document>";
            }

            Callback?.Invoke(message);
        }
Example #3
0
        public void Test_Meters()
        {
            var eastWest   = 406432730.00 / 1000.0;
            var northSouth = 4324887681.00 / 1000.0;
            var lat        = GisUtil.MetersToLatituide(eastWest);
            var lon        = GisUtil.MetersToLongitude(northSouth, lat);
            var latDegree  = 180 * lat / Math.PI;
            var lonDegree  = 180 * lon / Math.PI;

            Assert.True(lat > 0);
            Assert.True(lon > 0);
        }
Example #4
0
        // 剔除 Geometry 外的点
        private List <PoiInfo> removeOuter(List <PoiInfo> poiList, Geometry geometry)
        {
            List <PoiInfo> newPoiList = new List <PoiInfo>();

            foreach (PoiInfo poi in poiList)
            {
                if (GisUtil.IsContainsPoint(geometry, poi.Lng, poi.Lat))
                {
                    newPoiList.Add(poi);
                }
            }

            return(newPoiList);
        }
Example #5
0
        public async void SetModel(TrackModel tm)
        {
            _map.GetGraphicLayer("Drawing").IsCluster          = false;
            _map.GetGraphicLayer("Drawing").Labeling.IsEnabled = false;

            Tm = tm;
            if (tm.TrackPoints.Count < 2)
            {
                MessageBox.Show("错误的轨迹数据");
                Visibility = Visibility.Hidden;
                return;
            }
            Slider.Minimum       = 0;
            Slider.Maximum       = tm.TrackPoints.Count - 1;
            Slider.TickFrequency = 1;
            Slider.Value         = 0;
            _map.ClearGraphic("Drawing");
            _currentIndex = 0;
            _map.AddGraphic(tm.TrackLine, "Drawing");

            bool tag = false;

            foreach (Graphic g in tm.TrackPoints)
            {
                if (!tag)
                {
                    tag      = true;
                    g.Symbol = tm.StartSymbol;
                }
                _map.AddGraphic(g, "Drawing");
            }

            GisUtil util = new GisUtil(_map);

            await util.Locate(tm.TrackLine.Geometry, 20);
        }
Example #6
0
        // 点击分块建议按钮
        private void buttonBlock_Click(object sender, EventArgs e)
        {
            // 关键字
            string keyWord = getKeyWord();

            if (string.IsNullOrEmpty(keyWord))
            {
                MessageBox.Show("请输入自定义关键字");
                return;
            }

            // 获取对应矢量
            string cityName = comboBoxCity.SelectedItem.ToString();
            City   city     = CityDao.SelectByName(cityName);

            if (city == null)
            {
                MessageBox.Show("此城市没有相应的矢量数据,无法分块获取POI");
                return;
            }
            int fid = Convert.ToInt32(city.Id);

            // 开始请求
            Region region = comboBoxCity.SelectedItem as Region;

            handler = new PlaceAPIHandler(region, keyWord);
            int totalNum = handler.GetTotalNum((comboBoxProvince.SelectedItem as Region).Name);

            if (totalNum < 0) // 返回错误
            {
                MessageBox.Show(PlaceAPIHandler.GetErrMsg(totalNum));
            }
            else if (totalNum <= 400)
            {
                MessageBox.Show(string.Format("区域:{0},关键词:{1},共有 {2} 个结果,无需分块", region.Name, keyWord,
                                              totalNum));
                checkBoxBlock.Checked = false;
            }
            else // 有结果
            {
                int blockNum = totalNum / 400 + 1; // 最少分块数

                Envelope envelope = GisUtil.GetEnvelope(fid);
                double   x        = envelope.MaxX - envelope.MinX;
                double   y        = envelope.MaxY - envelope.MinY;
                int      xNum     = 1;
                int      yNum     = 1;
                if (x <= y)
                {
                    double r = y / x;
                    xNum = Convert.ToInt32(Math.Sqrt(blockNum / r)) + 1;
                    yNum = Convert.ToInt32(xNum * r) + 1;
                }
                else
                {
                    double r = x / y;
                    yNum = Convert.ToInt32(Math.Sqrt(blockNum / r)) + 1;
                    xNum = Convert.ToInt32(yNum * r) + 1;
                }
                xNum *= 2;
                yNum *= 2;

                MessageBox.Show(string.Format("区域:{0},关键词:{1},共有 {2} 个结果。建议分块为 {3} 行,{4} 列",
                                              region.Name, keyWord, totalNum, yNum, xNum));

                // 自动调整行列分块数
                if (xNum > 20)
                {
                    comboBoxBlockCol.Items.Clear();
                    for (int i = 1; i <= xNum + 10; i++)
                    {
                        comboBoxBlockCol.Items.Add(i);
                    }
                }
                comboBoxBlockCol.SelectedIndex = xNum - 1;
                if (yNum > 20)
                {
                    comboBoxBlockRow.Items.Clear();
                    for (int j = 1; j <= yNum + 10; j++)
                    {
                        comboBoxBlockRow.Items.Add(j);
                    }
                }
                comboBoxBlockRow.SelectedIndex = yNum - 1;
            }
        }
Example #7
0
        public void Test_Wgs84()
        {
            var m = GisUtil.Wgs84Transform(2.1196599980996, 0.543224178326409, 0);

            Assert.True(m != null);
        }