Ejemplo n.º 1
0
        private void WriteGeometryCollection(GeometryCollection geometryCollection)
        {
            wkbWriter.Write(geometryCollection.Geometries.Count);

            foreach (Geometry geometry in geometryCollection.Geometries)
                WriteInternal(geometry);
        }
        public void Constructor_IEnumerable_CreateNewCollectionWithDataInWSG84()
        {
            GeometryCollection<Geometry> target = new GeometryCollection<Geometry>(_geometries);

            Assert.Equal(SRIDList.WSG84, target.Srid);
            CheckGeometries(target, _geometries);
        }
        public void Constructor_SRIDIEnumerable_CreateNewCollectionWithDataInWSpecifiedSRID()
        {
            int srid = 1;
            GeometryCollection<Geometry> target = new GeometryCollection<Geometry>(srid, _geometries);

            Assert.Equal(srid, target.Srid);
            CheckGeometries(target, _geometries);
        }
        public void Constructor__CreatesNewEmptyCollectionInWSG84()
        {
            GeometryCollection<Geometry> target = new GeometryCollection<Geometry>();

            Assert.Equal(SRIDList.WSG84, target.Srid);
            Assert.NotNull(target.Geometries);
            Assert.Empty(target.Geometries);
        }
        public void Constructor_SRID_CreatesEmptyCollectionInSpecifiedSRID()
        {
            int srid = 1;
            GeometryCollection<Geometry> target = new GeometryCollection<Geometry>(srid);

            Assert.Equal(srid, target.Srid);
            Assert.NotNull(target.Geometries);
            Assert.Empty(target.Geometries);
        }
Ejemplo n.º 6
0
 public HexEditor()
 {
     m_HexGeo = new GeometryCollection();
     m_AsciiGeo = new GeometryCollection();
     InitializeComponent();
     DataRows = new ObservableCollection<HexEditorRow>();
     this.TextInput += HexEditor_TextInput;
     this.KeyDown += HexEditor_KeyDown;
     this.SizeChanged += HexEditor_SizeChanged;
 }
Ejemplo n.º 7
0
        public HexEditorBlock(GeometryCollection hexGeos, GeometryCollection ascciGeos)
        {
            m_Run = HexEditor.CreateGlyphRun(new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), "0", FontSize, new Point(0, FontSize));

            Unloaded += HexEditorTextBlock_Unloaded;
            Loaded += HexEditorTextBlock_Loaded;
            Width = 50;
            Height = 50;
            m_HexGeo = hexGeos;
            m_AsciiGeo = ascciGeos;
        }
Ejemplo n.º 8
0
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			StrokeCollection strokes = value as StrokeCollection;
			GeometryCollection gc = new GeometryCollection();
			foreach (Stroke stroke in strokes) {
				Path path = StrokeToPath(stroke);
				gc.Add(path.Data);
			}

			return gc;
		}
Ejemplo n.º 9
0
        private void WriteGeometryCollection(GeometryCollection geometryCollection)
        {
            wktBuilder.Append("(");

            foreach (Geometry geometry in geometryCollection.Geometries)
            {
                Write(geometry);
                wktBuilder.Append(",");
            }

            wktBuilder.Remove(wktBuilder.Length - 1, 1);
            wktBuilder.Append(")");
        }
Ejemplo n.º 10
0
        public void KmlReadGeometryv2_0()
        {
            // initialize the geometry source.
            KmlGeoStreamSource kmlSource = new KmlGeoStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v2.0.kml"));

            // pull all the objects from the stream into the given collection.
            GeometryCollection kmlCollection = new GeometryCollection(kmlSource);
            List<Geometry> geometries = new List<Geometry>(kmlCollection);

            // test collection contents.
            Assert.AreEqual(1, geometries.Count);
            Assert.IsInstanceOf(typeof(Point), geometries[0]);
        }
Ejemplo n.º 11
0
        public void GpxReadGeometryv1_0()
        {
            // initialize the geometry source.
            GpxGeoStreamSource gpxSource = new GpxGeoStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v1.0.gpx"),
                false);

            // pull all the objects from the stream into the given collection.
            GeometryCollection gpxCollection = new GeometryCollection(gpxSource);
            List<Geometry> geometries = new List<Geometry>(gpxCollection);

            // test collection contents.
            Assert.AreEqual(1, geometries.Count);
            Assert.IsInstanceOf(typeof(LineString), geometries[0]);
            Assert.AreEqual(424, (geometries[0] as LineString).Coordinates.Count);
        }
        public void GetBoundary_ReturnsGeometryCollectionWithBoundariesOfObjectsInCollection()
        {
            int srid = 1;
            GeometryCollection<Geometry> target = new GeometryCollection<Geometry>(srid);
            target.Geometries.Add(new LineString(srid, _coordinatesXYZM));

            IGeometryCollection<IGeometry> boundary = target.GetBoundary() as IGeometryCollection<IGeometry>;

            Assert.NotNull(boundary);
            Assert.Equal(srid, boundary.Srid);
            Assert.Equal(target.Geometries.Count, boundary.Geometries.Count());

            IMultiPoint expectedChildBoundary = target.Geometries[0].GetBoundary() as IMultiPoint;
            IMultiPoint childBoundary = boundary.Geometries.First() as IMultiPoint;;

            Assert.Equal(expectedChildBoundary.Geometries.First().Position, childBoundary.Geometries.First().Position);
            Assert.Equal(expectedChildBoundary.Geometries.Last().Position, childBoundary.Geometries.Last().Position);
        }
Ejemplo n.º 13
0
        private static GeoPolygon getPointBuffer(GeoPoint point, double angleDistance, int pointsPerCircle)
        {
            if (angleDistance < 0)
                return new GeoPolygon();

            GnomonicProjection projection = new GnomonicProjection(point.L, point.Phi);
            PointD planePoint = new PointD(0, 0);
            Polygon planePolygon = (Polygon)planePoint.Buffer(Math.Tan(angleDistance), pointsPerCircle, false);

            GeometryCollection geometryColllection = new GeometryCollection();
            geometryColllection.Add(planePolygon);
            GeographyCollection gc = GeometrySpreader.GetGeographies(geometryColllection, projection);

            if(gc[0] is GeoPolygon)
                return (GeoPolygon)gc[0];

            return new GeoPolygon();
        }
Ejemplo n.º 14
0
        protected Geometry CreateGeometry(GeometryType geometryType, Dimension dimension)
        {
            Geometry geometry = null;

            switch (geometryType)
            {
                case GeometryType.Point: geometry = new Point(); break;
                case GeometryType.LineString: geometry = new LineString(); break;
                case GeometryType.Polygon: geometry = new Polygon(); break;
                case GeometryType.MultiPoint: geometry = new MultiPoint(); break;
                case GeometryType.MultiLineString: geometry = new MultiLineString(); break;
                case GeometryType.MultiPolygon: geometry = new MultiPolygon(); break;
                case GeometryType.GeometryCollection: geometry = new GeometryCollection(); break;
            }

            geometry.Dimension = dimension;

            return geometry;
        }
Ejemplo n.º 15
0
        public static GeometryGroup DarkModuleGeometry(BitMatrix matrix)
        {
            GeometryCollection gCollection = new GeometryCollection();
            GeometryGroup gGroup = new GeometryGroup();
            if (matrix == null)
            {
                gGroup.Children = gCollection;
                return gGroup;
            }

            int preX = -1;
            int width = matrix.Width;
            for (int y = 0; y < width; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (matrix[x, y])
                    {
                        //Set start point if preX == -1
                        if (preX == -1)
                            preX = x;
                        //If this is last module in that row. Draw rectangle
                        if (x == width - 1)
                        {
                            gCollection.Add(CreateRectGeometry(new Rect(preX, y, x - preX + 1, 1)));
                            preX = -1;
                        }
                    }
                    else if (!matrix[x, y] && preX != -1)
                    {
                        //Here will be first light module after sequence of dark module.
                        //Draw previews sequence of dark Module
                        gCollection.Add(CreateRectGeometry(new Rect(preX, y, x - preX, 1)));
                        preX = -1;
                    }
                }
            }

            gGroup.Children = gCollection;
            return gGroup;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Finds the widest geometry in a geometry collection or list.
        /// The calculation is based on the envelope of the geometry.
        /// </summary>
        /// <param name="gc">
        /// The geometry collection from which to find the widest geometry.
        /// </param>
        /// <returns>The widest <see cref="Geometry"/>in the collection.</returns>
        private Geometry WidestGeometry(GeometryCollection gc)
        {
            if (gc.IsEmpty)
            {
                return(gc);
            }

            Geometry widestGeometry = gc.GetGeometry(0);
            int      nCount         = gc.NumGeometries;

            for (int i = 1; i < nCount; i++)
            {
                //Start at 1
                if (gc.GetGeometry(i).Bounds.Width >
                    widestGeometry.Bounds.Width)
                {
                    widestGeometry = gc.GetGeometry(i);
                }
            }

            return(widestGeometry);
        }
