Ejemplo n.º 1
0
        public static bool TestHelper(string wkt)
        {
            PrecisionModel pm = new PrecisionModel(1, 0, 0);
            GeometryFactory fact = new GeometryFactory(pm, 0);

            //read wkt
            Geometry a = new GeometryWKTReader(fact).Create(wkt);

            //write wkb
            FileStream fs = new FileStream("TestFile.wkb", FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);
            GeometryWKBWriter bWriter = new GeometryWKBWriter(bw, fact);
            bWriter.Write(a, WKBByteOrder.Ndr);
            bw.Close();
            fs.Close();

            //read wkb
            fs = new FileStream("TestFile.wkb", FileMode.Open);
            byte[] bytes = new byte[fs.Length];
            for(int i = 0; i < fs.Length; i++)
            {
                bytes[i] = (byte)fs.ReadByte();
            }
            GeometryWKBReader bReader = new GeometryWKBReader(fact);
            Geometry geom = bReader.Create(bytes);
            fs.Close();

            //write to wkt & compare with original text.
            bool results = ( Compare.WktStrings(wkt,a.toText()));
            return results;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the ShapefileDataReader class.
        /// </summary>
        /// <param name="filename">The shapefile to read (minus the .shp extension)</param>
        ///<param name="geometryFactory">The GeometryFactory to use.</param>
        public ShapefileDataReader(string filename, GeometryFactory geometryFactory)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename");
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException("geometryFactory");
            }
            _geometryFactory = geometryFactory;
            _open            = true;


            if (filename.ToLower().EndsWith(".shp"))
            {
                filename = filename.ToLower().Replace(".shp", "");
            }

            _dbfReader = new DbaseFileReader(filename + ".dbf");
            _shpReader = new ShapefileReader(filename + ".shp", geometryFactory);

            _dbfHeader   = _dbfReader.GetHeader();
            _recordCount = _dbfHeader.NumRecords;

            _wkbWriter = new GeometryWKBWriter(_geometryFactory);

            // copy dbase fields to our own array. Insert into the first position, the shape column
            _dbaseFields    = new DbaseFieldDescriptor[_dbfHeader.Fields.Length + 1];
            _dbaseFields[0] = DbaseFieldDescriptor.ShapeField();
            //_dbaseFields[1] = DbaseFieldDescriptor.IdField();
            for (int i = 0; i < _dbfHeader.Fields.Length; i++)
            {
                _dbaseFields[i + 1] = _dbfHeader.Fields[i];
            }

            _shpHeader = _shpReader.Header;

            _dbfEnumerator = _dbfReader.GetEnumerator();
            _shpEnumerator = _shpReader.GetEnumerator();

            _moreRecords = true;
        }