Exemplo n.º 1
0
        public void SplitByLatitude(double splitLat, out ShapePolyline lPly, out ShapePolyline rPly)
        {
            lPly = rPly = null;
            List <ShapeLineString> lStrings = new List <ShapeLineString>();
            List <ShapeLineString> rStrings = new List <ShapeLineString>();

            foreach (ShapeLineString str in _parts)
            {
                ShapeLineString lString = null, rString = null;
                str.SplitByLatitude(splitLat, out lString, out rString);
                if (lString != null)
                {
                    lStrings.Add(lString);
                }
                if (rString != null)
                {
                    rStrings.Add(rString);
                }
            }
            if (lStrings.Count > 0)
            {
                lPly = new ShapePolyline(lStrings.ToArray());
            }
            if (rStrings.Count > 0)
            {
                rPly = new ShapePolyline(rStrings.ToArray());
            }
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 4
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("矢量要素分割操作不支持请求的几何类型。");
     }
 }
Exemplo n.º 5
0
        private unsafe void PolylineToPath(ShapePolyline ply)
        {
            int partCount = ply.Parts.Length;

            for (int pi = 0; pi < partCount; pi++)
            {
                ShapePoint[] prjPts = ply.Parts[pi].Points;
                PointF[]     ptfs   = new PointF[prjPts.Length];
                for (int i = 0; i < ptfs.Length; i++)
                {
                    ptfs[i].X = (float)(_quickTransformArgs.kLon * prjPts[i].X + _quickTransformArgs.bLon);
                    ptfs[i].Y = (float)(_quickTransformArgs.kLat * prjPts[i].Y + _quickTransformArgs.bLat);
                }
                _path.AddLines(ptfs);
                _path.StartFigure();
            }
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 private bool HitTestByLine(ShapePolyline shapePolyline, double tolerance)
 {
     if (this is ShapePoint)
     {
         return(GeometryMathLib.GetDistance(shapePolyline, this as ShapePoint) < tolerance);
     }
     else if (this is ShapePolyline)
     {
         return(GeometryMathLib.IsCrossed2Lines(this as ShapePolyline, shapePolyline));
     }
     else if (this is ShapePolygon)
     {
         return((this as ShapePolygon).Contains(shapePolyline));
     }
     else
     {
         throw new NotSupportedException("暂不支持对\"" + this.GetType().ToString() + "\"进行点击测试。");
     }
 }
Exemplo n.º 8
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);
 }
Exemplo n.º 9
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 + "。");
     }
 }
Exemplo n.º 10
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();
        }
Exemplo n.º 11
0
 public static bool IsCrossed2Lines(ShapePolyline line1, ShapePolyline line2)
 {
     throw new NotSupportedException();
 }
Exemplo n.º 12
0
 public static double GetDistance(ShapePolyline plyline, ShapePoint hitPoint)
 {
     throw new NotSupportedException();
 }