Beispiel #1
0
    const float pLimit = .002f;    //Minimum sharpness prominence to be included as a vertex --Lewi-- Updated this to .5f. We were getting a ton of verticies.
    void SimplifyCurrent()
    {
        //Debug.Log(currentPositions.Count.ToString());
        Vector3[] pos   = currentPositions.ToArray();
        int       count = currentPositions.Count;

        float[] sharpness = new float[count];
        int     min       = 0;
        float   speed     = 0;

        for (int i = 0; i < count; ++i)
        {
            speed += Vector3.Distance(pos[(i + count - 1) % count], pos[i]);
        }
        speed /= count;

        for (int i = 0; i < count; ++i)
        {
            Vector3 p = pos[(i + count - 1) % count];
            Vector3 n = pos[(i + 1) % count];
            Vector3 v = pos[i];
            sharpness[i] = Vector3.AngleBetween(v - p, n - v) / (1 + (p - n).sqrMagnitude) * speed;
            if (sharpness[i] < sharpness[min])
            {
                min = i;
            }
        }

        List <TopoPoint> tPoints = new List <TopoPoint>();

        for (int i = 0; i < count; ++i)
        {
            int p = (i + min + count - 1) % count;
            int n = (i + min + 1) % count;
            int v = (i + min) % count;
            if (sharpness[v] < sharpness[p] == sharpness[v] < sharpness[n])
            {
                TopoPoint t = new TopoPoint();
                t.pos        = pos[v];
                t.height     = sharpness[v];
                t.prominence = 0;
                tPoints.Add(t);
            }
        }

        tPoints[0].parent = tPoints[0];
        TopoPoint[] tArr = tPoints.ToArray();
        TopoTree(tArr, 0, 0);

        currentPositions = new List <Vector3>();
        foreach (TopoPoint t in tArr)
        {
            if (t.prominence >= pLimit)
            {
                currentPositions.Add(t.pos);
            }
        }
    }
Beispiel #2
0
        public TopoObject Build()
        {
            TopoObject obj;

            switch (_type)
            {
            case "Point":
                obj = new TopoPoint(_type, _coordinates);
                break;

            case "LineString":
                obj = new TopoLineString(_type, _arcs);
                break;

            case "Polygon":
                obj = new TopoPolygon(_type, _arcs);
                break;

            case "MultiPoint":
                obj = new TopoMultiPoint(_type, _coordinates);
                break;

            case "MultiLineString":
                obj = new TopoMultiLineString(_type, _arcs);
                break;

            case "MultiPolygon":
                obj = new TopoMultiPolygon(_type, _arcs);
                break;

            case "GeometryCollection":
                obj = new TopoCollection(_type, _geometries);
                break;

            default:
                throw new ArgumentOutOfRangeException("unhandled type: " + _type);
            }
            obj.Id         = _id;
            obj.Properties = _properties;
            return(obj);
        }
