public async Task <ActionResult <List <MovieTheaterCloseDTO> > > Closers ( [FromQuery] MovieTheaterCloseFilterDTO filter ) { var userLocation = _geometryFactory.CreatePoint(new Coordinate(filter.Longitude, filter.Latitude)); var movieTheaters = await _context.MovieTheaters .OrderBy(x => x.Location.Distance(userLocation)) .Where(x => x.Location.IsWithinDistance(userLocation, filter.DistanceInKM * 1000)) .Select(x => new MovieTheaterCloseDTO { Id = x.Id, Name = x.Name, Latitude = x.Location.Y, Longitude = x.Location.X, DistanceInMts = Math.Round(x.Location.Distance(userLocation)) }) .ToListAsync(); return(movieTheaters); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity <Blog>( b => { b.Property(e => e.CreatedOn).HasDefaultValueSql("getdate()"); b.Property(e => e.GeometryCollection).HasDefaultValue(GeometryFactory.CreateGeometryCollection()); b.HasData( new Blog { Id = 9979, Name = "W Unicorns", CreatedOn = new DateTime(1974, 8, 3, 0, 10, 0), NeedsConverter = new NeedsConverter(111), GeometryCollection = GeometryFactory.CreateGeometryCollection( new Geometry[] { GeometryFactory.CreatePoint(new Coordinate(1, 2)) }) }); }); }
private static void AddPoints([NotNull] IFeatureClass fc) { IFeature row1 = fc.CreateFeature(); row1.Shape = GeometryFactory.CreatePoint(10, 10); row1.Store(); IFeature row2 = fc.CreateFeature(); row2.Shape = GeometryFactory.CreatePoint(11, 11); row2.Store(); IFeature row3 = fc.CreateFeature(); row3.Shape = GeometryFactory.CreatePoint(20, 20); row3.Store(); IFeature row4 = fc.CreateFeature(); row4.Shape = GeometryFactory.CreatePoint(40, 40); row4.Store(); }
public void CanInsertVertexIntoPolygon() { ISpatialReference lv95 = CreateSpatialReference(0.0125, 0.0125); IPolygon polygon = GeometryFactory.CreatePolygon(1000, 2000, 1500, 2500, lv95); GeometryUtils.Simplify(polygon, false); Assert.AreEqual(4, ((ISegmentCollection)polygon).SegmentCount); IPoint newPoint = GeometryFactory.CreatePoint(1250, 2000, lv95); SegmentReplacementUtils.InsertVertex(newPoint, 3, 0, (ISegmentCollection)polygon); Assert.AreEqual(5, ((ISegmentCollection)polygon).SegmentCount); newPoint = GeometryFactory.CreatePoint(1000, 2250, lv95); SegmentReplacementUtils.InsertVertex(newPoint, 0, 0, (ISegmentCollection)polygon); Assert.AreEqual(6, ((ISegmentCollection)polygon).SegmentCount); }
private Point CreatePoint(int dim, int lrs, Decimal[] elemInfo, int elemIndex, List <Coordinate> coords) { int sOffset = StartingOffset(elemInfo, elemIndex); SdoEType etype = EType(elemInfo, elemIndex); int interpretation = Interpretation(elemInfo, elemIndex); if (!(sOffset >= 1) || !(sOffset <= coords.Count)) { throw new ArgumentException("ELEM_INFO STARTING_OFFSET " + sOffset + " inconsistent with ORDINATES length " + coords.Count); } if (etype != SdoEType.Coordinate) { throw new ArgumentException("ETYPE " + etype + " inconsistent with expected POINT"); } if (interpretation != 1) { return(null); } int len = (dim + lrs); int start = (sOffset - 1) / len; int eOffset = StartingOffset(elemInfo, elemIndex + 1); // -1 for end Coordinate point; if ((sOffset == 1) && (eOffset == -1)) { // Use all Coordinates point = coords[0]; } else { int end = (eOffset != -1) ? ((eOffset - 1) / len) : coords.Count; point = SubList(coords, start, end)[0]; } return(_factory.CreatePoint(point)); }
public void test_Coordinates() { //create a new point GeometryFactory gf = new GeometryFactory(_precMod, _sRID); Point point = gf.CreatePoint(_coor); //returns a coordinates object Coordinates coordinates = point.GetCoordinates(); //test to make sure only one coordinate is returned for a point Assertion.AssertEquals("Coordinates1: ", 1, coordinates.Count); foreach (Coordinate coord in coordinates) { //test to make sure that the coordinates returned are equal to the coordinates sent Assertion.AssertEquals("test :", true, coord.Equals(_coor)); //testing each coordinate just to be sure Assertion.AssertEquals("Coordinates2: ", _coor.X, coord.X); Assertion.AssertEquals("Coordinates3: ", _coor.Y, coord.Y); } }
/// <summary> /// Creates a <see cref="Point"/> <see cref="Feature"/> that contains the same data stored /// in a given <see cref="GpxWaypoint"/>. /// </summary> /// <param name="waypoint"> /// The <see cref="GpxWaypoint"/> source. /// </param> /// <param name="geometryFactory"> /// The <see cref="GeometryFactory"/> to use to create the <see cref="Point"/>, or /// <see langword="null"/> to create a new one to use on-the-fly using the current /// <see cref="NtsGeometryServices"/>. /// </param> /// <returns> /// A <see cref="Feature"/> that contains the same data as <paramref name="waypoint"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// Thrown when <paramref name="waypoint"/> is <see langword="null"/> /// </exception> /// <remarks> /// The values of <see cref="Feature.Attributes"/> will be populated with the values of the /// <see cref="GpxWaypoint"/> properties, even when <see langword="null"/>, with exceptions: /// <list type="bullet"> /// <item><description><see cref="GpxWaypoint.Longitude"/> goes to <see cref="Point.X"/> instead,</description></item> /// <item><description><see cref="GpxWaypoint.Latitude"/> goes to <see cref="Point.Y"/> instead, and</description></item> /// <item><description><see cref="GpxWaypoint.ElevationInMeters"/> goes to <see cref="Point.Z"/> instead (when it's set)</description></item> /// </list> /// </remarks> public static Feature ToFeature(GpxWaypoint waypoint, GeometryFactory geometryFactory) { if (waypoint is null) { throw new ArgumentNullException(nameof(waypoint)); } if (geometryFactory is null) { geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(); } // a waypoint all on its own is an Point feature. var coord = new CoordinateZ(waypoint.Longitude, waypoint.Latitude, waypoint.ElevationInMeters ?? Coordinate.NullOrdinate); var point = geometryFactory.CreatePoint(coord); var attributes = new AttributesTable { { nameof(waypoint.TimestampUtc), waypoint.TimestampUtc }, { nameof(waypoint.Name), waypoint.Name }, { nameof(waypoint.Description), waypoint.Description }, { nameof(waypoint.SymbolText), waypoint.SymbolText }, { nameof(waypoint.MagneticVariation), waypoint.MagneticVariation }, { nameof(waypoint.GeoidHeight), waypoint.GeoidHeight }, { nameof(waypoint.Comment), waypoint.Comment }, { nameof(waypoint.Source), waypoint.Source }, { nameof(waypoint.Links), waypoint.Links }, { nameof(waypoint.Classification), waypoint.Classification }, { nameof(waypoint.FixKind), waypoint.FixKind }, { nameof(waypoint.NumberOfSatellites), waypoint.NumberOfSatellites }, { nameof(waypoint.HorizontalDilutionOfPrecision), waypoint.HorizontalDilutionOfPrecision }, { nameof(waypoint.VerticalDilutionOfPrecision), waypoint.VerticalDilutionOfPrecision }, { nameof(waypoint.PositionDilutionOfPrecision), waypoint.PositionDilutionOfPrecision }, { nameof(waypoint.SecondsSinceLastDgpsUpdate), waypoint.SecondsSinceLastDgpsUpdate }, { nameof(waypoint.DgpsStationId), waypoint.DgpsStationId }, { nameof(waypoint.Extensions), waypoint.Extensions }, }; return(new Feature(point, attributes)); }
public void LearningTestCanSubtractPointFromMultipoint() { IPoint p1 = GeometryFactory.CreatePoint(10, 5, 1000); IPoint p2 = GeometryFactory.CreatePoint(10, 6, 1000); IMultipoint g1 = GeometryFactory.CreateMultipoint(p1, p2); IPoint g2 = GeometryFactory.Clone(p2); IGeometry result = ((ITopologicalOperator)g1).Difference(g2); Console.WriteLine(@"result:"); Console.WriteLine(GeometryUtils.ToString(result)); Console.WriteLine(@"p1:"); Console.WriteLine(GeometryUtils.ToString(p1)); Assert.IsFalse(result.IsEmpty); var resultPoints = (IPointCollection)result; Assert.IsTrue(resultPoints.PointCount == 1); Assert.IsTrue(GeometryUtils.AreEqual(resultPoints.Point[0], p1)); }
public static IReadOnlyList <PointEntity> CreatePointEntities(GeometryFactory factory) { var entities = new[] { new PointEntity { Id = PointEntity.WellKnownId, Point = factory.CreatePoint( new Coordinate(0, 0)) }, new PointEntity { Id = Guid.Parse("67A54C9B-4C3B-4B27-8B4E-C0335E50E551"), Point = null } }; foreach (var entity in entities) { entity.Geometry = entity.Point?.Copy(); } return(entities); }
public void CanDeterminePolygonReshapeSideOutsideOnlyCuttingOffIsland() { // ________ // / _____ | // /__/ h / | //--------------- // The original polygon is below the reshape line (dashed-line ---) ISpatialReference spatialReference = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95); IGeometry geometryToReshape = GeometryFactory.CreatePolygon(100, 100, 200, 200, spatialReference); IGeometry reshapeLine = GeometryFactory.CreatePolyline(spatialReference, GeometryFactory.CreatePoint(200, 200), GeometryFactory.CreatePoint(200, 250), GeometryFactory.CreatePoint(125, 250), GeometryFactory.CreatePoint(125, 200), GeometryFactory.CreatePoint(150, 200), GeometryFactory.CreatePoint(150, 225), GeometryFactory.CreatePoint(175, 225), GeometryFactory.CreatePoint(175, 200)); // plus 50 * 75 minus 25 * 25 = 3750 - 625 = 13125 ReshapeInfo reshapeInfo = Reshape(GeometryFactory.Clone(geometryToReshape), reshapeLine, false); ExpectResult(reshapeInfo, RingReshapeSideOfLine.Left, 13125, 2, 1); const bool useNonDefaultSide = true; reshapeInfo = Reshape(GeometryFactory.Clone(geometryToReshape), reshapeLine, useNonDefaultSide); // not allowing non-default ExpectResult(reshapeInfo, RingReshapeSideOfLine.Left, 13125, 2, 1); }
public void CanGetZigZagNonPlanarLineError() { // the source polyline visits the same points several times by going back and forth ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95); var fc = new FeatureClassMock(1, "Fc", esriGeometryType.esriGeometryPolyline, esriFeatureType.esriFTSimple, lv95); IPolyline sourcePolyline = GeometryFactory.CreatePolyline( lv95, GeometryFactory.CreatePoint(0, 0), GeometryFactory.CreatePoint(10, 0), GeometryFactory.CreatePoint(20, 0), GeometryFactory.CreatePoint(10, 0), GeometryFactory.CreatePoint(20, 0), GeometryFactory.CreatePoint(30, 10)); IFeature f = fc.CreateFeature(sourcePolyline); var test = new QaSimpleGeometry(fc, true); var runner = new QaTestRunner(test); runner.Execute(f); Assert.AreEqual(0, runner.Errors.Count); test = new QaSimpleGeometry(fc, false); runner = new QaTestRunner(test) { KeepGeometry = true }; runner.Execute(f); Assert.AreEqual(1, runner.Errors.Count); Assert.AreEqual(2, ((IPointCollection)runner.ErrorGeometries[0]).PointCount); }
public void CanExecuteContainerOneDiagonalLine() { IFeatureClass featureClass = CreatePolylineFeatureClass("CanExecuteContainerOneDiagonalLine", 0.01); // Create error Feature IFeature row = featureClass.CreateFeature(); const double x = 2600000; const double y = 1200000; row.Shape = GeometryFactory.CreateLine( GeometryFactory.CreatePoint(x, y), GeometryFactory.CreatePoint(x + 1000, y + 800)); row.Store(); var helper = new CanExecuteContainerHelper(); helper.ExpectedMaximumRowCountPerTile = 1; var test = new VerifyingContainerTest((ITable)featureClass) { OnExecuteCore = helper.ExecuteRow, OnCompleteTile = helper.CompleteTile }; test.SetSearchDistance(10); var container = new TestContainer.TestContainer { TileSize = 600 }; container.AddTest(test); container.Execute(); Assert.AreEqual(4 + 1, helper.CompleteTileCount); // + 1 : wegen initialem Tile Assert.AreEqual(4, helper.ExecuteRowCount); // 1 feature x 4 intersected tiles }
public void CantGetDistanceToNonPlanarPolygon() { const double z1 = 10; var g1 = GeometryFactory.CreatePoint(100, 0, z1); var polygon = CurveConstruction.StartPoly(0, 0, 10) .LineTo(10, 0, 10) .LineTo(10, 10, 11) .LineTo(0, 10, 10) .ClosePolygon(); var polygonClass = new FeatureClassMock( 1, "polygon", esriGeometryType.esriGeometryPolygon, esriFeatureType.esriFTSimple, SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95)); var feature = polygonClass.CreateFeature(polygon); var intersectionPoints = ZDifferenceStrategyIntersectionPoints.GetDistanceToPlane( g1, feature, 0.01); foreach (var either in intersectionPoints) { either.Match(e => { Console.WriteLine( $@"expected nonplanar error: {e.Message} ({e.MaximumOffset})"); Assert.AreEqual(0.3324801391253977, e.MaximumOffset); return(0); }, pts => { Assert.Fail("Unexpected intersection point"); return(-1); }); } }
public void CanReportVertexInLeftTileByNearDistance() { const string testName = "CanReportVertexInLeftTileByNearDistance"; IFeatureClass nodeClass = CreateFeatureClass(string.Format("{0}_node", testName), esriGeometryType.esriGeometryPoint); IFeatureClass nearClass = CreateFeatureClass(string.Format("{0}_near", testName), esriGeometryType.esriGeometryPolyline); var nearClasses = new List <IFeatureClass> { nearClass }; IFeature nodeRow = nodeClass.CreateFeature(); nodeRow.Shape = GeometryFactory.CreatePoint(201, 100); nodeRow.Store(); IFeature nearRow = nearClass.CreateFeature(); nearRow.Shape = CurveConstruction.StartLine(100, 100) .LineTo(100, 199) .LineTo(199, 199) .LineTo(199, 100) .Curve; nearRow.Store(); IEnvelope verificationEnvelope = GeometryFactory.CreateEnvelope(0, 0, 500, 500); var test = new QaNodeLineCoincidence(nodeClass, nearClasses, 2.1); var runner = new QaContainerTestRunner(200, test); runner.Execute(verificationEnvelope); AssertUtils.OneError(runner, "NodeLineCoincidence.NodeTooCloseToLine.BetweenFeatures"); }
public void CanAllowVertexWithinCoincidenceTolerance() { const string testName = "CanAllowVertexWithinCoincidenceTolerance"; IFeatureClass nodeClass = CreateFeatureClass(string.Format("{0}_node", testName), esriGeometryType.esriGeometryPoint); IFeatureClass nearClass = CreateFeatureClass(string.Format("{0}_near", testName), esriGeometryType.esriGeometryPolyline); var nearClasses = new List <IFeatureClass> { nearClass }; IFeature nodeRow = nodeClass.CreateFeature(); nodeRow.Shape = GeometryFactory.CreatePoint(1, 0.1); nodeRow.Store(); IFeature nearRow = nearClass.CreateFeature(); nearRow.Shape = CurveConstruction.StartLine(0, 0) .LineTo(2, 0) .Curve; nearRow.Store(); IEnvelope verificationEnvelope = GeometryFactory.CreateEnvelope(0, 0, 500, 500); var test = new QaNodeLineCoincidence(nodeClass, nearClasses, 2) { CoincidenceTolerance = 0.2 }; var runner = new QaContainerTestRunner(1000, test); runner.Execute(verificationEnvelope); AssertUtils.NoError(runner); }
private void Form2_Load(object sender, EventArgs e) { var tileLayer = new TileAsyncLayer(KnownTileSources.Create(KnownTileSource.BingRoadsStaging), "TileLayer"); this.mapBox1.Map.BackgroundLayer.Add(tileLayer); GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 3857); IMathTransform mathTransform = LayerTools.Wgs84toGoogleMercator.MathTransform; Envelope geom = GeometryTransform.TransformBox( new Envelope(-9.205626, -9.123736, 38.690993, 38.740837), mathTransform); //Adds a pushpin layer VectorLayer pushPinLayer = new VectorLayer("PushPins"); List <IGeometry> geos = new List <IGeometry>(); geos.Add(gf.CreatePoint(geom.Centre)); GeometryProvider geoProvider = new GeometryProvider(geos); pushPinLayer.DataSource = geoProvider; //this.mapBox1.Map.Layers.Add(pushPinLayer); // ScaleGraticule this.mapBox1.Map.Layers.AddCollection(CreateGraticuleLayers()); // ScaleBar this.mapBox1.Map.SRID = 3857; this.mapBox1.Map.Decorations.Add( new ScaleBar { Anchor = MapDecorationAnchor.RightCenter, Enabled = chkScaleBar.Checked }); this.mapBox1.Map.ZoomToBox(geom); this.mapBox1.Map.Zoom = 8500; this.mapBox1.Refresh(); }
List <Point> CreatePoints(Envelope env, int nPts) { int nCells = (int)Math.Sqrt(nPts); var geoms = new List <Point>(); double width = env.Width; double xInc = width / nCells; double yInc = width / nCells; for (int i = 0; i < nCells; i++) { for (int j = 0; j < nCells; j++) { var @base = new Coordinate( env.MinX + i * xInc, env.MinY + j * yInc); var pt = fact.CreatePoint(@base); geoms.Add(pt); } } return(geoms); }
public void CanIntersectCircleWithRectangle() { var z1 = 100.0; var z2 = 200.0; var g1 = GeometryFactory.CreateCircleArcPolygon( GeometryFactory.CreatePoint(100, 100, z1), 10); var g2 = GeometryFactory.CreatePolygon(0, 0, 100, 200); GeometryUtils.MakeZAware(g1); GeometryUtils.MakeZAware(g2); GeometryUtils.ConstantZ(g1, z1); GeometryUtils.ConstantZ(g2, z2); Check(g1, g2, 2, (p, i) => At(i == 0, Equals(100, 110, z1, p.Point)) && At(i == 1, Equals(100, 90, z1, p.Point))); Check(g2, g1, 2, (p, i) => At(i == 0, Equals(100, 90, z2, p.Point)) && // TODO revise At(i == 1, Equals(100, 110, z2, p.Point))); // TODO revise }
public AutoMapperProfiles(GeometryFactory geometryFactory) { CreateMap <Genero, GeneroDTO>().ReverseMap(); CreateMap <GeneroCreacionDTO, Genero>(); CreateMap <Actor, ActorDTO>().ReverseMap(); CreateMap <ActorCreacionDTO, Actor>() .ForMember(x => x.Foto, options => options.Ignore()); CreateMap <CineCreacionDTO, Cine>() .ForMember(x => x.Ubicacion, x => x.MapFrom(dto => geometryFactory.CreatePoint(new Coordinate(dto.Longitud, dto.Latitud)))); CreateMap <Cine, CineDTO>() .ForMember(x => x.Latitud, dto => dto.MapFrom(campo => campo.Ubicacion.Y)) .ForMember(x => x.Longitud, dto => dto.MapFrom(campo => campo.Ubicacion.X)); CreateMap <PeliculaCreacionDTO, Pelicula>() .ForMember(x => x.Poster, opciones => opciones.Ignore()) .ForMember(x => x.PeliculasGeneros, opciones => opciones.MapFrom(MapearPeliculasGeneros)) .ForMember(x => x.PeliculasCines, opciones => opciones.MapFrom(MapearPeliculasCines)) .ForMember(x => x.PeliculasActores, opciones => opciones.MapFrom(MapearPeliculasActores)); CreateMap <Pelicula, PeliculaDTO>() .ForMember(x => x.Generos, options => options.MapFrom(MapearPeliculasGeneros)) .ForMember(x => x.Actores, options => options.MapFrom(MapearPeliculasActores)) .ForMember(x => x.Cines, options => options.MapFrom(MapearPeliculasCines)); }
public void GivenFeatureWithAllAttributes_WhenConvertFeatureToDtoIsCalled_ThenDtoShouldBeHaveAllPropertiesSet() { // Arrange const string address = "Piazza di Pasquino"; const string name = "Statua di Pasquino"; const string category = "Monument / Landmark"; const double longValue = 12.471773d; const double latValue = 41.897832155228d; var geometryFactory = new GeometryFactory(); var point = geometryFactory.CreatePoint(new Coordinate(longValue, latValue)); var feature = new Feature(point, new AttributesTable(new Dictionary <string, object> { { "address", address }, { "name", name }, { "category", category } })); var converter = new FeatureConverter(); // Act var featureDto = converter.ConvertFeatureToDto(feature); // Assert Assert.Equal(name, featureDto.Name); Assert.Equal(longValue, featureDto.PointGeometry.Coordinates[0]); Assert.Equal(latValue, featureDto.PointGeometry.Coordinates[1]); }
/// <summary> /// 绘制点 /// </summary> /// <param name="x">X值</param> /// <param name="y">Y值</param> /// <param name="z">Z值</param> private void DrawTopPoint(double x, double y, double z) { if (_TopPoint == null) { IGeometryFactory geometryFactory = new GeometryFactory(); _TopPoint = geometryFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ); } _TopPoint.SetCoords(x, y, z, 0, 0); if (_EndRenderPoint == null) { _EndRenderPoint = _AxRenderControl.ObjectManager.CreateRenderPoint(_TopPoint, _PointSymbol, rootId); _EndRenderPoint.MaxVisibleDistance = double.MaxValue; _EndRenderPoint.MinVisiblePixels = 1; } else { _EndRenderPoint.SetFdeGeometry(_TopPoint); } _EndRenderPoint.VisibleMask = gviViewportMask.gviViewAllNormalView; }
public void CanConvertToFromFeatureList() { var sr = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LN02); var fClass1 = new GdbFeatureClass(123, "TestFC", esriGeometryType.esriGeometryPolygon); fClass1.SpatialReference = sr; GdbFeature featureWithNoShape = new GdbFeature(41, fClass1); IPolygon polygon = GeometryFactory.CreatePolygon( GeometryFactory.CreatePoint(2600000, 1200000, sr), GeometryFactory.CreatePoint(2601000, 1201000, sr)); polygon.SpatialReference = sr; GdbFeature featureWithShape = new GdbFeature(42, fClass1) { Shape = polygon }; var fClass2 = new GdbFeatureClass(124, "TestClass2", esriGeometryType.esriGeometryMultipoint); fClass2.SpatialReference = sr; GdbFeature multipointFeature = new GdbFeature(41, fClass2); AssertCanConvertToDtoAndBack(new List <IFeature> { featureWithNoShape, multipointFeature, featureWithShape }); }
public void CutCurveHullTest() { //seg0 = CreateSegment(GeometryFactory.CreatePoint(0, 0, 0), GeometryFactory.CreatePoint(100, 200, 10)); //seg1 = CreateSegment(GeometryFactory.CreatePoint(0, 0, 0), GeometryFactory.CreatePoint(100, 200, 10)); //SegmentUtils.CutCurveHull(seg0, seg1, 0, 0, true, // out limits, out hullStartNear, out hullEndNear, out coincident); const double r = 0.0001; const double x0 = 600000; const double y0 = 200000; SegmentProxy seg0 = CreateSegment( GeometryFactory.CreatePoint(x0 + 100, y0 + 200, 10), GeometryFactory.CreatePoint(x0, y0, 500)); SegmentProxy seg1 = CreateSegment( GeometryFactory.CreatePoint(x0, y0, 500 + 2 * r), GeometryFactory.CreatePoint(x0 - 200 - r, y0, 20)); IList <double[]> limits; NearSegment hullStartNear; NearSegment hullEndNear; bool coincident; SegmentHull hull0 = seg0.CreateHull(0); SegmentHull hull1 = seg1.CreateHull(0); var pair2D = new SegmentPair2D(hull0, hull1); pair2D.CutCurveHull(0, out limits, out hullStartNear, out hullEndNear, out coincident); Assert.AreEqual(1, limits.Count); var pair3D = new SegmentPair3D(hull0, hull1); pair3D.CutCurveHull(0, out limits, out hullStartNear, out hullEndNear, out coincident); Assert.AreEqual(0, limits.Count); }
public Geometry Edit(Geometry geom, GeometryFactory factory) { factory = factory ?? geom.Factory; if (geom is Point) { return(factory.CreatePoint(((Point)geom).CoordinateSequence)); } if (geom is LineString) { return(RemoveSpikesFromLineString((LineString)geom, factory)); } if (geom is Polygon) { var poly = (Polygon)geom; var exteriorRing = RemoveSpikesFromLineString(poly.ExteriorRing, factory, true); var interiorRings = new List <LinearRing>(poly.NumInteriorRings); for (int i = 0; i < poly.NumInteriorRings; i++) { interiorRings.Add((LinearRing)RemoveSpikesFromLineString(poly.GetInteriorRingN(i), factory, true)); } return(factory.CreatePolygon((LinearRing)exteriorRing, interiorRings.ToArray())); } if (geom is GeometryCollection) { var lst = new List <Geometry>(); for (int i = 0; i < geom.NumGeometries; i++) { lst.Add(Edit(geom.GetGeometryN(i), geom.Factory)); } return(factory.CreateGeometryCollection(lst.ToArray())); } Utilities.Assert.ShouldNeverReachHere("Unhandled geometry type"); return(null); }
public void CanGetDistanceToPlanarPolygon() { const double z1 = 10; const double z2 = 20; var g1 = GeometryFactory.CreatePoint(100, 0, z1); var g2 = GeometryFactory.CreatePolygon(0, 0, 100, 200); GeometryUtils.MakeZAware(g2); g2 = GeometryUtils.ConstantZ(g2, z2); var polygonClass = new FeatureClassMock( 1, "polygon", esriGeometryType.esriGeometryPolygon, esriFeatureType.esriFTSimple, SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95)); var feature = polygonClass.CreateFeature(g2); var intersectionPoints = ZDifferenceStrategyIntersectionPoints.GetDistanceToPlane( g1, feature, 0.01); foreach (var either in intersectionPoints) { either.Match(e => { Assert.Fail($"unexpected nonplanar error: {e.Message}"); return(-1); }, pts => { var points = pts.ToList(); Assert.AreEqual(1, points.Count); Assert.AreEqual(z2 - z1, points[0].Distance); return(0); }); } }
public void CanGetNoDuplicatesMultipointPoints() { const double xyTolerance = 0.1; const double zTolerance = 0.1; IMultipoint original = GeometryFactory.CreateMultipoint( GeometryFactory.CreatePoint(100, 1000, 5000), GeometryFactory.CreatePoint(200, 1000, 5000), GeometryFactory.CreatePoint(300, 1000, 5000), GeometryFactory.CreatePoint(100, 2000, 5000), GeometryFactory.CreatePoint(100, 3000, 5000) ); original.SpatialReference = CreateSpatialReference(xyTolerance, zTolerance); IMultipoint clone = GeometryFactory.Clone(original); GeometryUtils.Simplify(clone); var vertexComparer = new GeometryComparison(original, clone, xyTolerance, zTolerance); IList <WKSPointZ> result = vertexComparer.GetDifferentVertices(true); Assert.AreEqual(0, result.Count); // Flip geometries: vertexComparer = new GeometryComparison(clone, original, xyTolerance, zTolerance); result = vertexComparer.GetDifferentVertices(true); Assert.AreEqual(0, result.Count); Assert.True(vertexComparer.HaveSameVertices()); Assert.True(vertexComparer.HaveSameVertices(false)); }
public void CanDeterminePolygonReshapeSideInsideAndOutsideOnePartWithCutBack() { // _ _ // / \ / \ //--\--\-----/-- \ \-----/ // \ / -> \ / // \____/ \____/ ISpatialReference spatialReference = SpatialReferenceUtils.CreateSpatialReference( WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95); IGeometry geometryToReshape = GeometryFactory.CreatePolygon(100, 100, 200, 200, spatialReference); IGeometry reshapeLine = GeometryFactory.CreatePolyline(spatialReference, GeometryFactory.CreatePoint(125, 200), GeometryFactory.CreatePoint(125, 150), GeometryFactory.CreatePoint(175, 150), GeometryFactory.CreatePoint(175, 250), GeometryFactory.CreatePoint(150, 250), GeometryFactory.CreatePoint(150, 200)); // one quarter plus 50 * 25 = 3750 ReshapeInfo reshapeInfo = Reshape(GeometryFactory.Clone(geometryToReshape), reshapeLine, false); ExpectResult(reshapeInfo, RingReshapeSideOfLine.Left, 3750, 1, 1); const bool useNonDefaultSide = true; reshapeInfo = Reshape(GeometryFactory.Clone(geometryToReshape), reshapeLine, useNonDefaultSide); // standard inside-outside, not allowing non-default ExpectResult(reshapeInfo, RingReshapeSideOfLine.Left, 3750, 1, 1); }
private static void CanCreateUnionWithPointsAndPolylinesFastEnoughCore() { var input = new List <IGeometry>(); for (int i = 0; i < 100; i++) { input.Add(GeometryFactory.CreatePoint(100 * i, 100 * i)); } double xmin = 0; for (int i = 0; i < 1000; i++) { xmin = xmin + 100; double xmax = xmin + 100; input.Add(GeometryFactory.CreatePolyline(xmin, 100, xmax, 100)); } var watch = new Stopwatch(); watch.Start(); var memoryInfo = new MemoryUsageInfo(); const double expansionDistance = 10; IGeometry union = GeometryFactory.CreateUnion(input, expansionDistance); GC.Collect(); watch.Stop(); memoryInfo.Refresh(); Console.WriteLine(memoryInfo); Console.WriteLine(@"{0:N2} ms", watch.ElapsedMilliseconds); Assert.AreEqual(esriGeometryType.esriGeometryPolyline, union.GeometryType); }
public Geometry Union() { var locater = new PointLocator(); // use a set to eliminate duplicates, as required for union var exteriorCoords = new HashSet <Coordinate>(); foreach (Point point in PointExtracter.GetPoints(_pointGeom)) { var coord = point.Coordinate; var loc = locater.Locate(coord, _otherGeom); if (loc == Location.Exterior) { exteriorCoords.Add(coord); } } // if no points are in exterior, return the other geom if (exteriorCoords.Count == 0) { return(_otherGeom); } // make a puntal geometry of appropriate size var exteriorCoordsArray = new Coordinate[exteriorCoords.Count]; exteriorCoords.CopyTo(exteriorCoordsArray, 0); Array.Sort(exteriorCoordsArray); var coords = _geomFact.CoordinateSequenceFactory.Create(exteriorCoordsArray); var ptComp = coords.Count == 1 ? (Geometry)_geomFact.CreatePoint(coords) : _geomFact.CreateMultiPoint(coords); // add point component to the other geometry return(GeometryCombiner.Combine(ptComp, _otherGeom)); }
/// <summary> /// Creates an empty result geometry of the appropriate dimension, /// based on the given overlay operation and the dimensions of the inputs. /// The created geometry is always an atomic geometry, /// not a collection. /// <para/> /// The empty result is constructed using the following rules: /// <list type="bullet"> /// <item><description><see cref="SpatialFunction.Intersection"/> - result has the dimension of the lowest input dimension</description></item> /// <item><description><see cref="SpatialFunction.Union"/> - result has the dimension of the highest input dimension</description></item> /// <item><description><see cref="SpatialFunction.Difference"/> - result has the dimension of the left-hand input</description></item> /// <item><description><see cref="SpatialFunction.SymDifference"/> - result has the dimension of the highest input dimension /// (since symDifference is the union of the differences).</description></item> /// </list> /// </summary> /// <param name="overlayOpCode">The overlay operation being performed</param> /// <param name="a">An input geometry</param> /// <param name="b">An input geometry</param> /// <param name="geomFact">The geometry factory being used for the operation</param> /// <returns>An empty atomic geometry of the appropriate dimension</returns> public static Geometry CreateEmptyResult(SpatialFunction overlayOpCode, Geometry a, Geometry b, GeometryFactory geomFact) { Geometry result = null; switch (ResultDimension(overlayOpCode, a, b)) { case Dimension.False: result = geomFact.CreateGeometryCollection(); break; case Dimension.Point: result = geomFact.CreatePoint(); break; case Dimension.Curve: result = geomFact.CreateLineString(); break; case Dimension.Surface: result = geomFact.CreatePolygon(); break; } return(result); }