コード例 #1
0
 private static NtsSpatialContext CreateNtsContext(SpatialOptions options)
 {
     if (options.Type == SpatialFieldType.Cartesian)
     {
         var nts = new NtsSpatialContext(new GeometryFactory(), false, new CartesianDistCalc(), null);
         nts.GetWorldBounds().Reset(options.MinX, options.MaxX, options.MinY, options.MaxY);
         return(nts);
     }
     return(GeoContext);
 }
コード例 #2
0
ファイル: NtsPolygonTest.cs プロジェクト: mundher/lucene.net
        private static readonly double LUCENE_4464_distErrPct = SpatialArgs.DEFAULT_DISTERRPCT;        //DEFAULT 2.5%

        public NtsPolygonTest()
        {
            //var args = new HashMap<String, String> {{"spatialContextFactory", "com.spatial4j.core.context.jts.JtsSpatialContextFactory"}};
            //SpatialContextFactory.MakeSpatialContext(args, getClass().getClassLoader());
            ctx = new NtsSpatialContext(true);

            var grid = new GeohashPrefixTree(ctx, 11);            //< 1 meter == 11 maxLevels

            this.strategy = new RecursivePrefixTreeStrategy(grid, GetType().Name);
            ((RecursivePrefixTreeStrategy)this.strategy).DistErrPct = LUCENE_4464_distErrPct;            //1% radius (small!)
        }
コード例 #3
0
        private IGeometry RandomGeometry(int points)
        {
            //a circle
            NtsSpatialContext     ctx = (NtsSpatialContext)base.ctx;
            GeometricShapeFactory gsf = new GeometricShapeFactory(ctx.GeometryFactory);

            gsf.Centre    = (new Coordinate(0, 0));
            gsf.Size      = (180);//diameter
            gsf.NumPoints = (points);
            return(gsf.CreateCircle());
        }
コード例 #4
0
 protected override IShape RandomShape()
 {
     if (random.Next(3) == 0)
     {
         NtsSpatialContext ctx = (NtsSpatialContext)base.ctx;
         return(ctx.MakeShape(RandomGeometry(random.Next(3, 20)), false, false));
     }
     else
     {
         return(base.RandomShape());
     }
 }
コード例 #5
0
ファイル: SpatialField.cs プロジェクト: ikvm/ravendb
 private static NtsSpatialContext CreateNtsContext(SpatialOptions options)
 {
     if (options.Type == SpatialFieldType.Cartesian)
     {
         var nts = new NtsSpatialContext(new NtsSpatialContextFactory {
             geo = false, distCalc = new CartesianDistCalc(), worldBounds = null
         });
         nts.WorldBounds.Reset(options.MinX, options.MaxX, options.MinY, options.MaxY);
         return(nts);
     }
     return(GeoContext);
 }
コード例 #6
0
        public virtual void PolyToRectCcwRule()
        {
            NtsSpatialContext ctx = (NtsSpatialContext) new NtsSpatialContextFactory()
            {
                datelineRule = DatelineRule.CcwRect
            }.NewSpatialContext();

            //counter-clockwise
            Assert.Equal(ctx.ReadShapeFromWkt("POLYGON((160 0, -170 0, -170 10, 160 10, 160 0))"),
                         ctx.MakeRectangle(160, -170, 0, 10));
            //clockwise
            Assert.Equal(ctx.ReadShapeFromWkt("POLYGON((160 10, -170 10, -170 0, 160 0, 160 10))"),
                         ctx.MakeRectangle(-170, 160, 0, 10));
        }
コード例 #7
0
ファイル: SpatialField.cs プロジェクト: ybdev/ravendb
        private SpatialStrategy CreateStrategy(string fieldName, SpatialOptions opt, NtsSpatialContext context)
        {
            switch (opt.Strategy)
            {
            case SpatialSearchStrategy.GeohashPrefixTree:
                return(new RecursivePrefixTreeStrategyThatSupportsWithin(new GeohashPrefixTree(context, opt.MaxTreeLevel), fieldName));

            case SpatialSearchStrategy.QuadPrefixTree:
                return(new RecursivePrefixTreeStrategyThatSupportsWithin(new QuadPrefixTree(context, opt.MaxTreeLevel), fieldName));

            case SpatialSearchStrategy.BoundingBox:
                return(new BBoxStrategyThatSupportsAllShapes(context, fieldName));
            }
            return(null);
        }
コード例 #8
0
        public virtual void TestArea()
        {
            //simple bbox
            IRectangle        r      = RandomRectangle(20);
            NtsSpatialContext ctxNts = (NtsSpatialContext)ctx;
            NtsGeometry       rPoly  = ctxNts.MakeShape(ctxNts.GetGeometryFrom(r), false, false);

            CustomAssert.EqualWithDelta(r.GetArea(null), rPoly.GetArea(null), 0.0);
            CustomAssert.EqualWithDelta(r.GetArea(ctx), rPoly.GetArea(ctx), 0.000001);//same since fills 100%

            CustomAssert.EqualWithDelta(1300, POLY_SHAPE.GetArea(null), 0.0);

            //fills 27%
            CustomAssert.EqualWithDelta(0.27, POLY_SHAPE.GetArea(ctx) / POLY_SHAPE.BoundingBox.GetArea(ctx), 0.009);
            Assert.True(POLY_SHAPE.BoundingBox.GetArea(ctx) > POLY_SHAPE.GetArea(ctx));
        }
