Exemplo n.º 1
0
        private void ReadHeader()
        {
            //FileCode
            int fileCode = ToLocalEndian.ToInt32FromBig(_brMainFile.ReadBytes(4));

            if (fileCode != 9994)
            {
                throw new Exception("文件不是ESRI Shape Files文件头!");
            }
            //Skip 20 bytes unused (5 integer)
            _brMainFile.ReadBytes(20);
            //File length
            _fileLength = ToLocalEndian.ToInt32FromBig(_brMainFile.ReadBytes(4)) * 2;
            if (_fileLength != _fsMainFile.Length)
            {
                throw new Exception("ESRI Shape Files文件未正确结束!");
            }
            //Version
            int Version = ToLocalEndian.ToInt32FromLittle(_brMainFile.ReadBytes(4));
            //Shape Type
            int ShapeType = ToLocalEndian.ToInt32FromLittle(_brMainFile.ReadBytes(4));

            _shapeType     = (enumShapeType)ShapeType;
            _envelope.MinX = ToLocalEndian.ToDouble64FromLittle(_brMainFile.ReadBytes(8));
            _envelope.MinY = ToLocalEndian.ToDouble64FromLittle(_brMainFile.ReadBytes(8));
            _envelope.MaxX = ToLocalEndian.ToDouble64FromLittle(_brMainFile.ReadBytes(8));
            _envelope.MaxY = ToLocalEndian.ToDouble64FromLittle(_brMainFile.ReadBytes(8));
            AdjustZeroWidthEnvelope(_envelope);
            //Skip minZ,maxZ,minM,maxM
            _brMainFile.ReadBytes(8 * 4);
            _fileHeaderSize = _fsMainFile.Position;
        }
Exemplo n.º 2
0
 public bool TryOpen(string filename, byte[] bytes, params object[] args)
 {
     _filename = filename;
     if (!filename.ToUpper().EndsWith(".000"))
     {
         return(false);
     }
     if (string.IsNullOrEmpty(filename))
     {
         throw new NullReferenceException("new MicapsDataReader(null)");
     }
     if (!File.Exists(filename))
     {
         throw new FileNotFoundException(filename);
     }
     if (args == null || args.Length < 1)
     {
         return(false);
     }
     _dataTypeId  = args[0].ToString();              //identify="GroundObserveData"
     _dataSetting = GetDataTypeSetting(_dataTypeId); //指定_dataTypeId的所有Field
     _fields      = GetFields(_dataSetting);         //_dataTypeId的所有Field的identify组成的[]
     //检查Field的合法性
     if (!CheckFieldsIsOK(filename))
     {
         return(false);
     }
     _shapeType        = enumShapeType.Point;
     _spatialReference = CodeCell.AgileMap.Core.SpatialReference.GetDefault();
     //创建Features
     _features = ConstructPoint(); //将000文件中的观测值读成features
     _envelope = GetEnvelope();    //所有features的并集
     return(true);
 }
Exemplo n.º 3
0
 public EsriShapeFilesWriterII(string outFilename, enumShapeType shape)
 {
     try
     {
         if (Path.GetExtension(outFilename).ToUpper() != ".SHP")
         {
             throw new Exception("请输入shp文件格式的文件名!");
         }
         _shapeType    = shape;
         _mainFileName = outFilename;
         string dir   = Path.GetDirectoryName(outFilename);
         string fname = Path.GetFileNameWithoutExtension(outFilename);
         _shxFileName = Path.Combine(dir, fname + ".shx");
         _dbfFileName = Path.Combine(dir, fname + ".dbf");
         if (File.Exists(_mainFileName))
         {
             File.Delete(_mainFileName);
         }
         if (File.Exists(_shxFileName))
         {
             File.Delete(_shxFileName);
         }
     }
     catch (Exception ex)
     {
         Log.WriterError(ex.Message);
     }
 }
        protected override object ConstructFeature(BinaryReader br, int oid)
        {
            enumShapeType shapeType = (enumShapeType)ToLocalEndian.ToInt32FromLittle(br.ReadBytes(4));

            switch (shapeType)
            {
            case enumShapeType.NullShape:
                break;

            case enumShapeType.Point:
                return(ConstructPoint(br, oid));

            case enumShapeType.MultiPoint:
                return(ConstructMultiPoint(br, oid));

            case enumShapeType.Polyline:
                return(ConstructPolyline(br, oid));

            case enumShapeType.PolylineM:
                return(ConstructPolylineM(br, oid));

            case enumShapeType.Polygon:
                return(ConstructPolygon(br, oid));

            default:
                return(null);
            }
            return(null);
        }
