private bool IsPointInCurrentExtent(Feature fet, Envelope rect)
        {
            ShapePoint pt = fet.Geometry as ShapePoint;

            return(!(pt.X < rect.MinX || pt.X > rect.MaxX ||
                     pt.Y < rect.MinY || pt.Y > rect.MaxY));
        }
Exemple #2
0
        private void ComplexSplit()
        {
            _currentPointIndex = 0;
            int        pointCount = _originalPoints.Count;
            ShapePoint pt = null, prePt = null;

            while (_currentPointIndex < pointCount)
            {
                pt = _originalPoints[_currentPointIndex];
                //确定活动环集合(即:在左侧还是在右侧)
                GetActivePartCollection(pt);
                //获取活动环
                if (prePt == null)//第一次
                {
                    GetActivePart(pt, null);
                }
                else
                {
                    bool isRight1 = pt.X >= _X;
                    bool isRight2 = prePt.X >= _X;
                    if (isRight1 ^ isRight2) //不在同侧
                    {
                        GetActivePart(pt, prePt);
                    }
                }
                //加入点到活动环
                _activePart.Points.Add(pt);
                //继续处理下一个点
                prePt = pt;
                _currentPointIndex++;
            }
        }
        private PointF ShapePoint2PixelPoint(ShapePoint shapePoint)
        {
            PointF ptf = new PointF();

            ptf.X = (float)(_quickTransformArgs.kLon * shapePoint.X + _quickTransformArgs.bLon);
            ptf.Y = (float)(_quickTransformArgs.kLat * shapePoint.Y + _quickTransformArgs.bLat);
            return(ptf);
        }
Exemple #4
0
        //判断输入的两个点是否跨过了交点的Y坐标
        public bool IsCrossY(ShapePoint leftPoint, ShapePoint rightPoint)
        {
            double Y = (rightPoint.Y + leftPoint.Y) / 2d;

            return(Math.Abs(Y - Point.Y) < 0.0000001d);
            //return (leftPoint.Y < Point.Y && rightPoint.Y >= Point.Y) ||
            //          (leftPoint.Y >= Point.Y && rightPoint.Y < Point.Y);
        }
Exemple #5
0
 public override void UpdateCentroid()
 {
     if (_centroid == null)
     {
         _centroid = new ShapePoint();
     }
     _centroid._x = _x;
     _centroid._y = _y;
 }
        private object ConstructPoint(BinaryReader br, int oid)
        {
            ShapePoint pt = new ShapePoint(ToLocalEndian.ToDouble64FromLittle(br.ReadBytes(8)),
                                           ToLocalEndian.ToDouble64FromLittle(br.ReadBytes(8))
                                           );
            Feature f = new Feature(oid, pt, GetFieldNames(), GetFieldValues(oid), GetAnnotation(oid));

            return(f);
        }
Exemple #7
0
        private void GetActivePart(ShapePoint pt, ShapePoint prePoint)
        {
            CrossPoint crossPt = null;

            //获取跨分割线的交点
            if (prePoint != null)
            {
                crossPt = GetCrossPoint(pt, prePoint);
                if (crossPt == null)
                {
                    throw new Exception("获取一对点的交点失败。"); //不会出现这样的错误。
                }
            }
            //
            if (_activePartCollection.Count == 0)
            {
                _activePart = new PartStatus();
                _activePartCollection.Add(_activePart);
                goto endLine;
            }
            else
            {
                //获取相邻的环
                foreach (PartStatus part in _activePartCollection)
                {
                    bool isLessThan = false;
                    if (part.IsNear(crossPt.Index, out isLessThan))//相邻
                    {
                        if (_activePartCollection.Equals(_leftParts) && isLessThan)
                        {
                            _activePart = part;
                            goto endLine;
                        }
                        if ((_activePartCollection.Equals(_rightParts) && !isLessThan))
                        {
                            _activePart = part;
                            goto endLine;
                        }
                    }
                }
                _activePart = new PartStatus();
                //将新建的环加入活动环集合
                _activePartCollection.Add(_activePart);
                goto endLine;
            }
endLine:
            //将当前交点与活动环关联
            if (crossPt != null)
            {
                if (_prePartStatus != null)
                {
                    _prePartStatus.AddLinkeCrossPointIndex(crossPt.Index);
                }
            }
            _prePartStatus = _activePart;
        }