Ejemplo n.º 17
0
        public void TestRelationMultipolygonAreaOneOuterTwoInners()
        {
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 0, 0),
                Node.Create(2, 0, 1),
                Node.Create(3, 1, 1),
                Node.Create(4, 1, 0),
                Node.Create(5, 0.25, 0.25),
                Node.Create(6, 0.25, 0.40),
                Node.Create(7, 0.40, 0.40),
                Node.Create(8, 0.40, 0.25),
                Node.Create(9, 0.60, 0.25),
                Node.Create(10, 0.60, 0.40),
                Node.Create(11, 0.75, 0.40),
                Node.Create(12, 0.75, 0.25),
                Way.Create(1, 1, 2, 3, 4, 1),
                Way.Create(2, 5, 6, 7, 8, 5),
                Way.Create(3, 9, 10, 11, 12, 9),
                Relation.Create(1,
                                new TagsCollection(
                                    Tag.Create("type", "multipolygon")),
                                RelationMember.Create(1, "outer", OsmGeoType.Way),
                                RelationMember.Create(2, "inner", OsmGeoType.Way),
                                RelationMember.Create(3, "inner", OsmGeoType.Way)));

            GeometryInterpreter interpreter = new SimpleGeometryInterpreter();
            GeometryCollection  geometries  = interpreter.Interpret(source.GetRelation(1), source);

            Assert.IsNotNull(geometries);
            Assert.AreEqual(1, geometries.Count);
            Geometry geometry = geometries[0];

            Assert.IsInstanceOf <Polygon>(geometry);
            Polygon polygon = geometry as Polygon;

            Assert.IsNotNull(polygon.Holes);
            Assert.AreEqual(2, polygon.Holes.Count());
            Assert.IsTrue(geometry.Attributes.ContainsKeyValue("type", "multipolygon"));
        }
Ejemplo n.º 18
0
 internal static void Write(JsonWriter writer, GeometryCollection geometryCollection)
 {
     if (writer == null)
     {
         throw new ArgumentNullException("writer");
     }
     if (geometryCollection == null)
     {
         throw new ArgumentNullException("geometryCollection");
     }
     writer.WriteStartObject();
     writer.WritePropertyName("type");
     writer.WriteValue("GeometryCollection");
     writer.WritePropertyName("geometries");
     writer.WriteStartArray();
     foreach (Geometry geometry in (GeometryCollectionBase <Geometry>)geometryCollection)
     {
         GeoJsonConverter.Write(writer, geometry);
     }
     writer.WriteEndArray();
     writer.WriteEndObject();
 }
Ejemplo n.º 19
0
        public void ParseGeometryCollection()
        {
            string             geomCollection = "GEOMETRYCOLLECTION (POINT (10 10), POINT (30 30), LINESTRING (15 15, 20 20))";
            GeometryCollection geom           = Geometry.GeomFromText(geomCollection) as GeometryCollection;

            Assert.IsNotNull(geom);
            Assert.AreEqual(3, geom.NumGeometries);
            Assert.IsTrue(geom[0] is Point);
            Assert.IsTrue(geom[1] is Point);
            Assert.IsTrue(geom[2] is LineString);
            Assert.AreEqual(geomCollection, geom.AsText());
            geom = Geometry.GeomFromText("GEOMETRYCOLLECTION EMPTY") as GeometryCollection;
            Assert.IsNotNull(geom);
            Assert.AreEqual(0, geom.NumGeometries);
            geomCollection = "GEOMETRYCOLLECTION (POINT (10 10), LINESTRING EMPTY, POINT (20 49))";
            geom           = Geometry.GeomFromText(geomCollection) as GeometryCollection;
            Assert.IsNotNull(geom);
            Assert.IsTrue(geom[1].IsEmpty());
            Assert.AreEqual(3, geom.NumGeometries);
            Assert.AreEqual(geomCollection, geom.AsText());
            Assert.AreEqual("GEOMETRYCOLLECTION EMPTY", new GeometryCollection().AsText());
        }
