public void TestCreatePolygonWithNull() { Geometry p = null; Assert.That(() => p = Factory.CreatePolygon((CoordinateSequence)null), Throws.Nothing); Assert.That(p.IsEmpty); Assert.That(() => p = Factory.CreatePolygon((Coordinate[])null), Throws.Nothing); Assert.That(p.IsEmpty); Assert.That(() => p = Factory.CreatePolygon((LinearRing)null), Throws.Nothing); Assert.That(p.IsEmpty); Assert.That(() => p = Factory.CreatePolygon(null, null), Throws.Nothing); Assert.That(p.IsEmpty); }
public static double GetLength([NotNull] IGeometry geometry) { var curve = geometry as ICurve; if (curve != null) { return(curve.Length); } var multiPatch = geometry as IMultiPatch; if (multiPatch != null) { IPolygon footprint = null; try { footprint = GeometryFactory.CreatePolygon(multiPatch); return(footprint.Length); } finally { if (footprint != null) { Marshal.ReleaseComObject(footprint); } } } return(0); }
public static IPolyline GetPreprocessedGeometryForExtent( IGeometry geometry, [CanBeNull] IEnvelope clipExtent) { IPolyline processedGeometry; if (geometry.GeometryType == esriGeometryType.esriGeometryMultiPatch) { geometry = GeometryFactory.CreatePolygon(geometry); } if (clipExtent != null) { // NOTE: convert polygons to polylines first otherwise clipped target lines intersect the // clipped polygon on the display boundary processedGeometry = GetClippedOutline(geometry, clipExtent); } else { processedGeometry = GeometryFactory.CreatePolyline(geometry); // For symmetry with clipped case: merge adjacent lines to avoid non-matching difference/target parts // in ReshapableSubcurveCalculator.GetTargetSegmentsAlong() used for minimum tolerance GeometryUtils.Simplify(processedGeometry, true, true); } return(processedGeometry); }
private static IPointCollection GetPoints(IPointCollection pointCollection, IGeometry inArea) { if (pointCollection == null || pointCollection.PointCount == 0) { return(null); } if (inArea == null) { return(pointCollection); } if (GeometryUtils.Disjoint(inArea, (IGeometry)pointCollection)) { return(null); } // because intersecting multipoints with envelope is not implemented: var withinPolygon = inArea as IPolygon; withinPolygon = withinPolygon ?? GeometryFactory.CreatePolygon(inArea); var result = (IPointCollection) IntersectionUtils.GetIntersection((IGeometry)pointCollection, withinPolygon); return(result); }
public Polygon GetProcessingPerimeter() { switch (SelectionType) { case ProcessSelectionType.SelectedFeatures: return(null); case ProcessSelectionType.SelectedFeaturesWithinPerimeter: return(EditPerimeter); case ProcessSelectionType.VisibleExtent: return(GeometryFactory.CreatePolygon(VisibleExtent)); case ProcessSelectionType.VisibleExtentWithinPerimeter: return(GeometryUtils.Intersection(VisibleExtent, EditPerimeter)); case ProcessSelectionType.AllFeatures: return(null); case ProcessSelectionType.AllFeaturesWithinPerimeter: return(EditPerimeter); default: throw new ArgumentOutOfRangeException(nameof(SelectionType)); } }
public IGeometry GetGeometry(GeometryFactory fact) { ILinearRing ring = fact.CreateLinearRing(GetCoordinates()); IPolygon tri = fact.CreatePolygon(ring, null); return(tri); }
public async System.Threading.Tasks.Task Should_Get_Hashes_For_PolygonAsync() { var hasher = new Geohasher(); var geometryFactory = new GeometryFactory(); var p1 = new Coordinate() { X = 9.612350463867186, Y = 52.31141727938367 }; var p2 = new Coordinate() { X = 9.914474487304686, Y = 52.31141727938367 }; var p3 = new Coordinate() { X = 9.914474487304686, Y = 52.42252295423907 }; var p4 = new Coordinate() { X = 9.612350463867186, Y = 52.42252295423907 }; var polygon = geometryFactory.CreatePolygon(new[] { p1, p2, p3, p4, p1 }); var result = await hasher.GetHashesAsync(polygon, 6); Assert.AreEqual(486, result.Count); }
public void GetElementsIndicesWithWeight_PolygonAccrossMeshElement(bool smesh) { var dfsufilepath = UnitTestHelper.TestDataDir + @"DfsuTest.dfsu"; var mesh = GetMesh(dfsufilepath, smesh); var gf = new GeometryFactory(); var polygon1 = gf.CreatePolygon(new Coordinate[] { new Coordinate(0.1, 0.04), new Coordinate(0.2, 0.04), new Coordinate(0.15, 0.0), new Coordinate(0.1, 0.04) }); var searcher = MeshFactory.CreateIntersectionCalculator(mesh); var search1 = searcher.CalculateWeights(polygon1); Assert.AreEqual(3, search1.Count); Assert.AreEqual(3, search1[0].ElementIndex); Assert.AreEqual(11, search1[1].ElementIndex); Assert.AreEqual(14, search1[2].ElementIndex); Assert.AreEqual(1.0, search1.Sum(w => w.Weight), 1e-6); searcher.WeightType = WeightType.Fraction; search1 = searcher.CalculateWeights(polygon1); Assert.AreEqual(3, search1.Count); Assert.AreEqual(0.1353821, search1.Sum(w => w.Weight), 1e-6); searcher.WeightType = WeightType.Area; search1 = searcher.CalculateWeights(polygon1); Assert.AreEqual(3, search1.Count); Assert.AreEqual(polygon1.Area, search1.Sum(w => w.Weight), 1e-6); Assert.AreEqual(polygon1.Area, searcher.IntersectionArea, 1e-6); }
public void GetElementsIndicesWithWeight_PolygonEnveloppingAMeshElement(bool smesh) { var dfsufilepath = UnitTestHelper.TestDataDir + @"DfsuTest.dfsu"; var mesh = GetMesh(dfsufilepath, smesh); var gf = new GeometryFactory(); var polygon1 = gf.CreatePolygon(new Coordinate[] { new Coordinate(-0.05, 0.12), new Coordinate(0.2, 0.12), new Coordinate(0.1, -0.14), new Coordinate(-0.05, -0.14), new Coordinate(-0.05, 0.12) }); var searcher = MeshFactory.CreateIntersectionCalculator(mesh); var search1 = searcher.CalculateWeights(polygon1); var indices = search1.Select(i => i.ElementIndex).ToList(); Assert.AreEqual(13, indices.Count); Assert.AreEqual(1.0, search1.Sum(w => w.Weight), 1e-6); CollectionAssert.Contains(indices, 1); CollectionAssert.Contains(indices, 8); CollectionAssert.Contains(indices, 13); CollectionAssert.Contains(indices, 15); CollectionAssert.Contains(indices, 7); CollectionAssert.Contains(indices, 5); CollectionAssert.DoesNotContain(indices, 4); searcher.WeightType = WeightType.Fraction; search1 = searcher.CalculateWeights(polygon1); Assert.AreEqual(13, search1.Count); Assert.AreEqual(3.600211, search1.Sum(w => w.Weight), 1e-6); searcher.WeightType = WeightType.Area; search1 = searcher.CalculateWeights(polygon1); Assert.AreEqual(13, search1.Count); Assert.AreEqual(polygon1.Area, search1.Sum(w => w.Weight), 1e-6); Assert.AreEqual(polygon1.Area, searcher.IntersectionArea, 1e-6); }
private IPolygon CreateSelectionPolygon(ICoordinate worldPosition) { if (MultiSelectionMode == MultiSelectionMode.Rectangle) { if (0 == Math.Abs(mouseDownLocation.X - worldPosition.X)) { return(null); } if (0 == Math.Abs(mouseDownLocation.Y - worldPosition.Y)) { return(null); } return(CreatePolygon(Math.Min(mouseDownLocation.X, worldPosition.X), Math.Max(mouseDownLocation.Y, worldPosition.Y), Math.Max(mouseDownLocation.X, worldPosition.X), Math.Min(mouseDownLocation.Y, worldPosition.Y))); } var vertices = new List <ICoordinate>(); foreach (var point in selectPoints) { vertices.Add(Map.ImageToWorld(point)); } if (vertices.Count == 1) { // too few points to create a polygon return(null); } vertices.Add((ICoordinate)worldPosition.Clone()); vertices.Add((ICoordinate)vertices[0].Clone()); ILinearRing newLinearRing = GeometryFactory.CreateLinearRing(vertices.ToArray()); return(GeometryFactory.CreatePolygon(newLinearRing, null)); }
public void GetElementsIndicesWithWeight_PolygonPartiallyOutside(bool smesh) { var dfsufilepath = UnitTestHelper.TestDataDir + @"DfsuTest.dfsu"; var mesh = GetMesh(dfsufilepath, smesh); var gf = new GeometryFactory(); var polygon1 = gf.CreatePolygon(new Coordinate[] { new Coordinate(0.3, -0.1), new Coordinate(0.6, -0.1), new Coordinate(0.6, -0.15), new Coordinate(0.3, -0.15), new Coordinate(0.3, -0.1) }); var searcher = MeshFactory.CreateIntersectionCalculator(mesh); var search1 = searcher.CalculateWeights(polygon1); var indices = search1.Select(i => i.ElementIndex).ToList(); CollectionAssert.Contains(indices, 2); Assert.AreEqual(1, indices.Count); Assert.AreEqual(1.0, search1.Sum(w => w.Weight), 1e-6); searcher.WeightType = WeightType.Fraction; search1 = searcher.CalculateWeights(polygon1); Assert.AreEqual(1, search1.Count); Assert.AreEqual(0.12871149, search1.Sum(w => w.Weight), 1e-6); searcher.WeightType = WeightType.Area; search1 = searcher.CalculateWeights(polygon1); Assert.AreEqual(1, search1.Count); Assert.AreEqual(0.015, polygon1.Area, 1e-6); Assert.AreEqual(0.0024292, search1.Sum(w => w.Weight), 1e-6); Assert.AreEqual(0.0024292, searcher.IntersectionArea, 1e-6); }
/// <summary> /// Function to read a either a <see cref="Polygon"/> or an <see cref="MultiPolygon"/> from a ShapeFile stream using the specified <paramref name="reader"/>. /// </summary> /// <param name="reader">The reader to use</param> /// <param name="ordinates">The ordinates to read</param> /// <returns>The read polygonal geometry</returns> protected Geometry ReadPolygon(BinaryReader reader, Ordinates ordinates) { /*var bbox = */ ReadBoundingBox(reader); // jump boundingbox int numParts = ReadNumParts(reader); int numPoints = ReadNumPoints(reader); int[] indexParts = ReadIndexParts(reader, numParts, numPoints); var buffer = new CoordinateBuffer(numPoints, ShapeFileConstants.NoDataBorder, true); ReadCoordinates(reader, numPoints, indexParts, ordinates, buffer); return(numParts == 1 ? _factory.CreatePolygon(_factory.CreateLinearRing(buffer.ToSequence()), null) : CreateSingleOrMultiPolygon(buffer)); }
static IPolygon ParseFlatbufPolygonSingleRing(double[] coords, byte dimensions) { var sequenceFactory = new PackedCoordinateSequenceFactory(); var factory = new GeometryFactory(sequenceFactory); var shell = factory.CreateLinearRing(sequenceFactory.Create(coords, dimensions)); return(factory.CreatePolygon(shell)); }
private static double GetMultiPatchPerimeterLength([NotNull] IMultiPatch multiPatch) { IPolygon polygon = GeometryFactory.CreatePolygon(multiPatch); return(polygon.IsEmpty ? 0 : polygon.Length); }
public void CanSearchSingleMultipatch() { AssertCanFindGeometry( GeometryFactory.CreateMultiPatch( GeometryFactory.CreatePolygon(1000, 1000, 2000, 2000, 100))); }
private IGeometry GetErrorGeometry([NotNull] IGeometry geometry, [NotNull] IRow row, int tableIndex) { var differences = new List <IGeometry>(); for (int containsClassIndex = 0; containsClassIndex < _containsClassesCount; containsClassIndex++) { foreach (IRow intersectingRow in SearchIntersectingFeatures(containsClassIndex, geometry)) { var intersectingFeature = (IFeature)intersectingRow; if (!_isContainingCondition.IsFulfilled( intersectingFeature, containsClassIndex, row, tableIndex)) { // condition is not fulfilled, ignore containing row continue; } esriGeometryType containingShapeType = _shapeTypes[containsClassIndex]; IGeometry geometryToSubtract = containingShapeType == esriGeometryType.esriGeometryMultiPatch ? GeometryFactory.CreatePolygon((IMultiPatch)intersectingFeature.Shape) : intersectingFeature.Shape; var topoOp = (ITopologicalOperator)geometry; IGeometry difference = topoOp.Difference(geometryToSubtract); const bool allowReorder = true; GeometryUtils.Simplify(difference, allowReorder); if (difference.IsEmpty) { // there is no difference --> geometry is contained! return(null); } differences.Add(difference); } } if (differences.Count == 0) { // no intersecting geometries --> report entire shape return(geometry); } IGeometry unionedDifferences = GeometryUtils.UnionGeometries(differences); GeometryUtils.Simplify(unionedDifferences, true); return(unionedDifferences); }
public void CanCreateBuffer() { IPolygon original = GeometryFactory.CreatePolygon(100, 100, 150, 200); IPolygon buffer = GeometryFactory.CreateBuffer(original, 100); Assert.AreEqual(250, buffer.Envelope.Width, 0.01); Assert.AreEqual(300, buffer.Envelope.Height, 0.01); }
private static void MakeInnerRing(IGeometry geometryToReshape) { IGeometry outerRingPoly = GeometryFactory.CreatePolygon(0, 0, 1000, 1000); ((IGeometryCollection)geometryToReshape).AddGeometryCollection( (IGeometryCollection)outerRingPoly); GeometryUtils.Simplify(geometryToReshape); }
private Polygon CreatePolygon(JsonReader reader, List <object> list) { var shell = _factory.CreateLinearRing(CreateCoordinateArray(reader, (List <object>)list[0])); if (list.Count == 1) { return(_factory.CreatePolygon(shell)); } var holes = new LinearRing[list.Count - 1]; for (int i = 0; i < holes.Length; i++) { holes[i] = _factory.CreateLinearRing(CreateCoordinateArray(reader, (List <object>)list[i + 1])); } return(_factory.CreatePolygon(shell, holes)); }
public void TopoJsonReaderReadContentTest() { GeometryFactory factory = new GeometryFactory(); //test 1st input file TopoJsonReader reader = new TopoJsonReader(_inputFilePaths[0]); IGeometry result = reader.Read(); Assert.IsInstanceOf(typeof(IGeometryCollection <IGeometry>), result); IGeometryCollection <IGeometry> collection = result as IGeometryCollection <IGeometry>; Assert.AreEqual(2, collection.Count); Assert.IsInstanceOf(typeof(IPolygon), collection[0]); Assert.IsInstanceOf(typeof(IPolygon), collection[1]); IPolygon left_polygon = factory.CreatePolygon(new Coordinate[] { new Coordinate(1, 2), new Coordinate(1, 0), new Coordinate(0, 0), new Coordinate(0, 2), new Coordinate(1, 2) }); IPolygon right_polygon = factory.CreatePolygon(new Coordinate[] { new Coordinate(1, 2), new Coordinate(2, 2), new Coordinate(2, 0), new Coordinate(1, 0), new Coordinate(1, 2) }); GeometryComparer comp = new GeometryComparer(); //System.Diagnostics.Debug.WriteLine((collection[0] as IPolygon).Shell.ToString()); Assert.AreEqual(0, comp.Compare(collection[0], left_polygon)); Assert.AreEqual(0, comp.Compare(collection[1], right_polygon)); reader.Close(); }
public override object?ParseLiteral(IValueNode literal) { if (literal is NullValueNode) { return(null); } if (!(literal is ObjectValueNode obj)) { throw ThrowHelper.InvalidInputObjectStructure(_geometryType); } (int typeIndex, int coordinateIndex, int crsIndex)indices = ParseLiteralHelper.GetFieldIndices(obj, _typeFieldName, _coordinatesFieldName, _crsFieldName); if (indices.typeIndex == -1) { throw ThrowHelper.InvalidInputObjectStructure(_geometryType); } var type = (GeoJSONGeometryType) _typeField.Type.ParseLiteral(obj.Fields[indices.typeIndex].Value); if (type != _geometryType || indices.coordinateIndex == -1) { throw ThrowHelper.InvalidInputObjectStructure(_geometryType); } var coordinates = (IList <Coordinate>) _coordinatesField.Type.ParseLiteral(obj.Fields[indices.coordinateIndex].Value); if (coordinates.Count < 4) { throw ThrowHelper.InvalidInputObjectStructure(_geometryType); } var coords = new Coordinate[coordinates.Count]; coordinates.CopyTo(coords, 0); var ring = new LinearRing(coords); if (indices.crsIndex == -1) { return(new Polygon(ring)); } var srid = (int)_crsField.Type.ParseLiteral(obj.Fields[indices.crsIndex].Value); GeometryFactory factory = NtsGeometryServices.Instance.CreateGeometryFactory(srid); return(factory.CreatePolygon(ring)); }
/// <summary> /// Transforms a <see cref="GisSharpBlog.NetTopologySuite.Geometries.Polygon"/>. /// </summary> /// <param name="p">Polygon to transform</param> /// <param name="transform">MathTransform</param> /// <returns>Transformed Polygon</returns> public static IPolygon TransformPolygon(IPolygon p, IMathTransform transform) { List <ILinearRing> rings = new List <ILinearRing>(p.InteriorRings.Length); for (int i = 0; i < p.InteriorRings.Length; i++) { rings.Add(TransformLinearRing((ILinearRing)p.InteriorRings[i], transform)); } return(GeometryFactory.CreatePolygon(TransformLinearRing((ILinearRing)p.ExteriorRing, transform), rings.ToArray())); }
public void CanPolygonBoundary() { var envelope = GeometryFactory.CreateEnvelope(0, 0, 100, 50); var polygon = GeometryFactory.CreatePolygon(envelope); var boundary = GeometryUtils.Boundary(polygon); Assert.NotNull(boundary); Assert.AreEqual(GeometryType.Polyline, boundary.GeometryType); Assert.AreEqual(polygon.PointCount, boundary.PointCount); }
public void CreateEmptyPolygonSucceeds() { GeometryFactory factory = new GeometryFactory( new BufferedCoordinate2DFactory(), new BufferedCoordinate2DSequenceFactory()); IPolygon p = factory.CreatePolygon(); Assert.IsNotNull(p); Assert.IsTrue(p.IsEmpty); }
public void CanTestDefinedExtentMultipleTilesWithLinesNearTileBoundary() { IPolycurve leftOfTileBoundary = CurveConstruction.StartLine(99.5, 10) .LineTo(99.5, 90) .Curve; IPolycurve rightOfTileBoundary = CurveConstruction.StartLine(100.5, 10) .LineTo(100.5, 90) .Curve; IFeatureClass fc = CreateLineClass(_testWs, "CanTestDefinedExtentMultipleTiles_fc"); IFeature row = fc.CreateFeature(); row.Shape = rightOfTileBoundary; row.Store(); IFeatureClass nearClass = CreateLineClass(_testWs, "CanTestDefinedExtentMultipleTiles_near"); IFeature nearRow = nearClass.CreateFeature(); nearRow.Shape = leftOfTileBoundary; nearRow.Store(); IPolygon polygon = GeometryFactory.CreatePolygon( GeometryFactory.CreateEnvelope(0, 0, 200, 200)); const double maximumDistance = 1.5; // one tile for the entire verification extent QaContainerTestRunner runnerLargeTileSize = CreateTestRunner( fc, nearClass, 200, maximumDistance); runnerLargeTileSize.Execute(polygon); AssertUtils.NoError(runnerLargeTileSize); // 4 tiles. // The feature is in the second tile, to the right of the left tile boundary, but within the search distance of it. // The 'near feature' is in the first tile, to the left of the right tile boundary, but within the search distance of it. // NOTE currently this results in an error, since the 'near feature' is not returned again for the second tile // (the test container assumes that it was already considered in the first tile; in this case however, it is // needed for a feature in the *second* tile, which was not yet returned for the first tile. // -> if the search geometry overlaps the tile boundary but the source feature for the search DOES NOT, then // features must be returned by the search even if they overlap a previous tile QaContainerTestRunner runnerSmallTileSize = CreateTestRunner( fc, nearClass, 100, maximumDistance); runnerSmallTileSize.Execute(polygon); AssertUtils.NoError(runnerSmallTileSize); }
} // public void AddHole(EdgeRing ring) /// <summary> /// /// </summary> /// <param name="geometryFactory"></param> /// <returns></returns> public Polygon ToPolygon(GeometryFactory geometryFactory) { LinearRing[] holeLR = new LinearRing[_holes.Count]; for (int i = 0; i < _holes.Count; i++) { holeLR[i] = ((EdgeRing)_holes[i]).GetLinearRing(); } Polygon poly = geometryFactory.CreatePolygon(GetLinearRing(), holeLR); return(poly); }
public IPolygon CreatePolygon(IList <Coordinate> shell, IList <Coordinate>[] holes = null) { ILinearRing[] geomHoles = new ILinearRing[holes == null ? 0 : holes.Length]; for (int i = 0; i < geomHoles.Length; i++) { geomHoles[i] = _factory.CreateLinearRing(holes[i]); } return(_factory.CreatePolygon(_factory.CreateLinearRing(shell), geomHoles)); }
private static void AddAreaFeature([NotNull] IFeatureClass featureClass, double xmin, double ymin, double xmax, double ymax, [CanBeNull] string stateId = null, [CanBeNull] string textFieldValue = null, double?doubleValue = null, DateTime?dateValue = null) { AddFeature(featureClass, GeometryFactory.CreatePolygon(xmin, ymin, xmax, ymax), stateId, textFieldValue, doubleValue, dateValue); }
/// <summary> /// Creates a <c>Polygon</c> using the next token in the stream. /// </summary> /// <param name="tokens"> /// Tokenizer over a stream of text in Well-known Text /// format. The next tokens must form a Polygon Text. /// </param> /// <returns> /// A <c>Polygon</c> specified by the next token /// in the stream. /// </returns> private Polygon ReadPolygonText(IList tokens) { string nextToken = GetNextEmptyOrOpener(tokens); if (nextToken.Equals("EMPTY")) //NOXLATE { return(geometryFactory.CreatePolygon(geometryFactory.CreateLinearRing(Array.Empty <Coordinate>()))); } var holes = new List <LinearRing>(); var shell = ReadLinearRingText(tokens); nextToken = GetNextCloserOrComma(tokens); while (nextToken.Equals(",")) //NOXLATE { var hole = ReadLinearRingText(tokens); holes.Add(hole); nextToken = GetNextCloserOrComma(tokens); } return(geometryFactory.CreatePolygon(shell, holes.ToArray())); }
public static Polygon CreateBox( GeometryFactory fact, double minx, double miny, int nSide, double segLen) { var pts = CreateBox(minx, minx, nSide, segLen); var ring = fact.CreateLinearRing(pts); var poly = fact.CreatePolygon(ring, null); return(poly); }