Example #1
0
        public void SplitByLatitude(double splitLat, out ShapePolygon lPly, out ShapePolygon rPly)
        {
            lPly = rPly = null;
            List <ShapeRing> lRings = new List <ShapeRing>();
            List <ShapeRing> rRings = new List <ShapeRing>();

            foreach (ShapeRing ring in _rings)
            {
                ShapeRing lRing = null, rRing = null;
                ring.SplitByLatitude(splitLat, out lRing, out rRing);
                if (lRing != null)
                {
                    lRings.Add(lRing);
                }
                if (rRing != null)
                {
                    rRings.Add(rRing);
                }
            }
            if (lRings.Count > 0)
            {
                lPly = new ShapePolygon(lRings.ToArray());
            }
            if (rRings.Count > 0)
            {
                rPly = new ShapePolygon(rRings.ToArray());
            }
        }
Example #2
0
        /// <summary>
        /// 使用斜率截距快速算法
        /// 以全球国家为例:220毫秒
        /// </summary>
        /// <param name="ply"></param>
        private unsafe void PolygonToPath(ShapePolygon ply)
        {
            float kLon      = _quickTransformArgs.kLon;
            float kLat      = _quickTransformArgs.kLat;
            float bLon      = _quickTransformArgs.bLon;
            float bLat      = _quickTransformArgs.bLat;
            int   ringCount = ply.Rings.Length;

            for (int ri = 0; ri < ringCount; ri++)
            {
                ShapePoint[] prjPts = ply.Rings[ri].Points;
                int          nCount = prjPts.Length;
                PointF[]     pts    = new PointF[nCount];
                fixed(PointF *ptr0 = pts)
                {
                    PointF *ptr = ptr0;

                    for (int i = 0; i < nCount; i++, ptr++)
                    {
                        ptr->X = (float)(kLon * prjPts[i].X + bLon);
                        ptr->Y = (float)(kLat * prjPts[i].Y + bLat);
                    }
                }

                _path.AddPolygon(pts);
            }
        }
Example #3
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));
        }
Example #4
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;
         }
     }
 }
Example #5
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("矢量要素分割操作不支持请求的几何类型。");
     }
 }
        private object ConstructPolygon(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)));
            }
            //rings
            ShapeRing[] rings = new ShapeRing[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];
                }
                rings[i] = new ShapeRing(rpts);
            }
            //
            ShapePolygon ply = new ShapePolygon(rings, evp);
            Feature      f   = new Feature(oid, ply, GetFieldNames(), GetFieldValues(oid), GetAnnotation(oid));

            return(f);
        }
        private void ReadBaicProperties()
        {
            if (_dbConnection.State != ConnectionState.Open)
            {
                _dbConnection.Open();
            }
            string sql = "select id,datatable,annotable," + _adapter.SQLToWktForShapeField("envelope") + ",featurecount,shapetype from " + BudGISMetadata.cstFeatureClassTableName +
                         " t where datatable = '" + _fetclassName + "'";

            using (IDbCommand cmd = _dbConnection.CreateCommand())
            {
                cmd.CommandText = sql;
                using (IDataReader dr = cmd.ExecuteReader())
                {
                    if (dr.Read())
                    {
                        _id        = _adapter.DrToString(dr, 0);
                        _datatable = _adapter.DrToString(dr, 1);
                        _annotable = _adapter.DrToString(dr, 2);
                        //
                        ShapePolygon ply = _adapter.DrToShape(dr, 3) as ShapePolygon;
                        if (ply != null)
                        {
                            ShapeRing ring = ply.Rings[0];
                            _envelope = new Envelope(ring.Points[0].X, ring.Points[2].Y, ring.Points[1].X, ring.Points[0].Y);
                        }
                        //
                        _fetCount = _adapter.DrToInt32(dr, 4);
                        //
                        string shapeTypeStr = _adapter.DrToString(dr, 5);
                        foreach (enumShapeType st in Enum.GetValues(typeof(enumShapeType)))
                        {
                            if (st.ToString() == shapeTypeStr.ToString())
                            {
                                _shapeType = st;
                                break;
                            }
                        }
                        //
                    }
                    else
                    {
                        throw new Exception("要素类\"" + _fetclassName + "\"在指定的空间数据库中不存在。");
                    }
                }
            }
        }