Ejemplo n.º 20
0
        private static void projectGeography(IGeography geography, out GnomonicProjection projection, out IGeometry geometry)
        {
            GeographyCollection geographyCollection = new GeographyCollection();

            geographyCollection.Add(geography);

            double centerLatitude, centerLongitude;

            GnomonicProjection.GetCenter(geography.ExtractPoints(), out centerLatitude, out centerLongitude);
            projection = new GnomonicProjection(centerLongitude, centerLatitude);

            GeometryCollection geometryCollection = GeometrySpreader.GetGeometries(geographyCollection, projection);

            if (geometryCollection.Count > 0)
            {
                geometry = geometryCollection[0];
            }
            else
            {
                geometry = null;
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Writes a geometrycollection.
        /// </summary>
        /// <param name="gc">The geometrycollection to be written.</param>
        /// <param name="bWriter">Stream to write to.</param>
        /// <param name="byteorder">Byte order</param>
        private static void WriteGeometryCollection(GeometryCollection gc, BinaryWriter bWriter, WkbByteOrder byteorder)
        {
            //Get the number of geometries in this geometrycollection.
            var num = gc.NumGeometries;

            //Write the number of geometries.
            WriteUInt32((uint)num, bWriter, byteorder);

            //Loop on the number of geometries.
            //NOTE: by contract, the first item returned
            //      from GetEnumerator (i.e. using foreach) is the GeometryCollection itself!
            for (var i = 0; i < num; i++)
            {
                Geometry geom = gc.GetGeometryN(i);
                //Write the byte-order format of the following geometry.
                bWriter.Write((byte)byteorder);
                //Write the type of each geometry.
                WriteType(geom, bWriter, byteorder);
                //Write each geometry.
                WriteGeometry(geom, bWriter, byteorder);
            }
        }
Ejemplo n.º 22
0
        private async Task <GeometryCollection> ReadGeometryCollection(BinaryReader reader, ByteOrder wkbByteOrder, WKBShapeType type, bool includeAltitude, bool includeM)
        {
            // The next byte in the array tells the number of geometries in this collection.
            int numGeometries = (int)NumberReader.ReadUInt32(reader, wkbByteOrder);

            // Create a new array for the geometries.
            var geographies = new GeometryCollection(numGeometries);

            Geometry g;

            // Loop on the number of geometries.
            for (int i = 0; i < numGeometries; i++)
            {
                g = await ReadGeometry(reader, wkbByteOrder, type, includeAltitude, includeM);

                // Call the main create function with the next geometry.
                geographies.Geometries.Add(g);
            }

            // Create and return the next geometry.
            return(geographies);
        }
Ejemplo n.º 23
0
        static ODataSpatialTypeUtil()
        {
            // Geometry type values.
            GeometryValue                = GeometryFactory.Point(32.0, -10.0).Build();
            GeometryPointValue           = GeometryFactory.Point(33.1, -11.0).Build();
            GeometryLineStringValue      = GeometryFactory.LineString(33.1, -11.5).LineTo(35.97, -11).Build();
            GeometryPolygonValue         = GeometryFactory.Polygon().Ring(33.1, -13.6).LineTo(35.97, -11.15).LineTo(11.45, 87.75).Ring(35.97, -11).LineTo(36.97, -11.15).LineTo(45.23, 23.18).Build();
            GeometryCollectionValue      = GeometryFactory.Collection().Point(-19.99, -12.0).Build();
            GeometryMultiPointValue      = GeometryFactory.MultiPoint().Point(10.2, 11.2).Point(11.9, 11.6).Build();
            GeometryMultiLineStringValue = GeometryFactory.MultiLineString().LineString(10.2, 11.2).LineTo(11.9, 11.6).LineString(16.2, 17.2).LineTo(18.9, 19.6).Build();
            GeometryMultiPolygonValue    = GeometryFactory.MultiPolygon().Polygon().Ring(10.2, 11.2).LineTo(11.9, 11.6).LineTo(11.45, 87.75).Ring(16.2, 17.2).LineTo(18.9, 19.6).LineTo(11.45, 87.75).Build();

            // Geography type values.
            GeographyValue                = GeographyFactory.Point(32.0, -100.0).Build();
            GeographyPointValue           = GeographyFactory.Point(33.1, -110.0).Build();
            GeographyLineStringValue      = GeographyFactory.LineString(33.1, -110.0).LineTo(35.97, -110).Build();
            GeographyPolygonValue         = GeographyFactory.Polygon().Ring(33.1, -110.0).LineTo(35.97, -110.15).LineTo(11.45, 87.75).Ring(35.97, -110).LineTo(36.97, -110.15).LineTo(45.23, 23.18).Build();
            GeographyCollectionValue      = GeographyFactory.Collection().Point(-19.99, -12.0).Build();
            GeographyMultiPointValue      = GeographyFactory.MultiPoint().Point(10.2, 11.2).Point(11.9, 11.6).Build();
            GeographyMultiLineStringValue = GeographyFactory.MultiLineString().LineString(10.2, 11.2).LineTo(11.9, 11.6).LineString(16.2, 17.2).LineTo(18.9, 19.6).Build();
            GeographyMultiPolygonValue    = GeographyFactory.MultiPolygon().Polygon().Ring(10.2, 11.2).LineTo(11.9, 11.6).LineTo(11.45, 87.75).Ring(16.2, 17.2).LineTo(18.9, 19.6).LineTo(11.45, 87.75).Build();
        }
Ejemplo n.º 24
0
        private void WriteGeometryCollection(GeometryCollection geoms, XmlWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("MultiGeometry");

            foreach (var g in geoms.Geometries)
            {
                if (g is Point || g is LineString || g is Polygon)
                {
                    WriteGeometry(g, xmlWriter);
                }
                else if (g is MultiPoint)
                {
                    var points = g as MultiPoint;
                    foreach (var p in points.Geometries)
                    {
                        WritePoint(p, xmlWriter);
                    }
                }
                else if (g is MultiLineString)
                {
                    var lines = g as MultiLineString;
                    foreach (var p in lines.Geometries)
                    {
                        WriteLineString(p, xmlWriter);
                    }
                }
                else if (g is MultiPolygon)
                {
                    var polys = g as MultiPolygon;
                    foreach (var p in polys.Geometries)
                    {
                        WritePolygon(p, xmlWriter);
                    }
                }
            }

            xmlWriter.WriteEndElement();
        }
Ejemplo n.º 25
0
        public FileContentResult Download(string Id, string type)
        {
            ///conteeeeeeeeeent
            var fileName   = "home-2floor-ft.ifc";
            var filePath   = Server.MapPath($"~/Users/input-files/{fileName}");
            var outputFile = Server.MapPath($"~/Users/output-files/{fileName}-Structure");

            StudTable.FilePath = Server.MapPath(@"~/App_Data\Tables\StudSpacingTable.csv");

            Table502_5.HeadersTableExteriorPath = Server.MapPath(@"~/App_Data\Tables\table502.5(1).csv");
            Table502_5.HeadersTableInteriorPath = Server.MapPath(@"~/App_Data\Tables\table502.5(2).csv");

            Table502_3_1.JoistTableLivingAreasPath   = Server.MapPath(@"~/App_Data\Tables\table502.3.1(2).csv");
            Table502_3_1.JoistTableSleepingAreasPath = Server.MapPath(@"~/App_Data\Tables\table502.3.1(1).csv");

            using (IfModel model = IfModel.Open(filePath))
            {
                Bim.Domain.Configuration.Startup.Configuration(model);

                model.Delete <IfcBeam>();
                model.Delete <IfcColumn>();
                WoodFrame wf = new WoodFrame(model);
                wf.FrameWalls();
                model.Delete <IfcWall>();
                model.Delete <IfcSlab>();

                // model.Save(saveName);

                GeometryCollection GC1 = new GeometryCollection();
                GC1.AddToCollection(model.Instances.OfType <IfJoist>());
                GC1.AddToCollection(model.Instances.OfType <IfStud>());
                GC1.AddToCollection(model.Instances.OfType <IfSill>());
                byte[] filecontent = GC1.ToExcel(GC1.BOQTable, "Testing Excel", false, "Number", "Collection");

                ///result
                return(File(filecontent, GC1.ExcelContentType, "test1.xlsx"));
            }
        }
Ejemplo n.º 26
0
        private void UpdateCoverageGeometry()
        {
            if (Locations == null)
            {
                return;
            }

            if (Network.Branches.Count == 0)
            {
                return;
            }

            IMultiDimensionalArray <INetworkLocation> locations = Locations.Values;

            if (locations.Count == 0)
            {
                return;
            }

            // Create a geometry object that is defined by all covered feature geometries
            var geometries = new IGeometry[locations.Count];

            for (int i = 0; i < locations.Count; i++)
            {
#if MONO
                geometries[i] = ((INetworkLocation)(((IMultiDimensionalArray)locations)[i])).Geometry;
#else
                geometries[i] = locations[i].Geometry;
#endif

                if (geometries[i] == null)
                {
                    // geometry-less feature
                    return;
                }
            }
            Geometry = new GeometryCollection(geometries);
        }
        private static GeometryCollection GetArcGeometry(Point center, double radius, double startAngle, double endAngle, int segments, bool clockwise = true)
        {
            var geometryCollection = new GeometryCollection();

            double angleDifference = 0;

            if (clockwise)
            {
                if (endAngle <= startAngle)
                {
                    endAngle += 360;
                }

                angleDifference = endAngle - startAngle;
            }
            else
            {
                if (startAngle <= endAngle)
                {
                    startAngle += 360;
                }

                angleDifference = startAngle - endAngle;
            }

            for (int i = 0; i < segments; i++)
            {
                double segmentStartAgnle = (startAngle + i * angleDifference / segments) * Math.PI / 180.0;
                double segmentEndAngle   = (startAngle + (i + 1) * angleDifference / segments) * Math.PI / 180.0;

                Point startPoint = center + new Vector(Math.Cos(segmentStartAgnle), Math.Sin(segmentStartAgnle)) * radius;
                Point endPoint   = center + new Vector(Math.Cos(segmentEndAngle), Math.Sin(segmentEndAngle)) * radius;

                geometryCollection.Add(new LineGeometry(startPoint, endPoint));
            }

            return(geometryCollection);
        }
        /// <summary>
        /// Transforms a <see cref="GeometryCollection"/> geometry.
        /// </summary>
        /// <param name="geom">The <c>GeometryCollection</c> to transform</param>
        /// <param name="parent">The parent geometry</param>
        /// <returns>A <c>GeometryCollection</c></returns>
        protected virtual Geometry TransformGeometryCollection(GeometryCollection geom, Geometry parent)
        {
            var transGeomList = new List <Geometry>();

            for (int i = 0; i < geom.NumGeometries; i++)
            {
                var transformGeom = Transform(geom.GetGeometryN(i));
                if (transformGeom == null)
                {
                    continue;
                }
                if (pruneEmptyGeometry && transformGeom.IsEmpty)
                {
                    continue;
                }
                transGeomList.Add(transformGeom);
            }
            if (preserveGeometryCollectionType)
            {
                return(Factory.CreateGeometryCollection(GeometryFactory.ToGeometryArray(transGeomList)));
            }
            return(Factory.BuildGeometry(transGeomList));
        }
Ejemplo n.º 29
0
        public static void Write(GeometryCollection geometries, JsonTextWriter writer)
        {
            if (geometries == null)
            {
                return;
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer", "A valid JSON writer object is required");
            }

            writer.WriteStartObject();
            writer.WritePropertyName("type");
            writer.WriteValue("GeometryCollection");
            writer.WritePropertyName("geometries");
            writer.WriteStartArray();
            foreach (Geometry geometry in geometries)
            {
                Write(geometry, writer);
            }
            writer.WriteEndArray();
            writer.WriteEndObject();
        }
Ejemplo n.º 30
0
        private bool WriteProposed(GeometryCollection geomCollection)
        {
            WriteByteOrder();

            int geometryType   = (int)GeometryWkbType.GeometryCollection;
            int coordDimension = geomCollection.CoordinateDimension;

            int nFlag3D  = (int)((coordDimension == 3) ? 0x80000000 : 0);
            int nTypeInt = geometryType | nFlag3D;

            WriterGeometryType(nTypeInt);

            int numGeometries = geomCollection.NumGeometries;

            m_objWriter.WriteInt32(numGeometries);

            for (int i = 0; i < numGeometries; i++)
            {
                WriteProposed(geomCollection[i]);
            }

            return(true);
        }
Ejemplo n.º 31
0
        }         // public static int Locate(Coordinate p, Geometry geom)

        private static bool ContainsPoint(Coordinate p, Geometry geom)
        {
            if (geom is Polygon)
            {
                return(ContainsPointInPolygon(p, (Polygon)geom));
            }
            else if (geom is GeometryCollection)
            {
                GeometryCollection gc = geom as GeometryCollection;
                foreach (Geometry g2 in gc)
                {
                    if (g2 != geom)                                             // TODO:  what is this line trying to do???
                    {
                        if (ContainsPoint(p, g2))
                        {
                            return(true);
                        }
                    }
                }         // foreach( Geometry g2 in geom )
            }             // else if( geom is GeometryCollection )

            return(false);
        }         // private static bool ContainsPoint(Coordinate p, Geometry geom)
Ejemplo n.º 32
0
        private static GeoPolygon getPointBuffer(GeoPoint point, double angleDistance, int pointsPerCircle)
        {
            if (angleDistance < 0)
            {
                return(new GeoPolygon());
            }

            GnomonicProjection projection   = new GnomonicProjection(point.L, point.Phi);
            PointD             planePoint   = new PointD(0, 0);
            Polygon            planePolygon = (Polygon)planePoint.Buffer(Math.Tan(angleDistance), pointsPerCircle, false);

            GeometryCollection geometryColllection = new GeometryCollection();

            geometryColllection.Add(planePolygon);
            GeographyCollection gc = GeometrySpreader.GetGeographies(geometryColllection, projection);

            if (gc[0] is GeoPolygon)
            {
                return((GeoPolygon)gc[0]);
            }

            return(new GeoPolygon());
        }
Ejemplo n.º 33
0
        public override Geometry GetHilightGeometry(TextRange range)
        {
            Geometry result = Geometry.Empty;

            if (range != null)
            {
                IEnumerable <Rect> rects = GetHighlightRects(range, this.textBlock);

                IEnumerable <Geometry> rectGeometries = from rect in rects
                                                        select FrozenGeometryFromRect(rect);

                GeometryCollection collection = new GeometryCollection(rectGeometries);
                collection.Freeze();

                result = new GeometryGroup()
                {
                    Children = collection
                };
                result.Freeze();
            }

            return(result);
        }
Ejemplo n.º 34
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geometryCollection"></param>
        /// <param name="writer"></param>
        protected void Write(GeometryCollection geometryCollection, XmlWriter writer)
        {
            writer.WriteStartElement(GMLElements.gmlPrefix, "MultiGeometry", GMLElements.gmlNS);
            if (_gmlVersion == GMLVersion.Two)
            {
                // Required in version 2
                writer.WriteAttributeString("srsName", GetEpsgCode(geometryCollection.Factory.SRID));
            }
            for (int i = 0; i < geometryCollection.NumGeometries; i++)
            {
                writer.WriteStartElement("geometryMember", GMLElements.gmlNS);
                Write(geometryCollection.Geometries[i], writer);
                writer.WriteEndElement();
            }

            if (geometryCollection.NumGeometries == 0 && _gmlVersion == GMLVersion.Two)
            {
                writer.WriteStartElement("geometryMember", GMLElements.gmlNS);
                writer.WriteEndElement();
            }

            writer.WriteEndElement();
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Tests the interior vertices (if any) defined by a linear Geometry
        /// for the best inside point. If a Geometry is not of dimension 1
        /// it is not tested.
        /// </summary>
        /// <param name="geom">The geometry to add.</param>
        private void Add(Geometry geom)
        {
            GeometryType geomType = geom.GeometryType;

            if (geomType == GeometryType.Polygon)
            {
                AddPolygon(geom);
            }
            else if (geomType == GeometryType.GeometryCollection ||
                     geomType == GeometryType.MultiPolygon ||
                     geomType == GeometryType.MultiCircle ||
                     geomType == GeometryType.MultiEllipse ||
                     geomType == GeometryType.MultiRectangle)
            {
                GeometryCollection gc = (GeometryCollection)geom;
                int nCount            = gc.NumGeometries;

                for (int i = 0; i < nCount; i++)
                {
                    Add(gc.GetGeometry(i));
                }
            }
        }
Ejemplo n.º 36
0
        public void TestRelationMultipolygonAreaOneOuter()
        {
            // tests a multipolygon containing one 'outer' member.
            MemoryDataSource source = new MemoryDataSource(
                Node.Create(1, 0, 0),
                Node.Create(2, 1, 0),
                Node.Create(3, 0, 1),
                Way.Create(1, 1, 2, 3, 1),
                Relation.Create(1,
                                new TagsCollection(
                                    Tag.Create("type", "multipolygon")),
                                RelationMember.Create(1, "outer", OsmGeoType.Way)));

            GeometryInterpreter interpreter = new SimpleGeometryInterpreter();
            GeometryCollection  geometries  = interpreter.Interpret(source.GetRelation(1), source);

            Assert.IsNotNull(geometries);
            Assert.AreEqual(1, geometries.Count);
            Geometry geometry = geometries[0];

            Assert.IsInstanceOf <LineairRing>(geometry);
            Assert.IsTrue(geometry.Attributes.ContainsKeyValue("type", "multipolygon"));
        }
Ejemplo n.º 37
0
        /// <summary> Adds the point(s) defined by a Geometry to the centroid total.
        /// If the geometry is not of dimension 0 it does not contribute to the centroid.
        /// </summary>
        /// <param name="geometry">the geometry to Add
        /// </param>
        public void Add(Geometry geometry)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }

            GeometryType geomType = geometry.GeometryType;

            if (geomType == GeometryType.Point)
            {
                Add(geometry.Coordinate);
            }
            else if (geomType == GeometryType.GeometryCollection ||
                     geomType == GeometryType.MultiPoint)
            {
                GeometryCollection gc = (GeometryCollection)geometry;
                for (int i = 0; i < gc.NumGeometries; i++)
                {
                    Add(gc.GetGeometry(i));
                }
            }
        }
