public void TestRoundTrip(string filename)
		{
			//
			// can't round trip since I added the ToExternal/ ToInternal to the shapefile readers and writers.
			// 
			PrecisionModel pm = new PrecisionModel();
			GeometryFactory geometryFactory = new GeometryFactory(pm,-1);

			int differenceCount=0;
			string testName="";
			string srcShpFilename= Global.GetUnitTestRootDirectory()+@"\IO\Shapefile\Testfiles\"+filename;
			string destShpFilename = Global.GetUnitTestRootDirectory()+@"\IO\Shapefile\Testfiles\testroundtrip"+filename;

			// do the round trip
			ShapefileReader shpReader = new ShapefileReader(srcShpFilename+".shp", geometryFactory);
			GeometryCollection shapes = shpReader.ReadAll();

			ShapefileWriter.Write(destShpFilename,shapes, geometryFactory);

			// perfom binary compare on the .shp 
			testName = String.Format("Test round trip .shp - {0}",filename);
			differenceCount = Compare.BinaryCompare(srcShpFilename+".shp", destShpFilename+".shp");
			Assertion.AssertEquals(testName,0,differenceCount);

			// perfom binary compare on the .shx file
			testName = String.Format("Test round trip .shx - {0}",filename);
			differenceCount = Compare.BinaryCompare(srcShpFilename+".shx", destShpFilename+".shx");
			Assertion.AssertEquals(testName,0,differenceCount);

		}
Exemplo n.º 2
0
        /// <summary>
        /// Test getting and setting the properties
        /// </summary>
        public void Test_MultipleRead()
        {
            PrecisionModel  pm = new PrecisionModel(1, 0, 0);
            GeometryFactory geometryFactory = new GeometryFactory(pm, -1);

            string filename = Global.GetUnitTestRootDirectory() + @"\IO\Shapefile\Testfiles\statepop.shp";

            // tests two readers reading the file as the same time.
            Geotools.IO.ShapefileReader shpFile  = new Geotools.IO.ShapefileReader(filename, geometryFactory);
            Geotools.IO.ShapefileReader shpFile2 = new Geotools.IO.ShapefileReader(filename, geometryFactory);
            foreach (object row in shpFile)
            {
                Assertion.AssertNotNull(row);
                foreach (object row2 in shpFile2)
                {
                    Assertion.AssertNotNull(row2);
                }
            }
        }
Exemplo n.º 3
0
        //byte[] _wkb;
//		GeometryWKBWriter _wkbWriter;

        #region Constructors
        /// <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;
        }
Exemplo n.º 4
0
		/// <summary>
		/// Test getting and setting the properties
		/// </summary>
		public void Test_MultipleRead() 
		{
			PrecisionModel pm = new PrecisionModel(1,0,0);
			GeometryFactory geometryFactory = new GeometryFactory(pm,-1);

			string filename= Global.GetUnitTestRootDirectory()+@"\IO\Shapefile\Testfiles\statepop.shp";
			
			// tests two readers reading the file as the same time.
			Geotools.IO.ShapefileReader shpFile = new Geotools.IO.ShapefileReader(filename, geometryFactory);
			Geotools.IO.ShapefileReader shpFile2 = new Geotools.IO.ShapefileReader(filename, geometryFactory);
			foreach(object row in shpFile)
			{
				Assertion.AssertNotNull(row);
				foreach(object row2 in shpFile2)
				{
					Assertion.AssertNotNull(row2);
				}
			}	
		}
Exemplo n.º 5
0
			/// <summary>
			/// Initializes a new instance of the ShapefileEnumerator class.
			/// </summary>
			public ShapefileEnumerator(ShapefileReader shapefile)
			{
				
				_parent = shapefile;

				// create a file stream for each enumerator that is given out. This allows the same file
				// to have one or more enumerator. If we used the parents stream - than only one IEnumerator 
				// could be given out.
				FileStream stream = new FileStream(_parent._filename, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read);
				_shpBinaryReader = new BigEndianBinaryReader(stream);
				
				// skip header - since parent has already read this.
				_shpBinaryReader.ReadBytes(100);
				ShapeType type = _parent._mainHeader.ShapeType;
				_handler = Shapefile.GetShapeHandler(type);
				if (_handler == null) 
				{
					throw new NotSupportedException("Unsuported shape type:" + type);
				}
			}
Exemplo n.º 6
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ShapefileEnumerator">ShapefileEnumerator</see> class.
            /// </summary>
            public ShapefileEnumerator(ShapefileReader shapefile)
            {
                _parent = shapefile;

                // create a file stream for each enumerator that is given out. This allows the same file
                // to have one or more enumerator. If we used the parents stream only one IEnumerator
                // could be given out.
                _shpBinaryReader = new BigEndianBinaryReader(new FileStream(_parent._filename, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read));

                // skip header - since parent has already read this.
                _shpBinaryReader.ReadBytes(100);
                ShapeType type = _parent._mainHeader.ShapeType;

                _handler = Shapefile.GetShapeHandler(type);

                if (_handler == null)
                {
                    throw new NotSupportedException("Unsuported shape type:" + type);
                }
            }
Exemplo n.º 7
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;
        }