コード例 #1
0
 private static void GetMetric(IPolygon geom, out Interval xrange, out Interval yrange, out Interval zrange,
                               out Interval mrange)
 {
     GetMetric(geom.Shell.CoordinateSequence, out xrange, out yrange, out zrange, out mrange);
     if (geom.NumInteriorRings > 0)
     {
         for (var i = 0; i < geom.NumInteriorRings; i++)
         {
             Interval x2range, y2range, z2range, m2range;
             var      ring = geom.GetInteriorRingN(i);
             GetMetric(ring.CoordinateSequence, out x2range, out y2range, out z2range,
                       out m2range);
             xrange = xrange.ExpandedByInterval(x2range);
             yrange = yrange.ExpandedByInterval(y2range);
             if ((ring.CoordinateSequence.Ordinates & Ordinates.Z) == Ordinates.Z)
             {
                 zrange = zrange.ExpandedByInterval(z2range);
             }
             if ((ring.CoordinateSequence.Ordinates & Ordinates.M) == Ordinates.M)
             {
                 mrange = mrange.ExpandedByInterval(m2range);
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Method to read the index header using the provided reader
        /// </summary>
        /// <param name="reader">The reader to use</param>
        public void Read(BinaryReader reader)
        {
            var fileCode      = BinaryIOExtensions.ReadInt32BE(reader);
            var fileCodeIndex = BinaryIOExtensions.ReadInt32BE(reader);

            if (fileCode != FileCode || fileCodeIndex != FileCodeIndex)
            {
                throw new SbnException("Not a Shapefile index file");
            }

            reader.BaseStream.Seek(16, SeekOrigin.Current);

            FileLength = BinaryIOExtensions.ReadInt32BE(reader) * 2;
            NumRecords = BinaryIOExtensions.ReadInt32BE(reader);

            var minX = BinaryIOExtensions.ReadDoubleBE(reader);
            var minY = BinaryIOExtensions.ReadDoubleBE(reader);

            XRange = Interval.Create(minX, BinaryIOExtensions.ReadDoubleBE(reader));
            YRange = Interval.Create(minY, BinaryIOExtensions.ReadDoubleBE(reader));
            ZRange = Interval.Create(BinaryIOExtensions.ReadDoubleBE(reader), BinaryIOExtensions.ReadDoubleBE(reader));
            MRange = Interval.Create(BinaryIOExtensions.ReadDoubleBE(reader), BinaryIOExtensions.ReadDoubleBE(reader));

            reader.BaseStream.Seek(4, SeekOrigin.Current);
        }
コード例 #3
0
        internal static void GetMetric(IGeometry self,
                                       out Interval xrange, out Interval yrange,
                                       out Interval zrange, out Interval mrange)
        {
            switch (self.OgcGeometryType)
            {
            case OgcGeometryType.Point:
                GetMetric((IPoint)self, out xrange, out yrange, out zrange, out mrange);
                break;

            case OgcGeometryType.LineString:
                GetMetric((ILineString)self, out xrange, out yrange, out zrange, out mrange);
                break;

            case OgcGeometryType.Polygon:
                GetMetric((IPolygon)self, out xrange, out yrange, out zrange, out mrange);
                break;

            default:
                GetMetric(self.GetGeometryN(0), out xrange, out yrange, out zrange, out mrange);
                for (var i = 1; i < self.NumGeometries; i++)
                {
                    Interval x2range, y2range, z2range, m2range;
                    var      ring = self.GetGeometryN(i);
                    GetMetric(ring, out x2range, out y2range, out z2range,
                              out m2range);
                    xrange = xrange.ExpandedByInterval(x2range);
                    yrange = yrange.ExpandedByInterval(y2range);
                    zrange = zrange.ExpandedByInterval(z2range);
                    mrange = mrange.ExpandedByInterval(m2range);
                }
                break;
            }
        }
コード例 #4
0
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="numRecords">The number of features</param>
 /// <param name="xInterval">The x-Oridnate extent</param>
 /// <param name="yInterval">The y-Oridnate extent</param>
 /// <param name="zInterval">The z-Oridnate extent</param>
 /// <param name="mInterval">The m-Oridnate extent</param>
 public SbnHeader(int numRecords, Interval xInterval, Interval yInterval, Interval zInterval, Interval mInterval)
 {
     NumRecords = numRecords;
     XRange     = xInterval;
     YRange     = yInterval;
     ZRange     = zInterval;
     MRange     = mInterval;
 }
コード例 #5
0
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="numRecords">The number of features</param>
 /// <param name="extent">The extent</param>
 public SbnHeader(int numRecords, Envelope extent)
 {
     NumRecords = numRecords;
     XRange     = Interval.Create(extent.MinX, extent.MaxX);
     YRange     = Interval.Create(extent.MinY, extent.MaxY);
     ZRange     = Interval.Create();
     MRange     = Interval.Create();
 }
コード例 #6
0
 internal void AddFeature(uint id, Envelope geometry, Interval?zRange, Interval?mRange)
 {
     NumRecords++;
     XRange = XRange.ExpandedByInterval(Interval.Create(geometry.MinX, geometry.MaxX));
     YRange = YRange.ExpandedByInterval(Interval.Create(geometry.MinY, geometry.MaxY));
     ZRange = ZRange.ExpandedByInterval(zRange ?? Interval.Create());
     MRange = MRange.ExpandedByInterval(mRange ?? Interval.Create());
 }
コード例 #7
0
 internal static void GetMetric(Envelope self,
                                out Interval xrange, out Interval yrange,
                                out Interval zrange, out Interval mrange)
 {
     xrange = Interval.Create(self.MinX, self.MaxX);
     yrange = Interval.Create(self.MinY, self.MaxY);
     zrange = Interval.Create();
     mrange = Interval.Create();
 }
コード例 #8
0
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 public SbnHeader()
 {
     FileLength = 100;
     NumRecords = 0;
     XRange     = Interval.Create();
     YRange     = Interval.Create();
     ZRange     = Interval.Create();
     MRange     = Interval.Create();
 }
コード例 #9
0
        internal static void Clamp(Envelope scale, Envelope envelope,
                                   out byte minx, out byte miny, out byte maxx, out byte maxy)
        {
            var xrange = Interval.Create(scale.MinX, scale.MaxX);
            var yrange = Interval.Create(scale.MinY, scale.MaxY);

            minx = ScaleLower(envelope.MinX, xrange);
            maxx = ScaleUpper(envelope.MaxX, xrange);
            miny = ScaleLower(envelope.MinY, yrange);
            maxy = ScaleUpper(envelope.MaxY, yrange);
        }
コード例 #10
0
        internal static byte ScaleUpper(double value, Interval range)
        {
            var max    = ((value - range.Min) / range.Width * 255.0);
            var modMax = (max % 1 + .005) % 1 + (int)max;
            var res    = (int)Math.Ceiling(modMax);

            if (res > 255)
            {
                res = 255;
            }
            return((byte)res);
        }
コード例 #11
0
        internal static byte ScaleLower(double value, Interval range)
        {
            var min = ((value - range.Min) / range.Width * 255.0);
            // not sure why this rounding is needed, but it is
            var modMin = (min % 1 - .005) % 1 + (int)min;
            var res    = (int)(Math.Floor(modMin));

            if (res < 0)
            {
                res = 0;
            }
            return((byte)res);
        }
コード例 #12
0
ファイル: SbnTree.cs プロジェクト: FObermaier/SharpSbn
        /// <summary>
        /// Method to insert a new feature to the tree
        /// </summary>
        /// <param name="fid">The feature's id</param>
        /// <param name="envelope">The feature's geometry</param>
        /// <param name="zRange">The z-ordinate extent</param>
        /// <param name="mRange">The m-ordinate extent</param>
#pragma warning disable 3001
        public void Insert(uint fid, Envelope envelope, Interval?zRange = null, Interval?mRange = null)
#pragma warning restore 3001
        {
            // lock the tree
            Monitor.Enter(_syncRoot);

            // Convert to an sbnfeature
            var sbnFeature = ToSbnFeature(fid, envelope);

            var inserted = false;

            // Has the tree already been built?
            if (Built)
            {
                // Does the feature fit into the current tree, signal that
                // the tree needs to be recreated in order to function properly.
                if (!_header.Extent.Contains(envelope))
                {
                    OnRebuildRequired(new SbnTreeRebuildRequiredEventArgs(fid, envelope, zRange, mRange));
                    Monitor.Exit(_syncRoot);
                    return;
                }

                // Compute number of features in tree
                var featureCount = FeatureCount + 1;

                // Does the new number of features require more levels?
                if (GetNumberOfLevels(featureCount) != NumLevels)
                {
                    // This can be done inplace.
                    RebuildTree(featureCount, sbnFeature);
                    inserted = true;
                }
            }

            //Insert the feature
            if (!inserted)
            {
                Insert(sbnFeature);
            }

            // Update the header metrics
            _header.AddFeature(fid, envelope, zRange ?? Interval.Create(), mRange ?? Interval.Create());

            // unlock the tree
            Monitor.Exit(_syncRoot);
        }
コード例 #13
0
ファイル: SbnTree.cs プロジェクト: FObermaier/SharpSbn
        /// <summary>
        /// Method to get some of the shapefile header values.
        /// </summary>
        /// <param name="geoms">An enumeration of (id, geometry) tuples</param>
        /// <param name="xrange">The x-extent</param>
        /// <param name="yrange">The y-extent</param>
        /// <param name="zrange">The z-extent</param>
        /// <param name="mrange">The m-extent</param>
        private static void GetIntervals(IEnumerable <Tuple <uint, IGeometry> > geoms, out Interval xrange, out Interval yrange,
                                         out Interval zrange, out Interval mrange)
        {
            xrange = Interval.Create();
            yrange = Interval.Create();
            zrange = Interval.Create();
            mrange = Interval.Create();

            foreach (var tuple in geoms)
            {
                Interval x2Range, y2Range, z2Range, m2Range;
                GeometryMetricExtensions.GetMetric(tuple.Item2, out x2Range, out y2Range, out z2Range, out m2Range);
                xrange = xrange.ExpandedByInterval(x2Range);
                yrange = yrange.ExpandedByInterval(y2Range);
                zrange = zrange.ExpandedByInterval(z2Range);
                mrange = mrange.ExpandedByInterval(m2Range);
            }
        }
コード例 #14
0
        private static void GetMetric(ICoordinateSequence seq, out Interval xrange, out Interval yrange,
                                      out Interval zrange,
                                      out Interval mrange)
        {
            xrange = Interval.Create();
            yrange = Interval.Create();
            zrange = Interval.Create();
            mrange = Interval.Create();

            for (var i = 0; i < seq.Count; i++)
            {
                xrange = xrange.ExpandedByValue(seq.GetX(i));
                yrange = yrange.ExpandedByValue(seq.GetY(i));
                if ((seq.Ordinates & Ordinates.Z) == Ordinates.Z)
                {
                    zrange = zrange.ExpandedByValue(seq.GetOrdinate(i, Ordinate.Z));
                }
                if ((seq.Ordinates & Ordinates.M) == Ordinates.M)
                {
                    mrange = mrange.ExpandedByValue(seq.GetOrdinate(i, Ordinate.M));
                }
            }
        }
コード例 #15
0
 internal static void WriteBE(BinaryWriter self, Interval value)
 {
     WriteBE(self, value.Min);
     WriteBE(self, value.Max);
 }
コード例 #16
0
 private static void GetMetric(ILineString geom, out Interval xrange, out Interval yrange, out Interval zrange,
                               out Interval mrange)
 {
     GetMetric(geom.CoordinateSequence, out xrange, out yrange, out zrange, out mrange);
 }