Ejemplo n.º 38
0
        private async Task <Geometry> ParseGeometry(XElement node)
        {
            switch (node.Name.LocalName)
            {
            case "Point":
                return(ParsePoint(node));

            case "LineString":
                return(await ParseLineString(node));

            case "Polygon":
                return(await ParsePolygon(node));

            case "MultiGeometry":
                var mg    = new GeometryCollection();
                var geoms = XmlUtilities.GetChildNodes(node, geomTypes);
                foreach (var ge in geoms)
                {
                    var g = await ParseGeometry(ge);

                    if (g != null)
                    {
                        mg.Geometries.Add(g);
                    }
                }
                if (mg.Geometries.Count > 0)
                {
                    return(mg);
                }
                break;

            default:
                break;
            }

            return(null);
        }
Ejemplo n.º 39
0
        public void test_Count()
        {
            //create a geomerty collection
            GeometryCollection geoColl = CreateCollection();

            Assertion.AssertEquals("Count-1: ", 10, geoColl.Count);

            //now try it with a null geometry collection
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            geoColl = gf.CreateGeometryCollection(null);

            Assertion.AssertEquals("Count-2: ", 0, geoColl.Count);

            //now try it with a different geometry collection
            geoColl = CreateCollection2();

            Assertion.AssertEquals("Count-3: ", 10, geoColl.Count);

            //now try it with a mixed geometry collection
            geoColl = CreateCollection3();

            Assertion.AssertEquals("Count-4: ", 10, geoColl.Count);
        }
