Beispiel #1
0
        /// <summary>
        /// 根据文件流创建shapefile
        /// </summary>
        /// <param name="shpFileStream"></param>
        /// <param name="shxFileStream"></param>
        /// <param name="dbfFileStream"></param>
        /// <param name="prjFileStream"></param>
        /// <returns></returns>
        public static FeatureSet CreateFeatureSet
            (Stream shpFileStream, Stream shxFileStream,
            Stream dbfFileStream, Stream prjFileStream = null)
        {
            using var dbfReader = new DbfReader(dbfFileStream);
            var shxIndexs = new ShxReader().ReadShx(shxFileStream);
            var recordNum = shxIndexs.Count;

            using var shpReader = new ShpReader(shpFileStream, shxIndexs);

            var fs = CreateFeatureSet(shpReader, dbfReader, recordNum);

            if (prjFileStream != null)
            {
                string prjWkt = "";
                using (var sr = new StreamReader(prjFileStream, dbfReader.Encoding))
                {
                    prjWkt = sr.ReadToEnd();
                }

                var proj = Crs.CreateFromWkt(prjWkt);
                fs.Crs = proj;
            }
            return(fs);
        }
Beispiel #2
0
        /// <summary>
        /// 从shapefile生成FeatureSet
        /// </summary>
        /// <param name="shpFilePath"></param>
        /// <returns></returns>
        public static FeatureSet CreateFeatureSet(string shpFilePath)
        {
            if (!ShpUtil.VerificationShp(shpFilePath, out var subFiles))
            {
                throw new IOException("该shapefile文件不存在或者主文件缺失!");
            }
            //else
            using var dbfReader = new DbfReader(subFiles.Item2);
            var shxIndexs = new ShxReader().ReadShx(subFiles.Item1);
            var recordNum = shxIndexs.Count;

            using var shpReader = new ShpReader(shpFilePath, shxIndexs);

            var fs = CreateFeatureSet(shpReader, dbfReader, recordNum);

            if (File.Exists(subFiles.Item3))
            {
                string prjWkt = "";
                using (var sr = new StreamReader(subFiles.Item3, Encoding.UTF8))
                {
                    prjWkt = sr.ReadToEnd();
                }

                var proj = Crs.CreateFromWkt(prjWkt);
                fs.Crs = proj;
            }

            return(fs);
        }
Beispiel #3
0
        public ShpReader(string shpFilePath)
        {
            string shxFilePath = shpFilePath.Substring(0, shpFilePath.Length - 3) + ".shx";

            _shxRecords    = new ShxReader().ReadShx(shxFilePath);
            _readStream    = new FileStream(shpFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            this.ShpHeader = ShpUtil.GetHeader(_readStream);
        }