This class is modelled after SpatialTestQuery. Before Lucene 4.7, this was a bit different in Spatial4n as SampleData & SampleDataReader.
Example #1
0
        protected virtual List <Document> getDocuments(IEnumerator <SpatialTestData> sampleData)
        {
            List <Document> documents = new List <Document>();

            while (sampleData.MoveNext())
            {
                SpatialTestData data     = sampleData.Current;
                Document        document = new Document();
                document.Add(new StringField("id", data.id, Field.Store.YES));
                document.Add(new StringField("name", data.name, Field.Store.YES));
                IShape shape = data.shape;
                shape = convertShapeFromGetDocuments(shape);
                if (shape != null)
                {
                    foreach (Field f in strategy.CreateIndexableFields(shape))
                    {
                        document.Add(f);
                    }
                    if (storeShape)//just for diagnostics
                    {
                        document.Add(new StoredField(strategy.FieldName, shape.toString()));
                    }
                }

                documents.Add(document);
            }
            return(documents);
        }
Example #2
0
        /** Reads the stream, consuming a format that is a tab-separated values of 3 columns:
         * an "id", a "name" and the "shape".  Empty lines and lines starting with a '#' are skipped.
         * The stream is closed.
         */
        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();
        }
Example #3
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
 }
Example #4
0
        /** Reads the stream, consuming a format that is a tab-separated values of 3 columns:
         * an "id", a "name" and the "shape".  Empty lines and lines starting with a '#' are skipped.
         * The stream is closed.
         */
        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());
        }
        /** Reads the stream, consuming a format that is a tab-separated values of 3 columns:
         * an "id", a "name" and the "shape".  Empty lines and lines starting with a '#' are skipped.
         * The stream is closed.
         */
        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('\t').TrimEnd();
                    if (vals.Length != 3)
                    {
                        throw RuntimeException.Create("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 (Spatial4n.Core.Exceptions.ParseException e) // LUCENENET: Spatial4n has its own ParseException that is different than the one in Support
                    {
                        throw RuntimeException.Create(e);
                    }
                    results.Add(data);
                }
            }
            finally
            {
                bufInput.Dispose();
            }
            return(results.GetEnumerator());
        }