Ejemplo n.º 40
0
        public void test_IsEmpty()
        {
            //create a geomerty collection
            GeometryCollection geoColl = CreateCollection();

            Assertion.AssertEquals("IsEmpty()-1: ", false, geoColl.IsEmpty());

            //now try it with a null geometry collection
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            geoColl = gf.CreateGeometryCollection(null);

            Assertion.AssertEquals("IsEmpty()-2: ", true, geoColl.IsEmpty());

            //now try it with a different geometry collection
            geoColl = CreateCollection2();

            Assertion.AssertEquals("IsEmpty()-3: ", false, geoColl.IsEmpty());

            //now try it with a mixed geometry collection
            geoColl = CreateCollection3();

            Assertion.AssertEquals("IsEmpty()-4: ", false, geoColl.IsEmpty());
        }
Ejemplo n.º 41
0
        /// <summary>
        /// Computes a convex hull of the specified points.
        /// </summary>
        /// <param name="points">Enumerator of coordinates for which convex hull should be computed</param>
        /// <returns>A list containing a sequence of the convex hull points</returns>
        public static IList <GeoPoint> GetConvexHull(IEnumerable <GeoPoint> points)
        {
            GeographyCollection geographyCollection = new GeographyCollection();

            foreach (GeoPoint p in points)
            {
                geographyCollection.Add(p);
            }

            GnomonicProjection projection         = GeometrySpreader.GetProjection(geographyCollection);
            GeometryCollection geometryCollection = GeometrySpreader.GetGeometries(geographyCollection, projection);
            List <ICoordinate> list = new List <ICoordinate>();

            foreach (IGeometry g in geometryCollection)
            {
                list.Add(((PointD)g).Coordinate);
            }

            IList <ICoordinate> planarResult = PlanimetryAlgorithms.GetConvexHull(list);

            geometryCollection.Clear();
            foreach (ICoordinate p in planarResult)
            {
                geometryCollection.Add(new PointD(p));
            }

            geographyCollection = GeometrySpreader.GetGeographies(geometryCollection, projection);
            List <GeoPoint> result = new List <GeoPoint>();

            foreach (GeoPoint p in geographyCollection)
            {
                result.Add(p);
            }

            return(result);
        }
Ejemplo n.º 42
0
        public void test_GetBoundaryDimension()
        {
            //create a geomerty collection
            GeometryCollection geoColl = CreateCollection();

            Assertion.AssertEquals("GetBoundaryDimension-1: ", -1, geoColl.GetBoundaryDimension());

            //now try it with a null geometry collection
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            geoColl = gf.CreateGeometryCollection(null);

            Assertion.AssertEquals("GetBoundaryDimension-2: ", -1, geoColl.GetBoundaryDimension());

            //now try it with a different geometry collection
            geoColl = CreateCollection2();

            Assertion.AssertEquals("GetBoundaryDimension-3: ", 0, geoColl.GetBoundaryDimension());

            //now try it with a mixed geometry collection
            geoColl = CreateCollection3();

            Assertion.AssertEquals("GetBoundryDimension-4: ", 0, geoColl.GetBoundaryDimension());
        }
Ejemplo n.º 43
0
        public void test_NumPoints()
        {
            //create a geomerty collection
            GeometryCollection geoColl = CreateCollection();

            Assertion.AssertEquals("NumPoints-1: ", 10, geoColl.GetNumPoints());

            //now try it with a null geometry collection
            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            geoColl = gf.CreateGeometryCollection(null);

            Assertion.AssertEquals("NumPoints-2: ", 0, geoColl.GetNumPoints());

            //now try it with a different geometry collection
            geoColl = CreateCollection2();

            Assertion.AssertEquals("NumPoints-3: ", 1000, geoColl.GetNumPoints());

            //now try it with a mixed geometry collection
            geoColl = CreateCollection3();

            Assertion.AssertEquals("NumPoints-4: ", 130, geoColl.GetNumPoints());
        }
Ejemplo n.º 44
0
        public void KmlReadGeometryv2_1()
        {
            // initialize the geometry source.
            KmlGeoStreamSource kmlSource = new KmlGeoStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v2.1.kml"));

            // pull all the objects from the stream into the given collection.
            GeometryCollection kmlCollection = new GeometryCollection(kmlSource);
            List <Geometry>    geometries    = new List <Geometry>(kmlCollection);

            // test collection contents.
            Assert.AreEqual(23, geometries.Count);
            Assert.IsInstanceOf(typeof(LineString), geometries[0]);
            Assert.IsInstanceOf(typeof(LineString), geometries[1]);
            Assert.IsInstanceOf(typeof(LineString), geometries[2]);
            Assert.IsInstanceOf(typeof(LineString), geometries[3]);
            Assert.IsInstanceOf(typeof(LineString), geometries[4]);
            Assert.IsInstanceOf(typeof(LineString), geometries[5]);
            Assert.IsInstanceOf(typeof(LineString), geometries[6]);
            Assert.IsInstanceOf(typeof(LineString), geometries[7]);
            Assert.IsInstanceOf(typeof(LineString), geometries[8]);
            Assert.IsInstanceOf(typeof(LineString), geometries[9]);
            Assert.IsInstanceOf(typeof(LineString), geometries[10]);
            Assert.IsInstanceOf(typeof(LineString), geometries[11]);
            Assert.IsInstanceOf(typeof(LineString), geometries[12]);
            Assert.IsInstanceOf(typeof(LineString), geometries[13]);
            Assert.IsInstanceOf(typeof(LineString), geometries[14]);
            Assert.IsInstanceOf(typeof(LineString), geometries[15]);
            Assert.IsInstanceOf(typeof(LineString), geometries[16]);
            Assert.IsInstanceOf(typeof(LineString), geometries[17]);
            Assert.IsInstanceOf(typeof(LineString), geometries[18]);
            Assert.IsInstanceOf(typeof(LineString), geometries[19]);
            Assert.IsInstanceOf(typeof(LineString), geometries[20]);
            Assert.IsInstanceOf(typeof(LineString), geometries[21]);
            Assert.IsInstanceOf(typeof(LineString), geometries[22]);
        }
Ejemplo n.º 45
0
        void UpdateChildren(GeometryCollection oldCollection, GeometryCollection newCollection)
        {
            if (oldCollection != null)
            {
                oldCollection.CollectionChanged -= OnChildrenCollectionChanged;

                foreach (var oldChildren in oldCollection)
                {
                    oldChildren.PropertyChanged -= OnChildrenPropertyChanged;
                }
            }

            if (newCollection == null)
            {
                return;
            }

            newCollection.CollectionChanged += OnChildrenCollectionChanged;

            foreach (var newChildren in newCollection)
            {
                newChildren.PropertyChanged += OnChildrenPropertyChanged;
            }
        }
        public void IsMeasured_ReturnsFalseForEmptyCollection()
        {
            GeometryCollection<Geometry> target = new GeometryCollection<Geometry>();

            Assert.False(target.IsMeasured);
        }
        public void IsMeasured_ReturnsFalseForCollectionOfNonMeasuredObjects()
        {
            GeometryCollection<Geometry> target = new GeometryCollection<Geometry>(_geometries);

            Assert.False(target.IsMeasured);
        }
Ejemplo n.º 48
0
 /// <summary>
 /// Converts a GeometryCollection to &lt;GeometryCollection Text &gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="geometryCollection">The GeometryCollection to process.</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 private static void AppendGeometryCollectionText(GeometryCollection geometryCollection, StringWriter writer)
 {
     if (geometryCollection == null || geometryCollection.IsEmpty())
         writer.Write("EMPTY");
     else
     {
         writer.Write("(");
         for (int i = 0; i < geometryCollection.Collection.Count; i++)
         {
             if (i > 0)
                 writer.Write(", ");
             AppendGeometryTaggedText(geometryCollection[i], writer);
         }
         writer.Write(")");
     }
 }