Exemple #8
0
        private bool CheckByPerGrid(int iLevel, Size size, Matrix transform)
        {
            int rowCount = (int)Math.Ceiling((float)size.Height / _gridSize);
            int colCount = (int)Math.Ceiling((float)size.Width / _gridSize);

            bool[,] grids = null;
            try
            {
                grids = new bool[rowCount, colCount];
            }
            catch
            {
                return(false);
            }
            //逐个要素计算所在的网格
            PointF  screenPt = new PointF();
            Feature fet      = null;

            ComputeQuickArgs(transform);
            for (int i = _features.Count - 1; i >= 0; i--)
            {
                fet = _features[i];
                ShapePoint pt = fet.Geometry.Centroid;
                screenPt.X = (float)(pt.X * _quickTranArgs.kLon + _quickTranArgs.bLon);
                screenPt.Y = (float)(pt.Y * _quickTranArgs.kLat + _quickTranArgs.bLat);
                //
                int c = Math.Min((int)Math.Ceiling(screenPt.X / _gridSize), colCount - 1);
                int r = Math.Min((int)Math.Ceiling(screenPt.Y / _gridSize), rowCount - 1);
                //
                #region debug
                //string name = fet.GetFieldValue(0);
                //if ((name == "嘉峪关市" || name == "酒泉市"))
                //{
                //    Console.WriteLine("");
                //}
                #endregion
                //如果某个网内只有一个要素,则该要素的显示级别为iLevel,否则可以按优先字段决定(暂时不实现)
                //目前实现,只要有一个已经占了该网格,其余的不允许占
                if (grids[r, c])
                {
                    continue;
                }
                else
                {
                    grids[r, c] = true;
                    if (!fet.TempFlag)
                    {
                        fet.SetFieldValue(_fieldIndexOfLevel, iLevel.ToString());
                        fet.ResetDisplayLevel();
                        fet.TempFlag = true;
                        _uncheckedCount--;
                    }
                }
            }
            return(true);
        }
Exemple #9
0
        public static bool IsPointInPolygon(ShapePoint hitPoint, ShapePolygon polygon)
        {
            int n = 0;

            foreach (ShapeRing ring in polygon.Rings)
            {
                n += ComputeCrossPointCount(hitPoint, ring.Points);
            }
            return(!(n % 2 == 0));
        }
Exemple #10
0
 private void GetActivePartCollection(ShapePoint pt)
 {
     if (pt.X >= _X)
     {
         _activePartCollection = _rightParts;
     }
     else
     {
         _activePartCollection = _leftParts;
     }
 }
Exemple #11
0
 private CrossPoint GetCrossPoint(ShapePoint pt, ShapePoint prePoint)
 {
     foreach (CrossPoint cpt in _crossPoints)
     {
         if (cpt.IsCrossY(pt, prePoint))
         {
             return(cpt);
         }
     }
     return(null);
 }
Exemple #12
0
 public override object Clone()
 {
     if (_points == null || _points.Length == 0)
     {
         return(null);
     }
     ShapePoint[] pts = new ShapePoint[_points.Length];
     for (int i = 0; i < pts.Length; i++)
     {
         pts[i] = _points[i].Clone() as ShapePoint;
     }
     return(new ShapeLineString(pts));
 }