Example #8
0
        private Int32 CalculateMainfileLengthInByte(Feature[] vf)
        {
            Int32 TmpLength = 0;

            if (vf[0].Geometry is ShapePoint)
            {
                TmpLength += 28 * vf.Length;
            }
            else if (vf[0].Geometry is ShapeMultiPoint)
            {
                foreach (Feature tvf in vf)
                {
                    TmpLength += 48 + (tvf.Geometry as ShapeMultiPoint).Points.Length * 16;
                }
            }
            else if (vf[0].Geometry is ShapePolyline)
            {
                //points?
                ShapePolyline polyLine = null;
                foreach (Feature tvf in vf)
                {
                    polyLine   = tvf.Geometry as ShapePolyline;
                    TmpLength += 52 + polyLine.Parts.Length * 4;
                    foreach (ShapeLineString pt in polyLine.Parts)
                    {
                        TmpLength += pt.Points.Length * 16;
                    }
                }
            }
            else if (vf[0].Geometry is ShapePolygon)
            {
                ShapePolygon polygon = null;
                foreach (Feature tvf in vf)
                {
                    polygon    = tvf.Geometry as ShapePolygon;
                    TmpLength += 52 + polygon.Rings.Length * 4;
                    foreach (ShapeRing sr in polygon.Rings)
                    {
                        TmpLength += sr.Points.Length * 16;
                    }
                }
            }
            _currentShpRecondLength += TmpLength;
            return(_currentShpRecondLength + 100);
        }
Example #9
0
 private bool HitTestByPolygon(ShapePolygon shapePolygon)
 {
     if (this is ShapePoint)
     {
         return(shapePolygon.Contains(this as ShapePoint));
     }
     else if (this is ShapePolyline)
     {
         return(shapePolygon.Contains(this as ShapePolyline));
     }
     else if (this is ShapePolygon)
     {
         return(shapePolygon.Contains(this as ShapePolygon));
     }
     else
     {
         throw new NotSupportedException("暂不支持对\"" + this.GetType().ToString() + "\"进行点击测试。");
     }
 }
Example #10
0
 public override bool Contains(Shape geometry)
 {
     if (!Envelope.Contains(geometry.Envelope))
     {
         return(false);
     }
     if (geometry is ShapePoint)
     {
         return(GeometryMathLib.IsPointInPolygon(geometry as ShapePoint, this));
     }
     else if (geometry is ShapePolyline)
     {
         ShapePolyline line = geometry as ShapePolyline;
         foreach (ShapeLineString part in line.Parts)
         {
             foreach (ShapePoint pt in part.Points)
             {
                 if (!GeometryMathLib.IsPointInPolygon(pt, this))
                 {
                     return(false);
                 }
             }
         }
         return(true);
     }
     else if (geometry is ShapePolygon)
     {
         ShapePolygon ply = geometry as ShapePolygon;
         foreach (ShapeRing ring in ply.Rings)
         {
             foreach (ShapePoint pt in ring.Points)
             {
                 if (!GeometryMathLib.IsPointInPolygon(pt, this))
                 {
                     return(false);
                 }
             }
         }
         return(true);
     }
     return(false);
 }
Example #11
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 + "。");
     }
 }
Example #12
0
        public void TryProject(IGrid grid)
        {
            if (_currentRuntimeProjecter == null)
            {
                return;
            }
            //
            if (!grid.CoordIsConverted)
            {
                _currentRuntimeProjecter.Project(grid.GridEnvelope);
                grid.CoordIsConverted = true;
            }
            //
            if (grid.VectorFeatures == null || grid.VectorFeatures.Count == 0)
            {
                return;
            }
            Shape shape = null;

            Feature[] fets = grid.VectorFeatures.ToArray();
            int       n    = fets.Length;
            Feature   fet  = null;

            for (int i = 0; i < n; i++)
            {
                fet = fets[i];
                //
                fet.SetFeatureClass(this);
                //
                if (fet.Projected)
                {
                    continue;
                }
                //annotations
                if (fet.Annotations != null)
                {
                    foreach (LabelLocation loc in fet.Annotations)
                    {
                        _currentRuntimeProjecter.Project(loc.Location);
                    }
                }
                //
                Envelope newEnvelope = new Envelope(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue);
                shape = fet.Geometry;
                if (shape == null || shape.IsProjected)
                {
                    continue;
                }
                shape.IsProjected = true;
                shape.Envelope    = newEnvelope;
                if (shape is ShapePoint)
                {
                    _currentRuntimeProjecter.Project(shape as ShapePoint);
                    UpdateEnvelopeByPoints(newEnvelope, new ShapePoint[] { shape as ShapePoint });
                    shape.UpdateCentroid();
                }
                else if (shape is ShapePolyline)
                {
                    ShapePolyline line = shape as ShapePolyline;
                    foreach (ShapeLineString part in line.Parts)
                    {
                        _currentRuntimeProjecter.Project(part.Points);
                        UpdateEnvelopeByPoints(newEnvelope, part.Points);
                    }
                    line.UpdateCentroid();
                }
                else if (shape is ShapePolygon)
                {
                    ShapePolygon ply = shape as ShapePolygon;
                    foreach (ShapeRing ring in ply.Rings)
                    {
                        _currentRuntimeProjecter.Project(ring.Points);
                        UpdateEnvelopeByPoints(newEnvelope, ring.Points);
                    }
                    ply.UpdateCentroid();
                }
                if (fet.LabelLocationService == null)
                {
                    fet.SetLabelLocationService(new LabelLocationServiceDefault(null));
                }
                fet.LabelLocationService.Update(fet.Geometry);
                fet.Projected = true;
            }
            (grid as Grid).UpdateEnvelope();
        }