示例#1
0
        /// <summary>
        /// Opens the datasource
        /// </summary>
        public void Open()
        {
            // TODO:
            // Get a Connector.  The connector returned is guaranteed to be connected and ready to go.
            // Pooling.Connector connector = Pooling.ConnectorPool.ConnectorPoolManager.RequestConnector(this,true);

            if (!_IsOpen)
            {
                fsShapeIndex = new FileStream(_Filename.Remove(_Filename.Length - 4, 4) + ".shx", FileMode.Open, FileAccess.Read);
                brShapeIndex = new BinaryReader(fsShapeIndex, System.Text.Encoding.Unicode);
                fsShapeFile  = new FileStream(_Filename, FileMode.Open, FileAccess.Read);
                brShapeFile  = new BinaryReader(fsShapeFile);
                InitializeShape(_Filename, _FileBasedIndex);
                if (dbaseFile != null)
                {
                    dbaseFile.Open();
                }
                _IsOpen = true;
            }
        }
示例#2
0
        /// <summary>
        /// Opens the datasource
        /// </summary>
        public virtual void Open(string path)
        {
            // Get a Connector.  The connector returned is guaranteed to be connected and ready to go.
            // Pooling.Connector connector = Pooling.ConnectorPool.ConnectorPoolManager.RequestConnector(this,true);

            logNoShapeFile = true;

            if (!_IsOpen || this.path != path)
            {
                if (!File.Exists(path))
                {
                    if (logNoShapeFile)
                    {
                        log.Error("Could not find " + path);
                        logNoShapeFile = false;
                    }
                    return;
                }

                try
                {
                    unsafe
                    {
                        this.path = path;
                        //tree = null;

                        //Initialize DBF
                        string dbffile = GetDbaseFilePath();
                        if (File.Exists(dbffile))
                        {
                            dbaseFile = new DbaseReader(dbffile);
                        }
                        //Parse shape header
                        ParseHeader();
                        //Read projection file
                        ParseProjection();

                        fsShapeIndex = new FileStream(GetIndexFilePath(), FileMode.Open, FileAccess.Read);
                        brShapeIndex = new BinaryReader(fsShapeIndex, Encoding.Unicode);
                        fsShapeFile  = new FileStream(this.path, FileMode.Open, FileAccess.Read);
                        brShapeFile  = new BinaryReader(fsShapeFile);

                        shpFileMemoryMap     = NativeMethods.MapFile(fsShapeFile);
                        shpFileMemoryMapView = NativeMethods.MapViewOfFile(shpFileMemoryMap,
                                                                           NativeMethods.FileMapAccess.FILE_MAP_READ, 0,
                                                                           0, 0);

                        zeroPtr = (byte *)shpFileMemoryMapView.ToPointer();

                        InitializeShape(this.path, _FileBasedIndex);

                        if (dbaseFile != null)
                        {
                            dbaseFile.Open();
                        }
                        _IsOpen = true;
                    }
                }
                catch (IOException e)
                {
                    log.Error(e.Message);
                    _IsOpen = false;
                }
            }
        }