Exemple #13
0
 private void TryHandleLongitudeRange(Feature feature)
 {
     if (feature.Geometry is ShapePolygon)
     {
         ShapePolygon ply = feature.Geometry as ShapePolygon;
         foreach (ShapeRing ring in ply.Rings)
         {
             foreach (ShapePoint pt in ring.Points)
             {
                 if (pt.X > _maxLon)
                 {
                     pt.X = _maxLon;
                 }
                 else if (pt.X < _minLon)
                 {
                     pt.X = _minLon;
                 }
             }
         }
     }
     else if (feature.Geometry is ShapePolyline)
     {
         ShapePolyline pline = feature.Geometry as ShapePolyline;
         foreach (ShapeLineString part in pline.Parts)
         {
             foreach (ShapePoint pt in part.Points)
             {
                 if (pt.X > _maxLon)
                 {
                     pt.X = _maxLon;
                 }
                 else if (pt.X < _minLon)
                 {
                     pt.X = _minLon;
                 }
             }
         }
     }
     else if (feature.Geometry is ShapePoint)
     {
         ShapePoint pt = feature.Geometry as ShapePoint;
         if (pt.X > _maxLon)
         {
             pt.X = _maxLon;
         }
         else if (pt.X < _minLon)
         {
             pt.X = _minLon;
         }
     }
 }
        private object ConstructPolylineM(BinaryReader br, int oid)
        {
            Envelope evp = new Envelope(ToLocalEndian.ToDouble64FromLittle(br.ReadBytes(8)),
                                        ToLocalEndian.ToDouble64FromLittle(br.ReadBytes(8)),
                                        ToLocalEndian.ToDouble64FromLittle(br.ReadBytes(8)),
                                        ToLocalEndian.ToDouble64FromLittle(br.ReadBytes(8)));
            int nParts  = ToLocalEndian.ToInt32FromLittle(br.ReadBytes(4));
            int nPoints = ToLocalEndian.ToInt32FromLittle(br.ReadBytes(4));

            int[] firstPoints = new int[nParts];
            for (int i = 0; i < nParts; i++)
            {
                firstPoints[i] = ToLocalEndian.ToInt32FromLittle(br.ReadBytes(4));
            }
            ShapePoint[] pts = new ShapePoint[nPoints];
            for (int i = 0; i < nPoints; i++)
            {
                pts[i] = new ShapePoint(ToLocalEndian.ToDouble64FromLittle(br.ReadBytes(8)),
                                        ToLocalEndian.ToDouble64FromLittle(br.ReadBytes(8)));
            }
            //ShapeLineString
            ShapeLineString[] Lines = new ShapeLineString[nParts];
            for (int i = 0; i < nParts; i++)
            {
                int bIdx = firstPoints[i];
                int eIdx = 0;
                if (nParts == 1 || i == nParts - 1)
                {
                    eIdx = nPoints;
                }
                else
                {
                    eIdx = firstPoints[i + 1];
                }
                ShapePoint[] rpts = new ShapePoint[eIdx - bIdx];
                for (int j = bIdx; j < eIdx; j++)
                {
                    rpts[j - bIdx] = pts[j];
                }
                Lines[i] = new ShapeLineString(rpts);
            }
            //
            br.ReadBytes(2 * 8);       //M Range
            br.ReadBytes(nPoints * 8); //M Array
            //
            ShapePolyline ply = new ShapePolyline(Lines, evp);
            Feature       f   = new Feature(oid, ply, GetFieldNames(), GetFieldValues(oid), GetAnnotation(oid));

            return(f);
        }
        private object ConstructMultiPoint(BinaryReader br, int oid)
        {
            int pointCount = ToLocalEndian.ToInt32FromLittle(br.ReadBytes(4));

            ShapePoint[] pts = new ShapePoint[pointCount];
            for (int i = 0; i < pts.Length; i++)
            {
                pts[i] = new ShapePoint(ToLocalEndian.ToDouble64FromLittle(br.ReadBytes(8)), ToLocalEndian.ToDouble64FromLittle(br.ReadBytes(8)));
            }
            ShapeMultiPoint multiPoint = new ShapeMultiPoint(pts);
            Feature         f          = new Feature(oid, multiPoint, GetFieldNames(), GetFieldValues(oid), GetAnnotation(oid));

            return(f);
        }
Exemple #16
0
        public ShapePolygon ToPolygon()
        {
            ShapePoint[] pts = new ShapePoint[]
            {
                new ShapePoint(MinX, MaxY),
                new ShapePoint(MaxX, MaxY),
                new ShapePoint(MaxX, MinY),
                new ShapePoint(MinX, MinY),
                new ShapePoint(MinX, MaxY)
            };
            ShapeRing ring = new ShapeRing(pts);

            return(new ShapePolygon(new ShapeRing[] { ring }));
        }