Ejemplo n.º 49
0
 /// <summary>
 /// Converts a GeometryCollection to &lt;GeometryCollection Tagged
 /// Text&gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="geometryCollection">The GeometryCollection to process</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 private static void AppendGeometryCollectionTaggedText(GeometryCollection geometryCollection,
                                                        StringWriter writer)
 {
     writer.Write("GEOMETRYCOLLECTION ");
     AppendGeometryCollectionText(geometryCollection, writer);
 }
Ejemplo n.º 50
0
        private static Geometry CreateWKBGeometryCollection(BinaryReader reader, WkbByteOrder byteOrder)
        {
            // The next byte in the array tells the number of geometries in this collection.
            int numGeometries = (int) ReadUInt32(reader, byteOrder);

            // Create a new array for the geometries.
            GeometryCollection geometries = new GeometryCollection();

            // Loop on the number of geometries.
            for (int i = 0; i < numGeometries; i++)
            {
                // Call the main create function with the next geometry.
                geometries.Collection.Add(Parse(reader));
            }

            // Create and return the next geometry.
            return geometries;
        }
Ejemplo n.º 51
0
        /// <summary>
        /// Interprets an OSM-object and returns the corresponding geometry.
        /// </summary>
        /// <param name="osmObject"></param>
        /// <returns></returns>
        public override GeometryCollection Interpret(CompleteOsmGeo osmObject)
        {
            // DISCLAIMER: this is a very very very simple geometry interpreter and
            // contains hardcoded all relevant tags.

            GeometryCollection collection = new GeometryCollection();
            TagsCollectionBase tags;
            if (osmObject != null)
            {
                switch (osmObject.Type)
                {
                    case CompleteOsmType.Node:
                        TagsCollection newCollection = new TagsCollection(
                            osmObject.Tags);
                        newCollection.RemoveKey("FIXME");
                        newCollection.RemoveKey("node");
                        newCollection.RemoveKey("source");

                        if (newCollection.Count > 0)
                        { // there is still some relevant information left.
                            collection.Add(new Point((osmObject as CompleteNode).Coordinate));
                        }
                        break;
                    case CompleteOsmType.Way:
                        tags = osmObject.Tags;

                        bool isArea = false;
                        if ((tags.ContainsKey("building") && !tags.IsFalse("building")) ||
                            (tags.ContainsKey("landuse") && !tags.IsFalse("landuse")) ||
                            (tags.ContainsKey("amenity") && !tags.IsFalse("amenity")) ||
                            (tags.ContainsKey("harbour") && !tags.IsFalse("harbour")) ||
                            (tags.ContainsKey("historic") && !tags.IsFalse("historic")) ||
                            (tags.ContainsKey("leisure") && !tags.IsFalse("leisure")) ||
                            (tags.ContainsKey("man_made") && !tags.IsFalse("man_made")) ||
                            (tags.ContainsKey("military") && !tags.IsFalse("military")) ||
                            (tags.ContainsKey("natural") && !tags.IsFalse("natural")) ||
                            (tags.ContainsKey("office") && !tags.IsFalse("office")) ||
                            (tags.ContainsKey("place") && !tags.IsFalse("place")) ||
                            (tags.ContainsKey("power") && !tags.IsFalse("power")) ||
                            (tags.ContainsKey("public_transport") && !tags.IsFalse("public_transport")) ||
                            (tags.ContainsKey("shop") && !tags.IsFalse("shop")) ||
                            (tags.ContainsKey("sport") && !tags.IsFalse("sport")) ||
                            (tags.ContainsKey("tourism") && !tags.IsFalse("tourism")) ||
                            (tags.ContainsKey("waterway") && !tags.IsFalse("waterway")) ||
                            (tags.ContainsKey("wetland") && !tags.IsFalse("wetland")) ||
                            (tags.ContainsKey("water") && !tags.IsFalse("water")) ||
                            (tags.ContainsKey("aeroway") && !tags.IsFalse("aeroway")))
                        { // these tags usually indicate an area.
                            isArea = true;
                        }

                        if (tags.IsTrue("area"))
                        { // explicitly indicated that this is an area.
                            isArea = true;
                        }
                        else if (tags.IsFalse("area"))
                        { // explicitly indicated that this is not an area.
                            isArea = false;
                        }

                        if (isArea)
                        { // area tags leads to simple polygon
                            LineairRing lineairRing = new LineairRing((osmObject as CompleteWay).GetCoordinates().ToArray<GeoCoordinate>());
                            lineairRing.Attributes = new SimpleGeometryAttributeCollection(tags);
                            collection.Add(lineairRing);
                        }
                        else
                        { // no area tag leads to just a line.
                            LineString lineString = new LineString((osmObject as CompleteWay).GetCoordinates().ToArray<GeoCoordinate>());
                            lineString.Attributes = new SimpleGeometryAttributeCollection(tags);
                            collection.Add(lineString);
                        }
                        break;
                    case CompleteOsmType.Relation:
                        CompleteRelation relation = (osmObject as CompleteRelation);
                        tags = relation.Tags;

                        string typeValue;
                        if (tags.TryGetValue("type", out typeValue))
                        { // there is a type in this relation.
                            if (typeValue == "multipolygon")
                            { // this relation is a multipolygon.
                                Geometry geometry = this.InterpretMultipolygonRelation(relation);
                                if (geometry != null)
                                { // add the geometry.
                                    collection.Add(geometry);
                                }
                            }
                            else if (typeValue == "boundary")
                            { // this relation is a boundary.

                            }
                        }
                        break;
                }
            }
            return collection;
        }
Ejemplo n.º 52
0
 /// <summary>
 /// Creates a <see cref="GeometryCollection"/> using the next token in the stream.
 /// </summary>
 /// <param name="tokenizer"> Tokenizer over a stream of text in Well-known Text
 /// format. The next tokens must form a GeometryCollection Text.</param>
 /// <returns>
 /// A <see cref="GeometryCollection"/> specified by the next token in the stream.</returns>
 private static GeometryCollection ReadGeometryCollectionText(WktStreamTokenizer tokenizer)
 {
     GeometryCollection geometries = new GeometryCollection();
     string nextToken = GetNextEmptyOrOpener(tokenizer);
     if (nextToken.Equals("EMPTY"))
         return geometries;
     geometries.Collection.Add(ReadGeometryTaggedText(tokenizer));
     nextToken = GetNextCloserOrComma(tokenizer);
     while (nextToken.Equals(","))
     {
         geometries.Collection.Add(ReadGeometryTaggedText(tokenizer));
         nextToken = GetNextCloserOrComma(tokenizer);
     }
     return geometries;
 }
