Exemple #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());
            }
        }
Exemple #2
0
        public void SplitByLatitude(double splitLat, out ShapeRing lRing, out ShapeRing rRing)
        {
            lRing = rRing = null;
            List <ShapePoint> lPoints = new List <ShapePoint>();
            List <ShapePoint> rPoints = new List <ShapePoint>();

            foreach (ShapePoint pt in _points)
            {
                if (pt.Y > splitLat)
                {
                    rPoints.Add(pt);
                }
                else
                {
                    lPoints.Add(pt);
                }
            }
            if (lPoints.Count > 2)
            {
                lRing = new ShapeRing(lPoints.ToArray());
            }
            if (rPoints.Count > 2)
            {
                rRing = new ShapeRing(rPoints.ToArray());
            }
        }
Exemple #3
0
 public override object Clone()
 {
     if (_rings == null || _rings.Length == 0)
     {
         return(null);
     }
     ShapeRing[] rings = new ShapeRing[_rings.Length];
     for (int i = 0; i < rings.Length; i++)
     {
         rings[i] = _rings[i].Clone() as ShapeRing;
     }
     return(new ShapePolygon(rings));
 }
Exemple #4
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 }));
        }
        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 + "\"在指定的空间数据库中不存在。");
                    }
                }
            }
        }
Exemple #7
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());
        }