Exemplo n.º 5
0
        private void setRandomShapes(Canvas e, enumShapeType t, int number)
        {
            double canvasHeight = e.ActualHeight;
            double canvasWidth  = e.ActualWidth;

            Shape shape = new Ellipse();

            for (int count = 0; count < number; count++)
            {
                switch (t)
                {
                case enumShapeType.ELLIPSE:
                    shape = new Ellipse();
                    break;

                case enumShapeType.RECTANGLE:
                    shape = new Rectangle();
                    break;
                }
                shape.Height = randomNumber.Next(10, 25);
                shape.Width  = shape.Height;
                SolidColorBrush mySolidColorBrush = new SolidColorBrush();

                // Describes the brush's color using RGB values.
                // Each value has a range of 0-255.

                mySolidColorBrush.Color = Color.FromArgb(255, (byte)randomNumber.Next(0, 255), (byte)randomNumber.Next(0, 255), (byte)randomNumber.Next(0, 255));
                shape.Fill = mySolidColorBrush;
                e.Children.Add(shape);
                Canvas.SetLeft(shape, randomNumber.Next(0, (int)(canvasWidth - shape.Width)));
                Canvas.SetTop(shape, randomNumber.Next(0, (int)(canvasHeight - shape.Height)));
            }
        }
Exemplo n.º 6
0
        public static MemoryDataSource FromXElement(XElement ele)
        {
            if (ele == null)
            {
                return(null);
            }
            string name = null;

            if (ele.Attribute("name") != null)
            {
                name = ele.Attribute("name").Value;
            }
            string        shapetype = ele.Attribute("shapetype").Value;
            enumShapeType stype     = enumShapeType.Point;

            foreach (enumShapeType st in Enum.GetValues(typeof(enumShapeType)))
            {
                if (st.ToString() == shapetype)
                {
                    stype = st;
                    break;
                }
            }
            MemoryDataSource ds = new MemoryDataSource(name, stype);

            if (ele.Element("ArgsOfLeveling") != null)
            {
                ds.SetArgOfLevel(ArgOfLeveling.FromXElement(ele.Element("ArgsOfLeveling")));
            }
            return(ds);
        }
Exemplo n.º 7
0
 internal void GetArgsFromDataSource()
 {
     _fullEnvelope      = _dataSource.GetFullEnvelope();
     _fullGridCount     = _dataSource.GetFullGridCount();
     _coordType         = _dataSource.GetCoordinateType();
     _shapeType         = _dataSource.GetShapeType();
     _fieldNames        = _dataSource.GetFieldNames();
     _originalCoordType = _coordType;
 }