Ejemplo n.º 53
0
        private GeometryCollection calculateOverlay(IGeometry geometry1, IGeometry geometry2, OverlayType operation, bool performSnapping)
        {
            GeometryCollection result = new GeometryCollection();

            if (geometry1 == null && geometry2 == null)
                return result;

            if (geometry2 == null)
            {
                if (operation != OverlayType.Intersection)
                    result.Add((IGeometry)geometry1.Clone());

                return result;
            }

            if (geometry1 == null)
            {
                if (operation == OverlayType.Intersection || operation == OverlayType.Difference)
                    return result;
                result.Add((IGeometry)geometry2.Clone());

                return result;
            }

            // If the bounding rectangles do not intersect, the result of all operations can be obtained easily
            BoundingRectangle br1 = geometry1.GetBoundingRectangle();
            BoundingRectangle br2 = geometry2.GetBoundingRectangle();
            if(!br1.IsEmpty())
                br1.Grow(PlanimetryAlgorithms.Tolerance);
            if (!br2.IsEmpty())
                br2.Grow(PlanimetryAlgorithms.Tolerance);

            if (!br1.Intersects(br2))
                return calculateNonIntersectedObjectsOverlay(geometry1, geometry2, operation, performSnapping);

            // easier to convert the point-to-multipoint to preserve generality
            if (geometry1 is PointD)
            {
                PointD p = (PointD)geometry1.Clone();
                geometry1 = new MultiPoint(new ICoordinate[] { p.Coordinate });
            }

            if (geometry2 is PointD)
            {
                PointD p = (PointD)geometry2.Clone();
                geometry2 = new MultiPoint(new ICoordinate[] { p.Coordinate });
            }

            int minDim = Math.Min((int)geometry1.Dimension, (int)geometry2.Dimension);
            int maxDim = Math.Max((int)geometry1.Dimension, (int)geometry2.Dimension);

            // overlay calculation points
            if (minDim == 0 && maxDim == 0)
                getPointPointOverlay((MultiPoint)geometry1, (MultiPoint)geometry2, operation, result);

            // calculation overlay polylines
            if (minDim == 1 && maxDim == 1)
                getPolylinePolylineOverlay((Polyline)geometry1, (Polyline)geometry2, operation, result, false);

            // calculation of polygon overlay
            if (minDim == 2 && maxDim == 2)
                getPolygonPolygonOverlay((Polygon)geometry1, (Polygon)geometry2, operation, result, false);

            // calculation overlay points and polylines
            if (minDim == 0 && maxDim == 1)
            {
                if (geometry1 is MultiPoint)
                    getPointPolylineOverlay((MultiPoint)geometry1, (Polyline)geometry2, operation, result, false, false);
                else
                    getPointPolylineOverlay((MultiPoint)geometry2, (Polyline)geometry1, operation, result, false, true);
            }

            // calculation point and polygon overlay
            if (minDim == 0 && maxDim == 2)
            {
                if (geometry1 is MultiPoint)
                    getPointPolygonOverlay((MultiPoint)geometry1, (Polygon)geometry2, operation, result, false, false);
                else
                    getPointPolygonOverlay((MultiPoint)geometry2, (Polygon)geometry1, operation, result, false, true);
            }

            // calculation overlay polylines and polygons
            if (minDim == 1 && maxDim == 2)
            {
                if (geometry1 is Polyline)
                    getPolylinePolygonOverlay((Polyline)geometry1, (Polygon)geometry2, operation, result, false, false);
                else
                    getPolylinePolygonOverlay((Polyline)geometry2, (Polygon)geometry1, operation, result, false, true);
            }

            return result;
        }
Ejemplo n.º 54
0
        private void getPointPolygonOverlay(MultiPoint mp, Polygon polygon, OverlayType operation, GeometryCollection result, bool performSnapping, bool inverseArgs)
        {
            try
            {
                _geometry1 = mp;
                _geometry2 = polygon;
                bool isValid = true;

                try
                {
                    init(performSnapping);

                    PlanarGraph graph = PlanarGraph.Build(_geometry1, _geometry2);

                    // duration test of the point inside the polygon to "collect" the original ground
                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        edge.Enabled = edge.Label.UsedByObject2;
                    }

                    Polygon pg = graph.BuildPolygon(inverseArgs, !inverseArgs);

                    // classify edges and nodes
                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        switch (operation)
                        {
                            case OverlayType.Intersection:
                                edge.Enabled = false;
                                break;
                            case OverlayType.Union:
                                edge.Enabled = edge.Label.UsedByObject2;
                                break;
                            case OverlayType.Difference:
                                edge.Enabled = inverseArgs ? edge.Label.UsedByObject2 : false;
                                break;
                            case OverlayType.SymmetricDifference:
                                edge.Enabled = edge.Label.UsedByObject2;
                                break;
                        }
                    }

                    foreach (PlanarGraphNode node in graph.Nodes)
                    {
                        bool hasEnabledEdges = false;
                        foreach (PlanarGraphEdge edge in node.IncidentEdges)
                            if (edge.Enabled)
                            {
                                hasEnabledEdges = true;
                                break;
                            }
                        if (hasEnabledEdges)
                            node.Enabled = false;
                        else
                        {
                            switch (operation)
                            {
                                case OverlayType.Intersection:
                                    node.Enabled = (pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2) ||
                                                   (node.Label.UsedByObject2 && node.Label.UsedByObject1);
                                    break;
                                case OverlayType.Union:
                                    node.Enabled = !pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2;
                                    break;
                                case OverlayType.Difference:
                                    node.Enabled = inverseArgs ? false : !pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2;
                                    break;
                                case OverlayType.SymmetricDifference:
                                    node.Enabled = !pg.ContainsPoint(node.Point) && !node.Label.UsedByObject2;
                                    break;
                            }
                        }
                    }

                    // build results:
                    // point
                    List<PointD> points = graph.BuildPoints();

                    foreach (PointD p in points)
                        result.Add(p);

                    // The landfill has been constructed to assess the position of the point.
                    // But it must be added to the result only in the case of the calculation of association,
                    // symmetric difference and the difference, which is a decrease.
                    if (operation == OverlayType.Union || operation == OverlayType.SymmetricDifference ||
                       (operation == OverlayType.Difference && inverseArgs))
                    {
                        if (pg.CoordinateCount > 0)
                            result.Add(pg);
                    }

                    for (int i = 0; i < result.Count; i++)
                    {
                        IGeometry g = translateGeometry(result[i], _translationCenter.X, _translationCenter.Y);
                        if (g is PointD)
                            result[i] = g;
                    }
                }
                catch (TopologyException)
                {
                    if (!performSnapping)
                        isValid = false;
                    else
                        throw new InvalidOperationException("Unable to complete operation correctly with this value of tolerance (PlanimertyAlgorithms.Tolerance)");
                }

                if (isValid)
                    return;
                else
                {
                    // overlay has not been calculated.
                    // it may be possible to calculate the overlay aligned to the grid
                    getPointPolygonOverlay(mp, polygon, operation, result, true, inverseArgs);
                    return;
                }
            }
            finally
            {
                _geometry1 = null;
                _geometry2 = null;
            }
        }
Ejemplo n.º 55
0
        private void getPolylinePolygonOverlay(Polyline polyline, Polygon polygon, OverlayType operation, GeometryCollection result, bool performSnapping, bool inverseArgs)
        {
            try
            {
                _geometry1 = polyline;
                _geometry2 = polygon;
                bool isValid = true;

                try
                {
                    init(performSnapping);

                    PlanarGraph graph = PlanarGraph.Build(_geometry1, _geometry2);

                    //building polygon
                    foreach (PlanarGraphNode node in graph.Nodes)
                        node.Layout = PlanarGraphNode.NodeLayout.Unknown;

                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        edge.Enabled = edge.Label.UsedByObject2;
                    }
                    Polygon pg = graph.BuildPolygon(true, false);

                    // build results:
                    // point
                    foreach (PlanarGraphNode node in graph.Nodes)
                        node.Enabled = isNodeEnabled(node, operation, polyline, pg, inverseArgs);

                    List<PointD> points = graph.BuildPoints();

                    foreach (PointD p in points)
                        result.Add(p);

                    // polyline
                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        edge.Enabled = isLinearEdgeEnabled(edge, operation, pg, inverseArgs);
                    }

                    Polyline pl = graph.BuildPolyline(false, false);
                    if (pl.CoordinateCount > 0)
                        result.Add(pl);

                    // landfill has been constructed, it may be added to the result
                    if (operation == OverlayType.SymmetricDifference || operation == OverlayType.Union ||
                        (operation == OverlayType.Difference && inverseArgs))
                        if(pg.CoordinateCount > 0)
                            result.Add(pg);

                    for (int i = 0; i < result.Count; i++)
                    {
                        IGeometry g = translateGeometry(result[i], _translationCenter.X, _translationCenter.Y);
                        if (g is PointD)
                            result[i] = g;
                    }
                }
                catch (TopologyException)
                {
                    if (!performSnapping)
                        isValid = false;
                    else
                        throw new InvalidOperationException("Unable to complete operation correctly with this value of tolerance (PlanimertyAlgorithms.Tolerance)");
                }

                if (isValid)
                    return;
                else
                {
                    //overlay has not been calculated.
                    // it may be possible to calculate the overlay aligned to the grid
                    getPolylinePolygonOverlay(polyline, polygon, operation, result, true, inverseArgs);
                    return;
                }
            }
            finally
            {
                _geometry1 = null;
                _geometry2 = null;
            }
        }
