コード例 #1
0
ファイル: ShpReader.cs プロジェクト: hakbra/SGIS
        public Layer readImpl(string filename)
        {
            // split filename in path and filename
            string[] split = filename.Split('\\');
            string name = split.Last();
            // remove extension
            name = name.Substring(0, name.Length - 4);
            string path = filename.Substring(0, filename.Length - name.Length - 4);

            layer = new Layer(name);

            // read .prj-file with same name or with name 'default.prj'
            string prjName = filename.Substring(0, filename.Length - 3) + "prj";
            if (File.Exists(prjName))
                layer.Projection = PrjReader.read(prjName);
            else if (File.Exists(path + "default.prj"))
                layer.Projection = PrjReader.read(path + "default.prj");
            else
            {
                // warning message if missing prj file
                string msg = "No projection da found. Assuming " + SGIS.App.getSrsName();
                MessageBox.Show(msg, "Missing spatial reference system: " + name, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            // try reading attribute file with same name
            string dbfName = filename.Substring(0, filename.Length - 3) + "dbf";
            if (File.Exists(dbfName))
                layer.DataTable = DbfReader.read(dbfName);

            // create stream from file
            FileStream f = File.Open(filename, FileMode.Open);
            br = new BinaryReaderExtension(f);
            pos = 0;
            length = (int)br.BaseStream.Length;

            readHeader();

            // set bounding box from values in header
            layer.Boundingbox = new Envelope(minx, maxx, miny, maxy);
            layer.createQuadTree();

            // content starts at pos 100
            pos = 100;

            // read all shapes until end
            while (pos < length)
                readShape();

            br.Close();

            // features now converted to application srs
            layer.Projection = SGIS.App.SRS;
            return layer;
        }