Ejemplo n.º 1
0
        public override bool MoveNext()
        {
            if (this._reader != null)
            {
                if (_reader.Read())
                {
                    this.current = _reader.GetDouble(this._index);
                    return(true);
                }
                // To maintain 4.0 behavior we Dispose
                // after reading to the end of the reader.
                Dispose();
            }

            return(false);
        }
Ejemplo n.º 2
0
        public void Test_TestConstructor()
        {
            PrecisionModel  pm = new PrecisionModel(100000, 0, 0);
            GeometryFactory geometryFactory = new GeometryFactory(pm, -1);

            string filename = Global.GetUnitTestRootDirectory() + @"\IO\Shapefile\Testfiles\statepop";
            ShapefileDataReader shpDataReader = Geotools.IO.Shapefile.CreateDataReader(filename, geometryFactory);

            int i = 0;

            //for( i=0;i<shpDataReader.FieldCount;i++)
            //{
            //	Console.WriteLine(i+" "+shpDataReader.GetName(i) +" " +shpDataReader.GetFieldType(i));
            //}

            Assertion.AssertEquals("Dbase header: Num records", 49, shpDataReader.RecordCount);
            Assertion.AssertEquals("Dbase header: Num fields", 253, shpDataReader.FieldCount);

            Assertion.AssertEquals("Field 1: name", "STATE_NAME", shpDataReader.GetName(1));
            Assertion.AssertEquals("Field 1: name", typeof(string), shpDataReader.GetFieldType(1));

            Assertion.AssertEquals("Field 252: name", "SAMP_POP", shpDataReader.GetName(252));
            Assertion.AssertEquals("Field 252: name", typeof(double), shpDataReader.GetFieldType(252));


            // note alaska and hawaii are missing - hence 48 states not 50.
            i = 0;
            foreach (object columnValues in shpDataReader)
            {
                if (columnValues == null)
                {
                    Assertion.Fail("columnValues should not be null.");
                }
                if (i == 0)
                {
                    Assertion.AssertEquals("Row1: STATE_NAME:", "Illinois", shpDataReader.GetString(1));
                    Assertion.AssertEquals("Row1: STATE_FIPS:", "17", shpDataReader.GetValue(2));
                    Assertion.AssertEquals("Row1: SAMP_POP", 1747776.0, shpDataReader.GetDouble(252));
                }
                if (i == 48)
                {
                    Assertion.AssertEquals("Row1: STATE_NAME:", "Washington", shpDataReader.GetString(1));
                    Assertion.AssertEquals("Row1: STATE_FIPS:", "53", shpDataReader.GetValue(2));
                    Assertion.AssertEquals("Row1: SAMP_POP", 736744.0, shpDataReader.GetDouble(252));
                }
                i++;
            }
            Assertion.AssertEquals("49 Records", 49, i);

            // try opening the file again, to make sure file is not locked from previous reader.
            ShapefileDataReader shpDataReader2 = Geotools.IO.Shapefile.CreateDataReader(filename, geometryFactory);

            i = 0;
            while (shpDataReader2.Read())
            {
                if (i == 0)
                {
                    Assertion.AssertEquals("Row1: STATE_NAME:", "Illinois", shpDataReader2.GetString(1));
                    Assertion.AssertEquals("Row1: STATE_FIPS:", "17", shpDataReader2.GetValue(2));
                    Assertion.AssertEquals("Row1: SAMP_POP", 1747776.0, shpDataReader2.GetDouble(252));
                }
                if (i == 48)
                {
                    Assertion.AssertEquals("Row1: STATE_NAME:", "Washington", shpDataReader2.GetString(1));
                    Assertion.AssertEquals("Row1: STATE_FIPS:", "53", shpDataReader2.GetValue(2));
                    Assertion.AssertEquals("Row1: SAMP_POP", 736744.0, shpDataReader2.GetDouble(252));
                }
                i++;
            }
            Assertion.AssertEquals("49 Records", 49, i);
        }
 public double GetDouble(int i)
 {
     return(_shapeFileDataReader.GetDouble(i));
 }