Beispiel #3
0
 private void agisControl_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     MouseLocation = e.Location;
     GridDivisionScreenRefresh();
     if (this.UserOperation != UserOperationType.DisplayInGrid ||
         GridDivisionCount_X * EachGridDivisionCount_X < 1 ||
         GridDivisionCount_Y * EachGridDivisionCount_Y < 1 ||
         this.IsGridVisible == false)
     {
         return;
     }
     if (e.Clicks == 2 && this.IsQueryIntersection == true && this.ShowTopology == false && this.IsGridVisible == true)
     {
         SelectPointX = SelectPointY = -1;
         int gridScreen_AxisX_count = GridScreen_AxisX.Count;
         for (int i = 0; i < gridScreen_AxisX_count; i++)
         {
             if (Math.Abs(GridScreen_AxisX[i] - this.MouseLocation.X) < this.SelectPixelThreshold)
             {
                 SelectPointX = this.agisControl.GetRealWorldLocX((float)GridScreen_AxisX[i]);
             }
         }
         int gridScreen_AxisY_count = GridScreen_AxisY.Count;
         for (int i = 0; i < gridScreen_AxisY_count; i++)
         {
             if (Math.Abs(GridScreen_AxisY[i] - this.MouseLocation.Y) < this.SelectPixelThreshold)
             {
                 SelectPointY = this.agisControl.GetRealWorldLocY((float)GridScreen_AxisY[i]);
             }
         }
         //选中了格网点
         if (SelectPointX != -1 && SelectPointY != -1 && agisControl.GridIntMethod != Mehtod.GridInterpolationMehtod.None)
         {
             this.agisControl.Refresh();
             string MethodName = "";
             string Para       = "";
             if (agisControl.GridIntMethod == Mehtod.GridInterpolationMehtod.方位加权平均法)
             {
                 if (agisControl.方位加权平均法SectorNum < 0)
                 {
                     MessageBox.Show("按方位加权平均法 参数尚未设置", "错误"); return;
                 }
                 MethodName = "按方位加权平均法";
                 Para       = string.Format("{0}:{1}", "每个象限等分扇区数N0", agisControl.方位加权平均法SectorNum / 4);
             }
             else if (agisControl.GridIntMethod == Mehtod.GridInterpolationMehtod.距离平方倒数法)
             {
                 if (agisControl.距离平方倒数法NearPts < 0)
                 {
                     MessageBox.Show("距离平方倒数法 参数尚未设置", "错误"); return;
                 }
                 MethodName = "距离平方倒数法";
                 Para       = string.Format("{0}:{1}", "选取距插值点最近的N个点", agisControl.距离平方倒数法NearPts);
             }
             MessageBox.Show(string.Format("{0}\t\r\nX:{1}\t\nY:{2}\t\r\nValue:{3}\r\n\r\n{4}\r\n{5}",
                                           "格网点属性信息:", SelectPointX.ToString("0.00"), SelectPointY.ToString("0.00"),
                                           agisControl.GetGridInterpolationValue(SelectPointX, SelectPointY).ToString("0.000"),
                                           "插值方法:" + MethodName, Para
                                           ), "属性查询");
         }
     }
     if (e.Clicks == 2 && this.IsQueryTopoPolygon == true && this.ShowTopology == true && this.ShowTopoPolygon == true)
     {
         TopoPoint clickLoc = new TopoPoint(agisControl.GetRealWorldLocX(e.X), agisControl.GetRealWorldLocX(e.Y), 0, false);
         this.SelectedTopoPolygon = this.mTopoPolygonSet.GetClickPointInsidePolygon(clickLoc);
         this.agisControl.Refresh();
         if (SelectedTopoPolygon != null)
         {
             MessageBox.Show(string.Format("PID:{0}\r\n弧段数:{1}\r\n周长:{2}\r\n面积:{3}",
                                           SelectedTopoPolygon.PID, SelectedTopoPolygon.TopologyArcs.Count,
                                           SelectedTopoPolygon.GetPerimeter().ToString("0.00"),
                                           SelectedTopoPolygon.GetArea().ToString("0.00")), "多边形信息");
         }
     }
 }
Beispiel #4
0
 public PointF GetScreenPoint(TopoPoint point)
 {
     return(new PointF((float)((point.X - this.OffsetX) * this.Zoom),
                       (float)(this.Height - ((point.Y - this.OffsetY) * this.Zoom))));
 }
        public FeatureCollection Create(TopoObject data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string type = data.Type;

            if (String.IsNullOrEmpty(type))
            {
                throw new ArgumentException("type undefined", "data");
            }

            if (String.Equals("GeometryCollection", type))
            {
                // a TopoJSON "GeometryCollection" actually is an IFeature array
                // so we handle this stuff as a special case
                TopoCollection coll = (TopoCollection)data;
                return(CreateCollection(coll.Geometries));
            }

            IGeometry geometry;

            switch (type)
            {
            case "Point":
                TopoPoint point = (TopoPoint)data;
                geometry = CreatePoint(point.Coordinates);
                break;

            case "MultiPoint":
                TopoMultiPoint mpoint = (TopoMultiPoint)data;
                geometry = CreateMultiPoint(mpoint.Coordinates);
                break;

            case "LineString":
                TopoLineString lstring = (TopoLineString)data;
                geometry = CreateLineString(lstring.Arcs);
                break;

            case "MultiLineString":
                TopoMultiLineString mlstring = (TopoMultiLineString)data;
                geometry = CreateMultiLineString(mlstring.Arcs);
                break;

            case "Polygon":
                TopoPolygon poly = (TopoPolygon)data;
                geometry = CreatePolygon(poly.Arcs);
                break;

            case "MultiPolygon":
                TopoMultiPolygon mpoly = (TopoMultiPolygon)data;
                geometry = CreateMultiPolygon(mpoly.Arcs);
                break;

            default:
                string s = string.Format("type unsupported: {0}", type);
                throw new NotSupportedException(s);
            }

            IAttributesTable      properties = data.Properties;
            Feature               feature    = new Feature(geometry, properties);
            Collection <IFeature> collection = new Collection <IFeature> {
                feature
            };

            return(new FeatureCollection(collection));
        }