Exemplo n.º 8
0
        private void SetRandomShapes(Canvas e, enumShapeType t, int number)
        {
            double canvasHeight = e.ActualHeight;
            double canvasWidth  = e.ActualWidth;
            Shape  shape        = new Ellipse();

            for (int count = 0; count < number; count++)
            {
                switch (t)
                {
                case enumShapeType.ELLIPSE:
                    shape = new Ellipse();
                    break;

                case enumShapeType.RECTANGLE:
                    shape = new Rectangle();
                    break;

                case enumShapeType.TRIANGLE:
                    Polygon temp     = new Polygon();
                    int     temp_len = randomNumber.Next(10, 25);
                    //10,110 60,10 110,110
                    System.Windows.Point Point1            = new System.Windows.Point(0, 0);
                    System.Windows.Point Point2            = new System.Windows.Point(7, 0);
                    System.Windows.Point Point3            = new System.Windows.Point(7, 7);
                    PointCollection      myPointCollection = new PointCollection
                    {
                        Point1,
                        Point2,
                        Point3
                    };
                    temp.Points = myPointCollection;
                    shape       = temp;
                    break;
                }

                shape.Height = randomNumber.Next(10, 25);
                shape.Width  = shape.Height;



                SolidColorBrush mySolidColorBrush = new SolidColorBrush();

                // Describes the brush's color using RGB values.
                // Each value has a range of 0-255.

                mySolidColorBrush.Color = Color.FromArgb(255, (byte)randomNumber.Next(0, 255), (byte)randomNumber.Next(0, 255), (byte)randomNumber.Next(0, 255));
                shape.Fill = mySolidColorBrush;
                e.Children.Add(shape);
                Canvas.SetLeft(shape, randomNumber.Next(0, (int)(canvasWidth - shape.Width)));
                Canvas.SetTop(shape, randomNumber.Next(0, (int)(canvasHeight - shape.Height)));
            }
        }
Exemplo n.º 9
0
 public MemoryDataSource(string name,
                         enumShapeType shapeType
                         )
     : base(name)
 {
     _shapeType          = shapeType;
     _coordType          = enumCoordinateType.Geographic;
     _gridDefinition     = new GridDefinition(360, 180);
     _fullEnvelope       = new Envelope(-180, -90, 180, 90);
     _gridStateIndicator = new GridStateIndicator(_fullEnvelope.Clone() as Envelope, _gridDefinition);
     _fullGridCount      = _gridStateIndicator.Width * _gridStateIndicator.Height;
     _grid = new Grid(0, _fullEnvelope.Clone() as Envelope, new Feature[] { });
 }