コード例 #9
0
        public NtsGeometry(IGeometry geom, NtsSpatialContext ctx, bool dateline180Check, bool allowMultiOverlap)
        {
            this.ctx = ctx;

            //GeometryCollection isn't supported in relate()
            if (geom.GetType() == typeof(GeometryCollection))
            {
                throw new ArgumentException("NtsGeometry does not support GeometryCollection but does support its subclasses.");
            }

            //NOTE: All this logic is fairly expensive. There are some short-circuit checks though.
            if (ctx.IsGeo)
            {
                //Unwraps the geometry across the dateline so it exceeds the standard geo bounds (-180 to +180).
                if (dateline180Check)
                {
                    UnwrapDateline(geom); //potentially modifies geom
                }
                //If given multiple overlapping polygons, fix it by union
                if (allowMultiOverlap)
                {
                    geom = UnionGeometryCollection(geom); //returns same or new geom
                }
                //Cuts an unwrapped geometry back into overlaid pages in the standard geo bounds.
                geom = CutUnwrappedGeomInto360(geom);                       //returns same or new geom
                Debug.Assert(geom.EnvelopeInternal.Width <= 360);
                Debug.Assert(geom.GetType() != typeof(GeometryCollection)); //double check

                //Compute bbox
                bbox = ComputeGeoBBox(geom);
            }
            else
            {//not geo
                if (allowMultiOverlap)
                {
                    geom = UnionGeometryCollection(geom);//returns same or new geom
                }
                Envelope env = geom.EnvelopeInternal;
                bbox = new Rectangle(env.MinX, env.MaxX, env.MinY, env.MaxY, ctx);
            }
            var _ = geom.EnvelopeInternal;//ensure envelope is cached internally, which is lazy evaluated. Keeps this thread-safe.

            this.geom = geom;
            Debug.Assert(AssertValidate());//kinda expensive but caches valid state

            this._hasArea = !((geom is ILineal) || (geom is IPuntal));
        }
コード例 #10
0
        public virtual void TestFiji()
        {
            //Fiji is a group of islands crossing the dateline.
            string wktStr = ReadFirstLineFromRsrc("fiji.wkt.txt");

            NtsSpatialContextFactory factory = new NtsSpatialContextFactory();

            factory.normWrapLongitude = true;
            NtsSpatialContext ctx = (NtsSpatialContext)factory.NewSpatialContext();

            IShape shape = ctx.ReadShapeFromWkt(wktStr);

            AssertRelation(null, SpatialRelation.CONTAINS, shape,
                           ctx.MakePoint(-179.99, -16.9));
            AssertRelation(null, SpatialRelation.CONTAINS, shape,
                           ctx.MakePoint(+179.99, -16.9));
            Assert.True(shape.BoundingBox.Width < 5);//smart bbox
            Console.WriteLine("Fiji Area: " + shape.GetArea(ctx));
        }
コード例 #11
0
        public IShape ReadNtsGeom(BinaryReader dataInput)
        {
            NtsSpatialContext ctx = (NtsSpatialContext)base.ctx;

#pragma warning disable 612, 618
            WKBReader reader = new WKBReader(ctx.GeometryFactory);
#pragma warning restore 612, 618
            try
            {
                Stream    inStream = new InputStreamAnonymousHelper(dataInput);
                IGeometry geom     = reader.Read(inStream);
                //false: don't check for dateline-180 cross or multi-polygon overlaps; this won't happen
                // once it gets written, and we're reading it now
                return(ctx.MakeShape(geom, false, false));
            }
            catch (GeoAPI.IO.ParseException ex)
            {
                throw new InvalidShapeException("error reading WKT", ex);
            }
        }
コード例 #12
0
 public PolygonBuilder(NtsSpatialContext ctx)
 {
     this.ctx = ctx;
 }
コード例 #13
0
 public ShapeStringReadWriter(SpatialOptions options, NtsSpatialContext context)
 {
     this.options              = options;
     this.ntsShapeReadWriter   = CreateNtsShapeReadWriter(options, context);
     this.shapeStringConverter = new ShapeStringConverter(options);
 }
