diff --git a/Tabula/RectangleSpatialIndex.Str.cs b/Tabula/RectangleSpatialIndex.Str.cs new file mode 100644 index 0000000..148c07e --- /dev/null +++ b/Tabula/RectangleSpatialIndex.Str.cs @@ -0,0 +1,104 @@ +using NetTopologySuite.Geometries; +using NetTopologySuite.Index.Strtree; +using System; +using System.Collections.Generic; +using System.Linq; +using UglyToad.PdfPig.Core; +using UglyToad.PdfPig.Geometry; + +namespace Tabula +{ + /// + /// ported from tabula-java/blob/master/src/main/java/technology/tabula/RectangleSpatialIndex.java + /// + /// + public class RectangleSpatialIndex where T : TableRectangle + { + private STRtree si = new STRtree(); + private List rectangles = new List(); + + /// + /// + /// + /// + public void Add(T te) + { + rectangles.Add(te); + si.Insert(new Envelope(te.Left, te.Right, te.Bottom, te.Top), te); + } + + /// + /// hack + /// + /// + private PdfRectangle Expand(PdfRectangle rectangle) + { + return new PdfRectangle(rectangle.Left - 1, rectangle.Bottom - 1, rectangle.Right + 1, rectangle.Top + 1); + } + + /// + /// + /// + /// + /// + public List Contains(PdfRectangle r) + { + IList intersection = si.Query(new Envelope(r.Left, r.Right, r.Top, r.Bottom)); + List rv = new List(); + + foreach (T ir in intersection) + { + if (r.Contains(ir.BoundingBox)) + { + rv.Add(ir); + } + } + + Utils.Sort(rv, new TableRectangle.ILL_DEFINED_ORDER()); + return rv; + } + + /// + /// + /// + /// + /// + public List Contains(TableRectangle r) + { + IList intersection = si.Query(new Envelope(r.Left, r.Right, r.Top, r.Bottom)); + List rv = new List(); + + foreach (T ir in intersection) + { + if (r.Contains(ir)) + { + rv.Add(ir); + } + } + + Utils.Sort(rv, new TableRectangle.ILL_DEFINED_ORDER()); + return rv; + + } + + /// + /// + /// + /// + /// + public List Intersects(TableRectangle r) + { + IList rv = si.Query(new Envelope(r.Left, r.Right, r.Top, r.Bottom)); + return (List)rv; + + } + + /// + /// Minimum bounding box of all the Rectangles contained on this RectangleSpatialIndex. + /// + public TableRectangle GetBounds() + { + return TableRectangle.BoundingBoxOf(rectangles.Cast()); + } + } +} diff --git a/Tabula/Tabula.csproj b/Tabula/Tabula.csproj index 13a6021..e44f25a 100644 --- a/Tabula/Tabula.csproj +++ b/Tabula/Tabula.csproj @@ -1,29 +1,85 @@  - - netcoreapp3.1;netstandard2.0;net452;net46;net461;net462;net47;net5.0;net6.0 - Extract tables from PDF files (port of tabula-java using PdfPig). - https://github.com/BobLd/tabula-sharp - 0.1.2 - BobLd - BobLd - pdf, extract, table, tabula, pdfpig, parse, extraction, export - MIT - https://github.com/BobLd/tabula-sharp - README.md - True - True - - - - - True - \ - - - - - - + + netcoreapp3.1;netstandard2.0;net452;net46;net461;net462;net47;net5.0;net6.0 + Extract tables from PDF files (port of tabula-java using PdfPig). + https://github.com/BobLd/tabula-sharp + 0.1.2 + BobLd + BobLd + pdf, extract, table, tabula, pdfpig, parse, extraction, export + MIT + https://github.com/BobLd/tabula-sharp + README.md + True + True + + + + + + + + + True + \ + + + + + + + + + + 2.4.0 + + + + + + 2.4.0 + + + + + + + + + + + + + + + + 2.4.0 + + + + + + 2.4.0 + + + + + + 2.4.0 + + + + + + 2.4.0 + + + + + + 2.4.0 + +