예제 #1
0
        private void AddInteger(ref SHPRecordHeader ASHPRecordHeader, int Order, int MyInt32)
        {
            switch (Order)
            {
            case 0:
                ASHPRecordHeader.RecordNumber = MyInt32;
                break;

            case 1:
                ASHPRecordHeader.RecordLength = MyInt32;
                break;
            }
        }
예제 #2
0
        private void ReadRecordHeader(Stream f, ref SHPRecordHeader ASHPRecordHeader)
        {
            BinaryReader bin = new BinaryReader(f);

            int myInt32;

            for (int i = 0; i < 2; ++i)
            {
                myInt32 = bin.ReadInt32();
                AddInteger(ref ASHPRecordHeader, i, myInt32);
            }

            ASHPRecordHeader.RecordNumber = Reverse(ASHPRecordHeader.RecordNumber);
            ASHPRecordHeader.RecordLength = Reverse(ASHPRecordHeader.RecordLength);
        }
예제 #3
0
        /// <summary>
        /// Loads an ESRI(c) SHP file into a Map series.
        /// </summary>
        /// <param name="Series"></param>
        /// <param name="FileName"></param>
        /// <param name="Table"></param>
        /// <param name="FieldName"></param>
        /// <param name="FieldValue"></param>
        /// <param name="Debug"></param>
        public void LoadMap(Map Series, string FileName, DataTable Table,
                            string FieldName, string FieldValue, ListBox.ObjectCollection Debug,
                            string filter)
        {
            debug = Debug;
            SHPHeader       shpHeader       = new SHPHeader();
            SHPRecordHeader shpRecordHeader = new SHPRecordHeader();

            // Verify map file name
            string tmpName = replaceFilePath(FileName, ".shp");

            FileStream f = File.OpenRead(tmpName);

            try
            {
                if (debug != null)
                {
                    debug.Clear();
                }

                AddDebug("Real File size: " + f.Length.ToString());

                f.Position = 0;
                ReadSHPHeader(f, ref shpHeader);

                VerifySignature(shpHeader.FileCode, tmpName);

                ShowHeader(shpHeader);

                tmpName = replaceFilePath(FileName, ".shx");

                FileStream fx = File.OpenRead(tmpName);
                try
                {
                    fx.Position = 0;
                    ReadSHPHeader(fx, ref shpHeader);

                    VerifySignature(shpHeader.FileCode, tmpName);

                    if (debug != null)
                    {
                        AddDebug(" ");
                        AddDebug("Real File size: " + fx.Length.ToString());
                    }

                    int NumRecords = ShowHeader(shpHeader);

                    Series.Clear();
                    Series.BeginUpdate();
                    Series.Chart.AutoRepaint = false;

                    for (int i = 1; i <= NumRecords; ++i)
                    {
                        ReadRecordHeader(fx, ref shpRecordHeader);

                        if (debug != null)
                        {
                            AddDebug(" ");
                            AddDebug("Record Num: " + Convert.ToString(i) + " Offset: " + Convert.ToString(2 * shpRecordHeader.RecordNumber) +
                                     " Length: " + Convert.ToString(shpRecordHeader.RecordLength));
                        }

                        f.Position = 2 * shpRecordHeader.RecordNumber;
                        ReadRecordHeader(f, ref shpRecordHeader);

                        if (debug != null)
                        {
                            AddDebug("Record Num: " + Convert.ToString(shpRecordHeader.RecordNumber));
                        }

                        BinaryReader bin = new BinaryReader(f);

                        ShapeType = bin.ReadInt32();
                        LoadShape(bin, Table, Series, FieldName, FieldValue, i - 1);
                    }

                    Series.EndUpdate();
                    Series.Chart.AutoRepaint = true;
                    //Series.Chart.Invalidate();
                }
                finally
                {
                    fx.Close();
                }
            }
            finally
            {
                f.Close();
            }
        }