Exemple #17
0
 public void SplitByLongitude(double splitLon, out Feature lfet, out Feature rfet)
 {
     lfet = null;
     rfet = null;
     if (_geometry is ShapePoint)
     {
         ShapePoint pt = _geometry as ShapePoint;
         lfet          = Clone() as Feature;
         lfet.Geometry = new ShapePoint(pt.X, pt.Y);
         rfet          = null;
     }
     else if (_geometry is ShapePolyline)
     {
         ShapePolyline lLine = null, rLine = null;
         (_geometry as ShapePolyline).SplitByLongitude(splitLon, out lLine, out rLine);
         if (lLine != null)
         {
             lfet          = Clone() as Feature;
             lfet.Geometry = lLine;
         }
         //
         if (rLine != null)
         {
             rfet          = Clone() as Feature;
             rfet.Geometry = rLine;
         }
     }
     else if (_geometry is ShapePolygon)
     {
         ShapePolygon lPly = null, rPly = null;
         (_geometry as ShapePolygon).SplitByLongitude(splitLon, out lPly, out rPly);
         if (lPly != null)
         {
             lfet          = Clone() as Feature;
             lfet.Geometry = lPly;
         }
         //
         if (rPly != null)
         {
             rfet          = Clone() as Feature;
             rfet.Geometry = rPly;
         }
     }
     else
     {
         throw new NotSupportedException("矢量要素分割操作不支持请求的几何类型。");
     }
 }
Exemple #18
0
 public override bool Contains(Shape geometry)
 {
     if (geometry is ShapePoint)
     {
         ShapePoint pt = geometry as ShapePoint;
         return(Math.Abs(pt.X - X) < double.Epsilon && Math.Abs(pt.Y - Y) < double.Epsilon);
     }
     else if (geometry is ShapePolyline)
     {
         return(false);
     }
     else if (geometry is ShapePolygon)
     {
         return(false);
     }
     return(false);
 }
 public ShapePoint GetLocationByFeature(Feature fet)
 {
     lock (fet)
     {
         ShapePoint           pt   = fet.Geometry.Centroid.Clone() as ShapePoint;
         ICoordinateTransform tran = (_mapRuntime as IFeatureRenderEnvironment).CoordinateTransform;
         if ((fet.Projected && fet.FeatureClass.OriginalCoordinateType == enumCoordinateType.Geographic) ||
             fet.FeatureClass.OriginalCoordinateType == enumCoordinateType.Projection)
         {
             return(pt);
         }
         else if (!fet.Projected && fet.FeatureClass.OriginalCoordinateType == enumCoordinateType.Geographic)
         {
             tran.GeoCoord2PrjCoord(new ShapePoint[] { pt });
         }
         return(pt);
     }
 }
Exemple #20
0
        /// <summary>
        /// 计算多边形重心,假定质量分布式不均匀的
        /// </summary>
        /// <returns></returns>
        public ShapePoint GetBarycenterQualityIsNotUniformity()
        {
            ShapePoint[] _points = _rings[0].Points;
            if (_points == null || _points.Length < 3)
            {
                return(null);
            }
            int n             = _points.Length;
            int triangleCount = n - 2;

            if (triangleCount < 1)
            {
                return(null);
            }
            int i = 1;

            double[]     S       = new double[triangleCount];
            ShapePoint[] centers = new ShapePoint[triangleCount];
            while (i <= triangleCount)
            {
                ShapePoint p0 = _points[0];
                //ShapePoint p1 = _points[i + 1];
                //ShapePoint p2 = _points[i + 2];
                ShapePoint p1 = _points[i];
                ShapePoint p2 = _points[i + 1];
                //S =( x0*y1 + x1*y2 + x2*y0 - x1*y0  - x2*y1  - x0*y2 ) /2;
                S[i - 1] = 0.5d * (p0.X * p1.Y + p1.X * p2.Y + p2.X * p0.Y -
                                   p1.X * p0.Y - p2.X * p1.Y - p0.X * p2.Y);
                centers[i - 1] = new ShapePoint((p0.X + p1.X + p2.X) / 3f, (p0.Y + p1.Y + p2.Y) / 3f);
                //
                i++;
            }
            //X = ∑( xi×mi ) / ∑mi
            //Y = ∑( yi×mi ) / ∑mi
            double sumx = 0, sumy = 0, sumi = 0;

            for (int j = 0; j < S.Length; j++)
            {
                sumx += (centers[j].X * S[j]);
                sumy += (centers[j].Y * S[j]);
                sumi += S[j];
            }
            return(new ShapePoint(sumx / sumi, sumy / sumi));
        }