Exemplo n.º 10
0
        public EsriShapeFilesWriter(string outFilename, Feature[] features, enumShapeType shape)
        {
            //检查输入是否合法
            string dir          = Path.GetDirectoryName(outFilename);
            string mainFilename = outFilename;
            string shxFilename  = Path.Combine(dir, Path.GetFileNameWithoutExtension(outFilename) + ".shx");
            string dbfFilename  = Path.Combine(dir, Path.GetFileNameWithoutExtension(outFilename) + ".dbf");

            try
            {
                if (!outFilename.Contains(".shp"))
                {
                    throw new Exception("请输入shp文件格式的文件名!");
                }
                if (File.Exists(mainFilename))
                {
                    File.Delete(mainFilename);
                }
                if (File.Exists(shxFilename))
                {
                    File.Delete(shxFilename);
                }
                _shapeType = shape;
                //创建文件
                _fsMainFile = new FileStream(mainFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                _bwMainFile = new BinaryWriter(_fsMainFile);
                _fsShxFile  = new FileStream(shxFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                _bwShxFile  = new BinaryWriter(_fsShxFile);

                /*
                 * River.shp
                 * River.shx
                 * River.dbf
                 * 1、shp文件,几何形状的文件
                 * 2、shx文件,索引文件
                 * 3、dbf文件,属性数据文件
                 * 4、prj文件,坐标系统
                 */
                //write dbf file
                _bwDbfFile = new DbfWriter(dbfFilename, features);
                // write main file and shx file
                WriteVectorDataToFiles(features);
                WriteDbfEncode(dbfFilename);
            }
            catch (Exception ex)
            {
                Log.WriterError(ex.Message);
            }
        }
Exemplo n.º 11
0
 public MemoryDataSource(string name,
                         enumShapeType shapeType,
                         enumCoordinateType coordType,
                         Envelope fullEnvelope
                         )
     : base(name)
 {
     _shapeType      = shapeType;
     _coordType      = enumCoordinateType.Geographic;
     _gridDefinition = new GridDefinition((float)(fullEnvelope.Width + float.Epsilon),
                                          (float)(fullEnvelope.Height + float.Epsilon));
     _fullEnvelope       = fullEnvelope;
     _gridStateIndicator = new GridStateIndicator(_fullEnvelope.Clone() as Envelope, _gridDefinition);
     _fullGridCount      = _gridStateIndicator.Width * _gridStateIndicator.Height;
     _grid = new Grid(0, _fullEnvelope.Clone() as Envelope, new Feature[] { });
 }
        private void ReadBaicProperties()
        {
            if (_dbConnection.State != ConnectionState.Open)
            {
                _dbConnection.Open();
            }
            string sql = "select id,datatable,annotable," + _adapter.SQLToWktForShapeField("envelope") + ",featurecount,shapetype from " + BudGISMetadata.cstFeatureClassTableName +
                         " t where datatable = '" + _fetclassName + "'";

            using (IDbCommand cmd = _dbConnection.CreateCommand())
            {
                cmd.CommandText = sql;
                using (IDataReader dr = cmd.ExecuteReader())
                {
                    if (dr.Read())
                    {
                        _id        = _adapter.DrToString(dr, 0);
                        _datatable = _adapter.DrToString(dr, 1);
                        _annotable = _adapter.DrToString(dr, 2);
                        //
                        ShapePolygon ply = _adapter.DrToShape(dr, 3) as ShapePolygon;
                        if (ply != null)
                        {
                            ShapeRing ring = ply.Rings[0];
                            _envelope = new Envelope(ring.Points[0].X, ring.Points[2].Y, ring.Points[1].X, ring.Points[0].Y);
                        }
                        //
                        _fetCount = _adapter.DrToInt32(dr, 4);
                        //
                        string shapeTypeStr = _adapter.DrToString(dr, 5);
                        foreach (enumShapeType st in Enum.GetValues(typeof(enumShapeType)))
                        {
                            if (st.ToString() == shapeTypeStr.ToString())
                            {
                                _shapeType = st;
                                break;
                            }
                        }
                        //
                    }
                    else
                    {
                        throw new Exception("要素类\"" + _fetclassName + "\"在指定的空间数据库中不存在。");
                    }
                }
            }
        }
Exemplo n.º 13
0
        private static ISymbol GetSymbol(string dataName, enumShapeType shapeType)
        {
            switch (shapeType)
            {
            case enumShapeType.Point:
                return(new SimpleMarkerSymbol(masSimpleMarkerStyle.Circle));

            case enumShapeType.Polyline:
                return(new SimpleLineSymbol(Color.Blue, 1));

            case enumShapeType.Polygon:
                return(new SimpleFillSymbol(Color.Transparent, new SimpleLineSymbol(Color.Blue, 1)));

            default:
                return(null);
            }
        }
Exemplo n.º 14
0
        private void TryExport2ShapeFile(Feature[] iceLines, string shpFileName, enumShapeType shapeType)
        {
            int    cntCount = iceLines.Length;
            string tip      = "正在将等值线导出为矢量文件({0}/{1})...";
            int    progress = 0;
            float  interval = 100f / cntCount;
            IEsriShapeFilesWriter writer = null;

            try
            {
                writer = new EsriShapeFilesWriterII(shpFileName, shapeType);
                writer.BeginWrite();
                Feature[] buffer = new Feature[1];
                for (int i = 0; i < cntCount; i++)
                {
                    if (iceLines[i] == null)
                    {
                        continue;
                    }
                    progress = (int)(Math.Floor(interval * i));
                    //Feature fet = GetIceLineFeature(iceLines[i], resX, resY, minX, maxY, i);
                    Feature fet = iceLines[i];
                    if (fet != null)
                    {
                        buffer[0] = fet;
                        writer.Write(buffer);
                    }
                    if (_progressTracker != null)
                    {
                        _progressTracker(progress, string.Format(tip, i, cntCount));
                    }
                }
            }
            finally
            {
                if (writer != null)
                {
                    writer.EndWriter();
                }
            }
        }
Exemplo n.º 15
0
        internal static SymbolTypeItem[] GetSymbolTypeItemsByShapeType(enumShapeType shapeType)
        {
            SymbolTypeItem[]      Items    = GetAllSymbolTypeItems();
            List <SymbolTypeItem> retItems = new List <SymbolTypeItem>();

            foreach (SymbolTypeItem it in Items)
            {
                switch (shapeType)
                {
                case enumShapeType.Point:
                case enumShapeType.MultiPoint:
                    if (Array.IndexOf(it.SymbolType.GetInterfaces(), typeof(IMarkerSymbol)) >= 0)
                    {
                        retItems.Add(it);
                    }
                    break;

                case enumShapeType.Polyline:
                case enumShapeType.PolylineM:
                case enumShapeType.PolylineZ:
                    if (Array.IndexOf(it.SymbolType.GetInterfaces(), typeof(ILineSymbol)) >= 0)
                    {
                        retItems.Add(it);
                    }
                    break;

                case enumShapeType.Polygon:
                    if (Array.IndexOf(it.SymbolType.GetInterfaces(), typeof(IFillSymbol)) >= 0)
                    {
                        retItems.Add(it);
                    }
                    break;

                default:
                    continue;
                }
            }
            return(retItems.ToArray());
        }
Exemplo n.º 16
0
        public static string GetStringByShapeType(enumShapeType shapeType)
        {
            switch (shapeType)
            {
            case enumShapeType.Point:
                return("点");

            case enumShapeType.Polyline:
                return("线");

            case enumShapeType.Polygon:
                return("多边形");

            case enumShapeType.NullShape:
                return("空");

            case enumShapeType.MixGeomtry:
                return("混合(点、线、多边形)");

            default:
                throw new NotImplementedException("几何形状\"" + shapeType.ToString() + "\"到字符串的转换未实现。");
            }
        }
Exemplo n.º 17
0
        private void InitDataReader()
        {
            _shapeType        = enumShapeType.Point;
            _spatialReference = CodeCell.AgileMap.Core.SpatialReference.GetDefault();
            //
            string[]      lines  = File.ReadAllLines(_fileNames[0]);
            List <string> fields = new List <string>();

            fields.Add("Location");
            fields.AddRange(lines[4].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
            _fields = fields.ToArray();
            List <string>  fieldValues = new List <string>();
            int            oId = 0; ShapePoint pt;
            double         lon, lat;
            List <Feature> features = new List <Feature>();

            foreach (string file in _fileNames)
            {
                lines = File.ReadAllLines(file);
                string[] infos = lines[2].Split(new string[] { ",", "=" }, StringSplitOptions.RemoveEmptyEntries);
                if (!double.TryParse(infos[3], out lon) || !double.TryParse(infos[5], out lat))
                {
                    return;
                }
                for (int i = 5; i < lines.Length; i++)
                {
                    pt = new ShapePoint(lon, lat);
                    fieldValues.Clear();
                    fieldValues.Add(infos[1]);
                    fieldValues.AddRange(lines[i].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
                    Feature f = new Feature(oId++, pt, _fields, fieldValues.ToArray(), null);
                    features.Add(f);
                }
            }
            _features = features.ToArray();
            _envelope = GetEnvelope();//所有features的并集
        }
Exemplo n.º 18
0
 public StatInfoFetClass(enumShapeType shapeType, int featureCount, Envelope envelope)
 {
     ShapeType    = shapeType;
     FeatureCount = featureCount;
     Envelope     = envelope;
 }
Exemplo n.º 19
0
 public LayerInfo(string name, string id, enumShapeType shapeType)
 {
     _name      = name;
     _id        = id;
     _shapeType = shapeType;
 }
Exemplo n.º 20
0
 private string GetShapeTypeString(enumShapeType enumShapeType)
 {
     return(ShapeTypeToString.GetStringByShapeType(enumShapeType));
 }