Ejemplo n.º 56
0
        private void getPointPolylineOverlay(MultiPoint mp, Polyline polyline, OverlayType operation, GeometryCollection result, bool performSnapping, bool inverseArgs)
        {
            try
            {
                _geometry1 = mp;
                _geometry2 = polyline;
                bool isValid = true;

                try
                {
                    init(performSnapping);

                    PlanarGraph graph = PlanarGraph.Build(_geometry1, _geometry2);

                    // classify edges and nodes
                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        switch (operation)
                        {
                            case OverlayType.Intersection:
                                edge.Enabled = false;
                                break;
                            case OverlayType.Union:
                                edge.Enabled = edge.Label.UsedByObject2;
                                break;
                            case OverlayType.Difference:
                                edge.Enabled = inverseArgs ? edge.Label.UsedByObject2 : false;
                                break;
                            case OverlayType.SymmetricDifference:
                                edge.Enabled = edge.Label.UsedByObject2;
                                break;
                        }
                    }

                    foreach (PlanarGraphNode node in graph.Nodes)
                    {
                        bool hasEnabledEdges = false;
                        foreach (PlanarGraphEdge edge in node.IncidentEdges)
                            if (edge.Enabled)
                            {
                                hasEnabledEdges = true;
                                break;
                            }
                        if (hasEnabledEdges)
                            node.Enabled = false;
                        else
                        {
                            switch (operation)
                            {
                                case OverlayType.Intersection:
                                    node.Enabled = node.Label.UsedByObject1 && node.Label.UsedByObject2;
                                    break;
                                case OverlayType.Union:
                                    node.Enabled = node.Label.UsedByObject1;
                                    break;
                                case OverlayType.Difference:
                                    node.Enabled = inverseArgs ? false : !node.Label.UsedByObject2;
                                    break;
                                case OverlayType.SymmetricDifference:
                                    node.Enabled = true;
                                    break;
                            }
                        }
                    }

                    // build results:
                    // point
                    List<PointD> points = graph.BuildPoints();

                    foreach (PointD p in points)
                        result.Add(p);

                    // polyline
                    Polyline pl = graph.BuildPolyline(false, false);

                    if (pl.CoordinateCount > 0)
                        result.Add(pl);

                    for (int i = 0; i < result.Count; i++)
                    {
                        IGeometry g = translateGeometry(result[i], _translationCenter.X, _translationCenter.Y);
                        if (g is PointD)
                            result[i] = g;
                    }
                }
                catch (TopologyException)
                {
                    if (!performSnapping)
                        isValid = false;
                    else
                        throw new InvalidOperationException("Unable to complete operation correctly with this value of tolerance (PlanimertyAlgorithms.Tolerance)");
                }

                if (isValid)
                    return;
                else
                {
                    // overlay has not been calculated.
                    // it may be possible to calculate the overlay aligned to the grid
                    getPointPolylineOverlay(mp, polyline, operation, result, true, inverseArgs);
                    return;
                }
            }
            finally
            {
                _geometry1 = null;
                _geometry2 = null;
            }
        }
Ejemplo n.º 57
0
        private void getPolygonPolygonOverlay(Polygon polygon1, Polygon polygon2, OverlayType operation, GeometryCollection result, bool performSnapping)
        {
            try
            {
                _geometry1 = polygon1;
                _geometry2 = polygon2;
                bool isValid = true;

                try
                {
                    init(performSnapping);

                    PlanarGraph graph = PlanarGraph.Build(_geometry1, _geometry2);

                    // build the first facility
                    foreach (PlanarGraphNode node in graph.Nodes)
                        node.Layout = PlanarGraphNode.NodeLayout.Unknown;

                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        edge.Enabled = edge.Label.UsedByObject1;
                    }
                    Polygon p1 = graph.BuildPolygon(true, false);

                    // building a second facility
                    foreach (PlanarGraphNode node in graph.Nodes)
                        node.Layout = PlanarGraphNode.NodeLayout.Unknown;

                    foreach (PlanarGraphEdge edge in graph.Edges)
                    {
                        edge.IsVisited = false;
                        edge.Enabled = edge.Label.UsedByObject2;
                    }
                    Polygon p2 = graph.BuildPolygon(false, true);

                    // build results:
                    // point
                    if (operation == OverlayType.Intersection)
                        addPoints(graph, operation, p1, p2, result);

                    // polyline
                    if (operation == OverlayType.Intersection)
                        addPolyline(graph, operation, p1, p2, result);

                    // ground
                    addPolygon(graph, operation, p1, p2, result);

                    for (int i = 0; i < result.Count; i++)
                    {
                        IGeometry g = translateGeometry(result[i], _translationCenter.X, _translationCenter.Y);
                        if (g is PointD)
                            result[i] = g;
                    }
                }
                catch (TopologyException)
                {
                    if (!performSnapping)
                        isValid = false;
                    else
                        throw new InvalidOperationException("Unable to complete operation correctly with this value of tolerance (PlanimertyAlgorithms.Tolerance)");
                }

                if (isValid)
                    return;
                else
                {
                    // overlay has not been calculated.
                    // it may be possible to calculate the overlay aligned to the grid
                    getPolygonPolygonOverlay(polygon1, polygon2, operation, result, true);
                    return;
                }
            }
            finally
            {
                _geometry1 = null;
                _geometry2 = null;
            }
        }
Ejemplo n.º 58
0
        private GeometryCollection calculateNonIntersectedObjectsOverlay(IGeometry geometry1, IGeometry geometry2, OverlayType operation, bool performSnapping)
        {
            GeometryCollection result = new GeometryCollection();

            // zero crossing
            if (operation == OverlayType.Intersection)
                return result;

            // difference is equal to the first object
            if (operation == OverlayType.Difference)
            {
                result.Add((IGeometry)geometry1.Clone());
                return result;
            }

            // symmetric difference and the union concatenating
            try
            {
                if (geometry1 is Polygon && geometry2 is Polygon)
                {
                    _polygon1Contours = SimplifyContours(((Polygon)geometry1).Contours);
                    _polygon2Contours = SimplifyContours(((Polygon)geometry2).Contours);

                    Polygon p = new Polygon();
                    foreach (Contour c in _polygon1Contours)
                        p.Contours.Add(c);

                    foreach (Contour c in _polygon2Contours)
                        p.Contours.Add(c);

                    result.Add(p);
                }
                else if (geometry1 is Polyline && geometry2 is Polyline)
                {
                    Polyline p = new Polyline();

                    foreach (LinePath path in ((Polyline)geometry1).Paths)
                        p.Paths.Add(path);

                    foreach (LinePath path in ((Polyline)geometry2).Paths)
                        p.Paths.Add(path);

                    result.Add(p);
                }
                else
                {
                    // If a figure is still a proving ground to normalize topology
                    if (geometry1 is Polygon)
                    {
                        geometry1 = (IGeometry)((Polygon)geometry1).Clone();
                        ((Polygon)geometry1).Simplify();
                    }

                    if (geometry2 is Polygon)
                    {
                        geometry2 = (IGeometry)((Polygon)geometry2).Clone();
                        ((Polygon)geometry2).Simplify();
                    }

                    result.Add(geometry1);
                    result.Add(geometry2);
                }

                return result;
            }
            finally
            {
                _polygon1Contours = null;
                _polygon2Contours = null;
            }
        }
        public void IsMeasured_ReturnsTrueForCollectionWithAtLeastOneMeasuredObject()
        {
            var members = new Geometry[] { new Point(1, 2), new Point(2, 3, 4, 5) };
            GeometryCollection<Geometry> target = new GeometryCollection<Geometry>(members);

            Assert.True(target.IsMeasured);
        }
        private void CheckGeometries(GeometryCollection<Geometry> target, Geometry[] geometries)
        {
            Assert.Equal(geometries.Length, target.Geometries.Count);

            for (int i = 0; i < geometries.Length; i++) {
                Assert.Same(geometries[i], target.Geometries[i]);
            }
        }