Exemple #21
0
        private void ComputeQuickArgs(Matrix transform)
        {
            if (_quickTranArgs == null)
            {
                _quickTranArgs = new QuickTransformArgs();
            }
            ShapePoint geoPt1 = _features[0].Geometry.Centroid;
            ShapePoint geoPt2 = _features[_features.Count - 1].Geometry.Centroid;
            PointF     prjPt1 = geoPt1.ToPointF();
            PointF     prjPt2 = geoPt2.ToPointF();

            PointF[] screenPts = new PointF[] { prjPt1, prjPt2 };
            transform.TransformPoints(screenPts);
            //
            _quickTranArgs.kLon = (screenPts[0].X - screenPts[1].X) / (prjPt1.X - prjPt2.X);
            _quickTranArgs.kLat = (screenPts[0].Y - screenPts[1].Y) / (prjPt1.Y - prjPt2.Y);
            _quickTranArgs.bLon = screenPts[0].X - _quickTranArgs.kLon * prjPt1.X;
            _quickTranArgs.bLat = screenPts[0].Y - _quickTranArgs.kLat * prjPt1.Y;
        }
        private Feature[] ConstructPoint()
        {
            List <Feature> features = new List <Feature>();
            ShapePoint     pt;

            string[] fieldValues;
            for (int oid = 0; oid < _pointCount; oid++)
            {
                fieldValues = new string[_fieldCount];
                pt          = new ShapePoint(_vectData[oid * _fieldCount + longIndex], _vectData[oid * _fieldCount + latIndex]);
                for (int j = 0; j < _fieldCount; j++)
                {
                    fieldValues[j] = _vectData[oid * _fieldCount + j].ToString();
                }
                Feature f = new Feature(oid, pt, _fields, fieldValues, null);
                features.Add(f);
            }
            return(features.ToArray());
        }
Exemple #23
0
 private bool HitTestByPoint(ShapePoint shapePoint, double tolerance)
 {
     if (this is ShapePoint)
     {
         Envelope evp = Envelope.Clone() as Envelope;
         evp = evp.Expand((float)tolerance);
         return(evp.Contains(shapePoint.Envelope));
     }
     else if (this is ShapePolyline)
     {
         return(GeometryMathLib.GetDistance(this as ShapePolyline, shapePoint) < tolerance);
     }
     else if (this is ShapePolygon)
     {
         return((this as ShapePolygon).Contains(shapePoint));
     }
     else
     {
         throw new NotSupportedException("暂不支持对\"" + this.GetType().ToString() + "\"进行点击测试。");
     }
 }
Exemple #24
0
        public static int ComputeCrossPointCount(ShapePoint hitPoint, ShapePoint[] points)
        {
            ShapePoint pt1 = null, pt2 = null;
            int        crossPointCount = 0;
            int        i = 1;

            for (; i < points.Length; i++)
            {
                pt1 = points[i - 1];
                pt2 = points[i];
                //射线和边无交点
                if ((pt1.Y < hitPoint.Y && pt2.Y < hitPoint.Y) || (pt1.Y > hitPoint.Y && pt2.Y > hitPoint.Y))
                {
                    continue;
                }
                if (hitPoint.X > pt1.X && hitPoint.X > pt2.X)
                {
                    continue;
                }
                //
                double k  = (pt2.Y - pt1.Y) / (pt2.X - pt1.X);
                double x0 = (hitPoint.Y - pt1.Y) / k + pt1.X;
                //交点射线的左半部分
                if (x0 < hitPoint.X)
                {
                    continue;
                }
                //交点在射线的右半部分
                else if (x0 > hitPoint.X)
                {
                    crossPointCount++;
                }
                //交点与顶点重合
                else
                {
                }
            }
            return(crossPointCount);
        }