コード例 #14
0
        public NtsGeometry(IGeometry geom, NtsSpatialContext ctx, bool dateline180Check)
        {
            this.ctx = ctx;

            //GeometryCollection isn't supported in relate()
            if (geom.GetType() == typeof(GeometryCollection))
            {
                throw new ArgumentException("NtsGeometry does not support GeometryCollection but does support its subclasses.");
            }

            //NOTE: All this logic is fairly expensive. There are some short-circuit checks though.
            if (ctx.IsGeo())
            {
                //Unwraps the geometry across the dateline so it exceeds the standard geo bounds (-180 to +180).
                if (dateline180Check)
                {
                    UnwrapDateline(geom); //potentially modifies geom
                }
                //If given multiple overlapping polygons, fix it by union
                geom = UnionGeometryCollection(geom); //returns same or new geom
                Envelope unwrappedEnv = geom.EnvelopeInternal;

                //Cuts an unwrapped geometry back into overlaid pages in the standard geo bounds.
                geom = CutUnwrappedGeomInto360(geom);                       //returns same or new geom
                Debug.Assert(geom.EnvelopeInternal.Width <= 360);
                Debug.Assert(geom.GetType() != typeof(GeometryCollection)); //double check

                //note: this bbox may be sub-optimal. If geom is a collection of things near the dateline on both sides then
                // the bbox will needlessly span most or all of the globe longitudinally.
                // TODO so consider using MultiShape's planned minimal geo bounding box algorithm once implemented.
                double envWidth = unwrappedEnv.Width;

                //adjust minX and maxX considering the dateline and world wrap
                double minX, maxX;
                if (envWidth >= 360)
                {
                    minX = -180;
                    maxX = 180;
                }
                else
                {
                    minX = unwrappedEnv.MinX;
                    maxX = DistanceUtils.NormLonDEG(unwrappedEnv.MinX + envWidth);
                }
                bbox = new RectangleImpl(minX, maxX, unwrappedEnv.MinY, unwrappedEnv.MaxY, ctx);
            }
            else
            {//not geo
                Envelope env = geom.EnvelopeInternal;
                bbox = new RectangleImpl(env.MinX, env.MaxX, env.MinY, env.MaxY, ctx);
            }
            var _ = geom.EnvelopeInternal;            //ensure envelope is cached internally, which is lazy evaluated. Keeps this thread-safe.

            //Check geom validity; use helpful error
            // TODO add way to conditionally skip at your peril later
            var isValidOp = new IsValidOp(geom);

            if (!isValidOp.IsValid)
            {
                throw new InvalidShapeException(isValidOp.ValidationError.ToString());
            }
            this.geom = geom;

            this._hasArea = !((geom is ILineal) || (geom is IPuntal));
        }
コード例 #15
0
ファイル: ShapeStringReadWriter.cs プロジェクト: ikvm/ravendb
 public ShapeStringReadWriter(SpatialOptions options, NtsSpatialContext context)
 {
     _options = options;
     _context = context;
     _shapeStringConverter = new ShapeStringConverter(options);
 }
コード例 #16
0
        new internal readonly NtsSpatialContext ctx;//note: masks superclass

        public NtsWktShapeParserTest()
            : base(NtsSpatialContext.GEO)
        {
            this.ctx = (NtsSpatialContext)base.ctx;
        }
コード例 #17
0
 public NtsBinaryCodec(NtsSpatialContext ctx, NtsSpatialContextFactory factory)
     : base(ctx, factory)
 {
     //note: ctx.geometryFactory hasn't been set yet
     useFloat = (factory.precisionModel.PrecisionModelType == PrecisionModels.FloatingSingle);
 }
コード例 #18
0
 public NtsShapeReadWriter(NtsSpatialContext ctx, bool normalizeGeomCoords)
     : base(ctx)
 {
     this.normalizeGeomCoords = normalizeGeomCoords;
 }
コード例 #19
0
 private static NtsShapeReadWriter CreateNtsShapeReadWriter(SpatialOptions opt, NtsSpatialContext ntsContext)
 {
     if (opt.Type == SpatialFieldType.Cartesian)
     {
         return(new NtsShapeReadWriter(ntsContext, false));
     }
     return(_geoShapeReadWriter ?? (_geoShapeReadWriter = new NtsShapeReadWriter(ntsContext, false)));
 }
コード例 #20
0
        public virtual void TestPoly()
        {
            NtsSpatialContext ctx = (NtsSpatialContext)base.ctx;

            ctx.MakeShape(RandomGeometry(random.Next(3, 20)), false, false);
        }
コード例 #21
0
        //Note: Historically, the code here originated from the defunct NtsShapeReadWriter.

        public NtsWKTReaderShapeParser(NtsSpatialContext ctx, NtsSpatialContextFactory factory)
            : base(ctx, factory)
        {
        }
コード例 #22
0
 public ShapeReaderWriterCoordinateSequenceFilter(NtsSpatialContext ctx, bool normalizeGeomCoords)
 {
     _ctx = ctx;
     _normalizeGeomCoords = normalizeGeomCoords;
 }
コード例 #23
0
 internal static bool once = false;//cheap way to test it was created
 public CustomWktShapeParser(NtsSpatialContext ctx, NtsSpatialContextFactory factory)
     : base(ctx, factory)
 {
     once = true;
 }
コード例 #24
0
ファイル: SpatialField.cs プロジェクト: otgoo0603/ravendb
 static SpatialField()
 {
     GeometryServiceProvider.Instance = new NtsGeometryServices();
     GeoContext = new NtsSpatialContext(true);
 }
コード例 #25
0
        private bool normalizeGeomCoords = true;//TODO make configurable

        public NtsShapeReadWriter(NtsSpatialContext ctx)
            : base(ctx)
        {
        }