Lucene.Net.Spatial.SpatialTestData.GetTestData C# (CSharp) Method

GetTestData() public static method

public static GetTestData ( Stream @in, SpatialContext ctx ) : IEnumerator
@in Stream
ctx Spatial4n.Core.Context.SpatialContext
return IEnumerator
        public static IEnumerator<SpatialTestData> GetTestData(Stream @in, SpatialContext ctx)
        {
            List<SpatialTestData> results = new List<SpatialTestData>();
            TextReader bufInput = new StreamReader(@in, Encoding.UTF8);
            try
            {
                String line;
                while ((line = bufInput.ReadLine()) != null)
                {
                    if (line.Length == 0 || line[0] == '#')
                        continue;

                    SpatialTestData data = new SpatialTestData();
                    String[] vals = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    if (vals.Length != 3)
                        throw new ArgumentException("bad format; expecting 3 tab-separated values for line: " + line);
                    data.id = vals[0];
                    data.name = vals[1];
                    try
                    {
                        data.shape = ctx.ReadShapeFromWkt(vals[2]);
                    }
                    catch (ParseException e)
                    {
                        throw new ApplicationException(e.Message, e);
                    }
                    results.Add(data);
                }
            }
            finally
            {
                bufInput.Dispose();
            }
            return results.GetEnumerator();
        }
    }

Usage Example

Beispiel #1
0
 protected virtual IEnumerator<SpatialTestData> getSampleData(String testDataFile)
 {
     String path = DATA_RESOURCE_PATH + testDataFile;
     Stream stream = GetType().getResourceAsStream(path);
     if (stream == null)
         throw new FileNotFoundException("classpath resource not found: " + path);
     return SpatialTestData.GetTestData(stream, ctx);//closes the InputStream
 }
SpatialTestData