Exemple #25
0
 public static Shape FromWKT(string wkt)
 {
     if (wkt == null)
     {
         return(null);
     }
     if (wkt.Contains("MULTIPOINT") || wkt.Contains("POINT"))
     {
         return(ShapePoint.FromWKT(wkt));
     }
     else if (wkt.Contains("MULTILINESTRING") || wkt.Contains("LINESTRING"))
     {
         return(ShapePolyline.FromWKT(wkt));
     }
     else if (wkt.Contains("MULTIPOLYGON") || wkt.Contains("POLYGON"))
     {
         return(ShapePolygon.FromWKT(wkt));
     }
     else
     {
         throw new NotSupportedException("不支持的几何类型或者错误的OGC WKT表达式," + wkt + "。");
     }
 }
Exemple #26
0
        public override string ToWkt()
        {
            if (_parts == null || _parts.Length == 0)
            {
                return(null);
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("MULTILINESTRING(");
            for (int i = 0; i < _parts.Length; i++)
            {
                ShapeLineString part = _parts[i];
                if (part.Points == null || part.Points.Length == 0)
                {
                    continue;
                }
                sb.Append("(");
                for (int j = 0; j < part.Points.Length; j++)
                {
                    ShapePoint pt = part.Points[j];
                    sb.Append(pt.X.ToString());
                    sb.Append(" ");
                    sb.Append(pt.Y.ToString());
                    if (j != part.Points.Length - 1)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append(")");
                if (i != _parts.Length - 1)
                {
                    sb.Append(",");
                }
            }
            sb.Append(")");
            return(sb.ToString());
        }
Exemple #27
0
        public override string ToWkt()
        {
            if (_rings == null || _rings.Length == 0)
            {
                return(null);
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("POLYGON(");
            for (int i = 0; i < _rings.Length; i++)
            {
                ShapeRing ring = _rings[i];
                if (ring.Points == null || ring.Points.Length == 0)
                {
                    continue;
                }
                sb.Append("(");
                for (int j = 0; j < ring.Points.Length; j++)
                {
                    ShapePoint pt = ring.Points[j];
                    sb.Append(pt.X.ToString());
                    sb.Append(" ");
                    sb.Append(pt.Y.ToString());
                    if (j != ring.Points.Length - 1)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append(")");
                if (i != _rings.Length - 1)
                {
                    sb.Append(",");
                }
            }
            sb.Append(")");
            return(sb.ToString());
        }
Exemple #28
0
        /// <summary>
        /// S =( -x0*y1 - x1*y2 - x2*y0
        ///      + x1*y0  + x2*y1  + x0*y2 ) /2;
        /// </summary>
        /// <returns></returns>
        public double GetArea()
        {
            if (_points == null || _points.Length < 3)
            {
                return(0);
            }
            int    nTrigangle = _points.Length - 2;
            double s          = 0;

            for (int i = 0; i < nTrigangle; i++)
            {
                ShapePoint pt0 = _points[0];
                ShapePoint pt1 = _points[i + 1];
                ShapePoint pt2 = _points[i + 2];
                s += (0.5d * (-pt0.X * pt1.Y - pt1.X * pt2.Y - pt2.X * pt0.Y +
                              pt1.X * pt0.Y + pt2.X * pt1.Y + pt0.X * pt2.Y)
                      );
            }
            if (s < 0)
            {
                Console.WriteLine(s.ToString());
            }
            return(s);
        }
 public void Focus(ShapePoint locationPrj, int times, int interval, string labelString)
 {
     if (times < 1 || locationPrj == null)
     {
         return;
     }
     _location    = locationPrj;
     _labelString = labelString;
     _isFlash     = true;
     try
     {
         for (int i = 0; i < times; i++)
         {
             _needRender = i % 2 == 0;
             _runtime.Host.RefreshContainer();
             Thread.Sleep(interval);
         }
     }
     finally
     {
         _isFlash = false;
         _runtime.MapRefresh.Render();
     }
 }
Exemple #30
0
 public void InverTransform(ShapePoint pt)
 {
     ShapePoint[] tempPts = new ShapePoint[1];
     tempPts[0] = pt;
     InverTransform(tempPts);
 }