示例#1
0
        private void MergeGeometry(IFeature target, IFeature source)
        {
            if (!target.Attributes[FeatureAttributes.POI_SOURCE].Equals(Sources.OSM) ||
                !source.Attributes[FeatureAttributes.POI_SOURCE].Equals(Sources.OSM))
            {
                // only merge geometry between OSM features
                return;
            }

            if (target.Geometry is GeometryCollection geometryCollection)
            {
                if (source.Geometry is GeometryCollection geometryCollectionSource)
                {
                    target.Geometry = _geometryFactory.CreateGeometryCollection(geometryCollection.Geometries.Concat(geometryCollectionSource.Geometries).ToArray());
                }
                else
                {
                    target.Geometry = _geometryFactory.CreateGeometryCollection(geometryCollection.Geometries.Concat(new[] { source.Geometry }).ToArray());
                }
            }
            else
            {
                target.Geometry = _geometryFactory.CreateGeometryCollection(new[] { target.Geometry, source.Geometry });
            }
        }
示例#2
0
 public void testBoundaryOfEmptyGeometry()
 {
     Assert.IsTrue(geometryFactory.CreatePoint((Coordinate)null).Boundary.GetType() ==
                   typeof(GeometryCollection));
     Assert.IsTrue(geometryFactory.CreateLinearRing(new Coordinate[] {}).Boundary.GetType() ==
                   typeof(MultiPoint));
     Assert.IsTrue(geometryFactory.CreateLineString(new Coordinate[] {}).Boundary.GetType() ==
                   typeof(MultiPoint));
     Assert.IsTrue(
         geometryFactory.CreatePolygon(geometryFactory.CreateLinearRing(new Coordinate[] {}), new LinearRing[] {})
         .Boundary.GetType() == typeof(MultiLineString));
     Assert.IsTrue(geometryFactory.CreateMultiPolygon(new Polygon[] {}).Boundary.GetType() ==
                   typeof(MultiLineString));
     Assert.IsTrue(geometryFactory.CreateMultiLineString(new LineString[] {}).Boundary.GetType() ==
                   typeof(MultiPoint));
     Assert.IsTrue(geometryFactory.CreateMultiPoint(new Point[] {}).Boundary.GetType() ==
                   typeof(GeometryCollection));
     try
     {
         var b = geometryFactory.CreateGeometryCollection(new Geometry[] {}).Boundary;
         Assert.IsTrue(false);
     }
     catch (ArgumentException e)
     {
     }
 }
示例#3
0
        private GeometryCollection ReadGeometryCollection()
        {
            int nGeometries = m_objReader.ReadInt32();

            if (nGeometries <= 0)
            {
                return(null);
            }

            Geometry[] geometries = new Geometry[nGeometries];

            for (int i = 0; i < nGeometries; i++)
            {
                BytesOrder byteOrder = (BytesOrder)m_objReader.ReadByte();  // handle the byte order
                m_objReader.Order = byteOrder;

                int geomType = m_objReader.ReadInt32();
                switch (geomType)
                {
                case 1:
                    geometries[i] = ReadPoint();
                    break;

                case 2:
                    geometries[i] = ReadLineString();
                    break;

                case 3:
                    geometries[i] = ReadPolygon();
                    break;

                case 4:
                    geometries[i] = ReadMultiPoint();
                    break;

                case 5:
                    geometries[i] = ReadMultiLineString();
                    break;

                case 6:
                    geometries[i] = ReadMultiPolygon();
                    break;

                case 7:
                    geometries[i] = ReadGeometryCollection();
                    break;

                default:
                    throw new GeometryIOException("The geometry type is not supported.");
                }
            }

            return(m_objFactory.CreateGeometryCollection(geometries));
        }
示例#4
0
        protected virtual Geometry Transform(GeometryCollection geom, Geometry parent)
        {
            GeometryList transGeomList = new GeometryList();

            for (int i = 0; i < geom.NumGeometries; i++)
            {
                Geometry transformGeom = Transform(geom[i]);
                if (transformGeom == null)
                {
                    continue;
                }
                if (pruneEmptyGeometry && transformGeom.IsEmpty)
                {
                    continue;
                }

                transGeomList.Add(transformGeom);
            }

            if (preserveGeometryCollectionType)
            {
                return(geomFactory.CreateGeometryCollection(transGeomList.ToArray()));
            }

            return(geomFactory.BuildGeometry(transGeomList));
        }
        /// <summary>
        /// Gets the computed variable-width line buffer.
        /// </summary>
        /// <returns>A polygon</returns>
        public Geometry GetResult()
        {
            Utilities.Assert.IsTrue(_line.NumPoints == _width.Length);

            var parts = new List <Geometry>();

            var pts = _line.Coordinates;

            for (int i = 0; i < _line.NumPoints; i++)
            {
                double dist  = _width[i] / 2;
                var    ptBuf = _line.GetPointN(i).Buffer(dist);
                parts.Add(ptBuf);

                if (i >= 1)
                {
                    var curvePts = GenerateSegmentCurve(pts[i - 1], pts[i],
                                                        _width[i - 1], _width[i]);
                    var segBuf = _geomFactory.CreatePolygon(curvePts);
                    parts.Add(segBuf);
                }
            }

            var partsGeom = _geomFactory.CreateGeometryCollection(GeometryFactory.ToGeometryArray(parts));
            var buffer    = partsGeom.Union();

            return(buffer);
        }
        public void test_Dimension()
        {
            //create a geomerty collection
            GeometryCollection geoColl = CreateCollection();

            //returns 0 because a point has a dimension of 0 & that is the largest dimesion in the collection
            Assertion.AssertEquals("Dimension-1: ", 0, geoColl.GetDimension());

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

            geoColl = gf.CreateGeometryCollection(null);

            //returns -1 because the collection is empty
            Assertion.AssertEquals("Dimension-2: ", -1, geoColl.GetDimension());

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

            //returns 1 because linestring has a dimension of 1 & that is the largest dimension in the collection
            Assertion.AssertEquals("Dimension-3: ", 1, geoColl.GetDimension());

            //returns 1 because linestring has a dimension of 1 & that is the largest dimension in the collection
            geoColl = CreateCollection3();

            Assertion.AssertEquals("Dimension-4: ", 1, geoColl.GetDimension());
        }
        private GeometryCollection CreateCollection()
        {
            //this is used to prevent having to rewrite this code over & over

            //create a new coordinate
            Coordinate coordinate = new Coordinate();
            //create a new point
            GeometryFactory gf    = new GeometryFactory(_precMod, _sRID);
            Point           point = gf.CreatePoint(coordinate);

            //create a new geometries array
            Geometry[] geom = new Geometry[10];
            //fill with points
            for (int i = 0; i < 10; i++)
            {
                //if this isn't here the coordinates for all the points are reset every time the coordinate is reset
                coordinate = new Coordinate();
                //make the x coordinate equal to the iterator
                coordinate.X = (double)i;
                //make the y coordinate equal to the iterator plus 10
                coordinate.Y = (double)i + 10;
                //create a new point to put in the geometry
                point = gf.CreatePoint(coordinate);
                //put the point in the geometies
                geom[i] = point;
            }
            //put the geometries into a geometry collection
            GeometryCollection geoColl = gf.CreateGeometryCollection(geom);

            return(geoColl);
        }
示例#8
0
        /// <summary>
        /// Computes the buffer polygon.
        /// </summary>
        /// <returns>A buffer polygon</returns>
        public Geometry GetResult()
        {
            var parts = new List <Geometry>();

            var pts = _line.Coordinates;

            // construct segment buffers
            for (int i = 1; i < pts.Length; i++)
            {
                double dist0 = _distance[i - 1];
                double dist1 = _distance[i];
                if (dist0 > 0 || dist1 > 0)
                {
                    var poly = SegmentBuffer(pts[i - 1], pts[i], dist0, dist1);
                    if (poly != null)
                    {
                        parts.Add(poly);
                    }
                }
            }

            var partsGeom = _geomFactory.CreateGeometryCollection(parts.ToArray());
            var buffer    = partsGeom.Union();

            // ensure an empty polygon is returned if needed
            if (buffer.IsEmpty)
            {
                return(_geomFactory.CreatePolygon());
            }
            return(buffer);
        }
        public void test_Coordinates()
        {
            //create a geomerty collection
            GeometryCollection geoColl = CreateCollection();

            //this geometry conatins 10 sets of coordinates
            Assertion.AssertEquals("Coordinates-1: ", 10, geoColl.GetCoordinates().Count);

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

            geoColl = gf.CreateGeometryCollection(null);

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

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

            //1000 sets of coordinates
            Assertion.AssertEquals("Cordinates-3: ", 1000, geoColl.GetCoordinates().Count);

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

            Assertion.AssertEquals("Coordinates-4: ", 130, geoColl.GetCoordinates().Count);
        }
        private GeometryCollection CreateCollection2()
        {
            //create a new geometries array
            Geometry[] geom = new Geometry[10];

            Coordinate  coordinate = new Coordinate();
            Coordinates coords     = new Coordinates();

            GeometryFactory gf         = new GeometryFactory(_precMod, _sRID);
            LineString      lineString = gf.CreateLineString(coords);

            for (int c = 0; c < 10; c++)
            {
                for (int i = c; i < c + 10; i++)
                {
                    //if this isn't here the coordinates for all the points are reset every time the coordinate is reset
                    coordinate = new Coordinate();
                    //make the x coordinate equal to the iterator
                    coordinate.X = (double)i;
                    //make the y coordinate equal to the iterator plus 10
                    coordinate.Y = (double)i + 10;
                    coords.Add(coordinate);
                }
                lineString = gf.CreateLineString(coords);
                geom[c]    = lineString;
            }
            //put the geometries into a geometry collection
            GeometryCollection geoColl = gf.CreateGeometryCollection(geom);

            return(geoColl);
        }
示例#11
0
        public static IGeometry SqlGeometryToGeometry(SqlGeometry geom, GeometryFactory factory)
        {
            if (geom.STIsEmpty())
            {
                return(factory.CreateGeometryCollection(null));
            }

            OpenGisGeometryType geometryType = (OpenGisGeometryType)Enum.Parse(typeof(OpenGisGeometryType), geom.STGeometryType().Value);

            switch (geometryType)
            {
            case OpenGisGeometryType.Point:
                return(SqlGeometryToGeometryPoint(geom, factory));

            case OpenGisGeometryType.LineString:
                return(SqlGeometryToGeometryLineString(geom, factory));

            case OpenGisGeometryType.Polygon:
                return(SqlGeometryToGeometryPolygon(geom, factory));

            case OpenGisGeometryType.MultiPoint:
                return(SqlGeometryToGeometryMultiPoint(geom, factory));

            case OpenGisGeometryType.MultiLineString:
                return(SqlGeometryToGeometryMultiLineString(geom, factory));

            case OpenGisGeometryType.MultiPolygon:
                return(SqlGeometryToGeometryMultiPolygon(geom, factory));

            case OpenGisGeometryType.GeometryCollection:
                return(SqlGeometryToGeometryGeometryCollection(geom, factory));
            }

            throw new ArgumentException(string.Format("Cannot convert SqlServer '{0}' to Geometry", geom.STGeometryType()), "geom");
        }
        /// <summary>
        /// Creates an empty result geometry of the appropriate dimension,
        /// based on the given overlay operation and the dimensions of the inputs.
        /// The created geometry is an atomic geometry,
        /// not a collection(unless the dimension is <see cref="Dimension.Unknown"/>,
        /// in which case a <c>GEOMETRYCOLLECTION EMPTY</c> is created.
        /// </summary>
        /// <param name="dim">The dimension of the empty geometry</param>
        /// <param name="geomFact">The geometry factory being used for the operation</param>
        /// <returns>An empty atomic geometry of the appropriate dimension</returns>
        internal static Geometry CreateEmptyResult(Dimension dim, GeometryFactory geomFact)
        {
            Geometry result = null;

            switch (dim)
            {
            case Dimension.Point:
                result = geomFact.CreatePoint();
                break;

            case Dimension.Curve:
                result = geomFact.CreateLineString();
                break;

            case Dimension.Surface:
                result = geomFact.CreatePolygon();
                break;

            case Dimension.Unknown:
                result = geomFact.CreateGeometryCollection();
                break;

            default:
                Assert.ShouldNeverReachHere("Unable to determine overlay result geometry dimension");
                break;
            }
            return(result);
        }
        /// <summary>
        /// Reads a <see cref="GeometryCollection"/> from the input stream.
        /// </summary>
        /// <param name="reader">The binary reader.</param>
        /// <param name="factory">The geometry factory to use for geometry creation.</param>
        /// <returns>The GeometryCollection</returns>
        protected GeometryCollection ReadGeometryCollection(BinaryReader reader, GeometryFactory factory)
        {
            int numGeometries = reader.ReadInt32();
            var geometries    = new Geometry[numGeometries];

            ReadGeometryArray(reader, geometries);
            return(factory.CreateGeometryCollection(geometries));
        }
示例#14
0
        /// <summary>
        /// Transforms a <see cref="GeometryCollection"/>.
        /// </summary>
        /// <param name="geoms">GeometryCollection to transform</param>
        /// <param name="transform">MathTransform</param>
        /// <returns>Transformed GeometryCollection</returns>
        public static GeoAPI.Geometries.IGeometryCollection TransformGeometryCollection(GeoAPI.Geometries.IGeometryCollection geoms, IMathTransform transform)
        {
            List <IGeometry> coll = new List <IGeometry>(geoms.Geometries.Length);

            foreach (IGeometry g in geoms.Geometries)
            {
                coll.Add(TransformGeometry(g, transform));
            }
            return(GeometryFactory.CreateGeometryCollection(coll.ToArray()));
        }
示例#15
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>
        /// <param name="factory">The factory to create the result geometry</param>
        /// <returns>
        /// A <see cref="GeometryCollection"/> specified by the next token in the stream.</returns>
        private static GeometryCollection ReadGeometryCollectionText(WktStreamTokenizer tokenizer, GeometryFactory factory)
        {
            var nextToken = GetNextEmptyOrOpener(tokenizer);

            if (nextToken.Equals("EMPTY"))
            {
                return(factory.CreateGeometryCollection(null));
            }
            var geometries = new List <Geometry>();

            geometries.Add(ReadGeometryTaggedText(tokenizer));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken.Equals(","))
            {
                geometries.Add(ReadGeometryTaggedText(tokenizer));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return(factory.CreateGeometryCollection(geometries.ToArray()));
        }
示例#16
0
        private static object CreateResult(List <Geometry> result, GeometryFactory geometryFactory)
        {
            if (result.Count == 1)
            {
                return(result[0]);
            }
            var resultGeoms = result.ToArray();

            return(geometryFactory.CreateGeometryCollection(resultGeoms));
        }
示例#17
0
        private static IGeometryCollection SqlGeometryToGeometryGeometryCollection(SqlGeometry geometry, GeometryFactory factory)
        {
            IGeometry[] geoms = new IGeometry[geometry.STNumGeometries().Value];
            for (int i = 1; i <= geoms.Length; i++)
            {
                geoms[i - 1] = SqlGeometryToGeometry(geometry.STGeometryN(i), factory);
            }

            return(factory.CreateGeometryCollection(geoms));
        }
示例#18
0
        /// <summary>
        /// Transforms a <see cref="NetTopologySuite.Geometries.GeometryCollection"/>.
        /// </summary>
        /// <param name="geoms">GeometryCollection to transform</param>
        /// <param name="transform">MathTransform</param>
        /// <param name="targetFactory">The factory to create the target geometry</param>
        /// <returns>Transformed GeometryCollection</returns>
        public static GeometryCollection TransformGeometryCollection(GeometryCollection geoms, MathTransform transform, GeometryFactory targetFactory)
        {
            var geomList = new Geometry[geoms.NumGeometries];

            for (var i = 0; i < geoms.NumGeometries; i++)
            {
                geomList[i] = TransformGeometry(geoms[i], transform, targetFactory);
            }
            return(targetFactory.CreateGeometryCollection(geomList));
        }
示例#19
0
        public void CreateEmptyGeometryCollectionSucceeds()
        {
            GeometryFactory factory = new GeometryFactory(
                new BufferedCoordinate2DFactory(),
                new BufferedCoordinate2DSequenceFactory());

            IGeometryCollection g = factory.CreateGeometryCollection();

            Assert.IsNotNull(g);
            Assert.IsTrue(g.IsEmpty);
        }
示例#20
0
        internal static GeometryCollection ToNTSGeometryCollection(Geometries.GeometryCollection geometryCollection,
                                                                   GeometryFactory factory)
        {
            Geometry[] geometries = new Geometry[geometryCollection.Collection.Count];
            int        index      = 0;

            foreach (Geometries.Geometry geometry in geometryCollection.Collection)
            {
                geometries[index++] = ToNTSGeometry(geometry, factory);
            }
            return(factory.CreateGeometryCollection(geometries) as GeometryCollection);
        }
示例#21
0
        /**
         *  Creates a <code>GeometryCollection</code> using the next token in the
         *  stream.
         *
         *@param  tokenizer        tokenizer over a stream of text in Well-known Text
         *      format. The next tokens must form a &lt;GeometryCollection Text&gt;.
         *@return                  a <code>GeometryCollection</code> specified by the
         *      next token in the stream
         *@throws  ParseException  if the coordinates used to create a <code>Polygon</code>
         *      shell and holes do not form closed linestrings, or if an unexpected
         *      token was encountered
         *@throws  IOException     if an I/O error occurs
         */
        private GeometryCollection ReadGeometryCollectionText(WktStreamTokenizer tokenizer)
        {
            string nextToken = GetNextEmptyOrOpener(tokenizer);

            if (nextToken == "EMPTY")
            {
                return(_geometryFactory.CreateGeometryCollection(new Geometry[] {}));
            }
            ArrayList geometries = new ArrayList();
            Geometry  geometry   = ReadGeometryTaggedText(tokenizer);

            geometries.Add(geometry);
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                geometry = ReadGeometryTaggedText(tokenizer);
                geometries.Add(geometry);
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            Geometry[] array = new Geometry[geometries.Count];
            return(_geometryFactory.CreateGeometryCollection((Geometry[])geometries.ToArray(typeof(Geometry))));
        }
示例#22
0
        /**
         * Reads one or more WKT geometries from a string.
         *
         * @param wkt
         * @param geomFact
         * @return
         * @throws ParseException
         * @throws IOException
         */

        public static Geometry ReadGeometriesFromWktString(string wkt, GeometryFactory geomFact)
        {
            var reader     = new WKTReader(geomFact);
            var fileReader = new WKTFileReader(new StringReader(wkt), reader);
            var geomList   = fileReader.Read();

            if (geomList.Count == 1)
            {
                return(geomList[0]);
            }

            return(geomFact.CreateGeometryCollection(GeometryFactory.ToGeometryArray(geomList)));
        }
        /// <summary>
        /// Creates a <c>GeometryCollection</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 &lt;GeometryCollection Text.
        /// </param>
        /// <returns>
        /// A <c>GeometryCollection</c> specified by the
        /// next token in the stream.</returns>
        private GeometryCollection ReadGeometryCollectionText(IList tokens)
        {
            string nextToken = GetNextEmptyOrOpener(tokens);

            if (nextToken.Equals("EMPTY")) //NOXLATE
            {
                return(geometryFactory.CreateGeometryCollection(Array.Empty <NetTopologySuite.Geometries.Geometry>()));
            }

            var geometries = new List <NetTopologySuite.Geometries.Geometry>();
            var geometry   = ReadGeometryTaggedText(tokens);

            geometries.Add(geometry);
            nextToken = GetNextCloserOrComma(tokens);
            while (nextToken.Equals(",")) //NOXLATE
            {
                geometry = ReadGeometryTaggedText(tokens);
                geometries.Add(geometry);
                nextToken = GetNextCloserOrComma(tokens);
            }
            return(geometryFactory.CreateGeometryCollection(geometries.ToArray()));
        }
        /// <summary>
        /// Gets the geometry for the triangles in a triangulated subdivision as a <see cref="GeometryCollection"/>
        /// of triangular <see cref="Polygon"/>s.
        /// </summary>
        /// <param name="geomFact">the GeometryFactory to use</param>
        /// <returns>a GeometryCollection of triangular Polygons</returns>
        public GeometryCollection GetTriangles(GeometryFactory geomFact)
        {
            var triPtsList = GetTriangleCoordinates(false);
            var tris       = new Polygon[triPtsList.Count];
            int i          = 0;

            foreach (var triPt in triPtsList)
            {
                tris[i++] = geomFact
                            .CreatePolygon(geomFact.CreateLinearRing(triPt));
            }
            return(geomFact.CreateGeometryCollection(tris));
        }
示例#25
0
        public void SetUp()
        {
            var point      = factory.CreatePoint(new Coordinate(1, 1));
            var linestring = factory.CreateLineString(new[] { new Coordinate(1, 1), new Coordinate(2, 2), new Coordinate(3, 3), });
            var shell      = factory.CreateLinearRing(new[] { new Coordinate(1, 1), new Coordinate(2, 2), new Coordinate(3, 3), new Coordinate(1, 1) });
            var polygon    = factory.CreatePolygon(shell);

            geometries           = new Geometry[] { point, linestring, polygon };
            serializedGeometries = //"\"geometries\":[{\"type\":\"Point\",\"coordinates\":[1.0,1.0]},{\"type\":\"LineString\",\"coordinates\":[[1.0,1.0],[2.0,2.0],[3.0,3.0]]},{\"type\":\"Polygon\",\"coordinates\":[[[1.0,1.0],[2.0,2.0],[3.0,3.0],[1.0,1.0]]]}]";
                                   "[{\"type\":\"Point\",\"coordinates\":[1.0,1.0]},{\"type\":\"LineString\",\"coordinates\":[[1.0,1.0],[2.0,2.0],[3.0,3.0]]},{\"type\":\"Polygon\",\"coordinates\":[[[1.0,1.0],[2.0,2.0],[3.0,3.0],[1.0,1.0]]]}]";

            collection           = factory.CreateGeometryCollection(geometries);
            serializedCollection = "{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[1.0,1.0]},{\"type\":\"LineString\",\"coordinates\":[[1.0,1.0],[2.0,2.0],[3.0,3.0]]},{\"type\":\"Polygon\",\"coordinates\":[[[1.0,1.0],[2.0,2.0],[3.0,3.0],[1.0,1.0]]]}]}";
        }
示例#26
0
        private GeometryCollection LoadData()
        {
            List <Geometry> data = null;

            try
            {
                data = readWKTFile(EmbeddedResourceManager.GetResourceStream("NetTopologySuite.Tests.NUnit.TestData.world.wkt"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }

            return(Factory.CreateGeometryCollection(data.ToArray()));
        }
示例#27
0
        public void TestCreateEmpty()
        {
            CheckEmpty(Factory.CreateEmpty(Dimension.Point), typeof(Point));
            CheckEmpty(Factory.CreateEmpty(Dimension.Curve), typeof(LineString));
            CheckEmpty(Factory.CreateEmpty(Dimension.Surface), typeof(Polygon));

            CheckEmpty(Factory.CreatePoint(), typeof(Point));
            CheckEmpty(Factory.CreateLineString(), typeof(LineString));
            CheckEmpty(Factory.CreatePolygon(), typeof(Polygon));

            CheckEmpty(Factory.CreateMultiPoint(), typeof(MultiPoint));
            CheckEmpty(Factory.CreateMultiLineString(), typeof(MultiLineString));
            CheckEmpty(Factory.CreateMultiPolygon(), typeof(MultiPolygon));
            CheckEmpty(Factory.CreateGeometryCollection(), typeof(GeometryCollection));
        }
示例#28
0
        /// <summary>
        /// Writes two geometries to an svg file
        /// </summary>
        /// <param name="filename">The path of the svg file.</param>
        /// <param name="a">The A geometry</param>
        /// <param name="b">The B geometry</param>
        public void DisplayTest(string filename, Geometry a, Geometry b)
        {
            Geotools.Geometries.PrecisionModel pm = new Geotools.Geometries.PrecisionModel(1, 0, 0);
            GeometryFactory    fact = new GeometryFactory(pm, 0);
            GeometrySVGWriter  svgWriter = new GeometrySVGWriter(fact.PrecisionModel);
            StreamWriter       sw = new StreamWriter(filename);
            GeometryCollection geomCollection = fact.CreateGeometryCollection(new Geometry[] { a, b });
            double             minx, miny, maxx, maxy;

            geomCollection.Extent2D(out minx, out miny, out maxx, out maxy);
            sw.WriteLine(String.Format("<svg viewBox=\"{0} {1} {2} {3}\">", minx, miny, maxx, maxy * 1.2));
            svgWriter.Write(a, sw, "fill-rule:evenodd;", "fill:blue;stroke:blue;stroke-width:1;fill-opacity:0.2");
            svgWriter.Write(b, sw, "fill-rule:evenodd;", "fill:red;stroke:red;stroke-width:1;fill-opacity:0.2");
            sw.WriteLine("</svg>");
            sw.Close();
        }
示例#29
0
        /// <summary>
        /// Creates a geometrycollection from the wkb.
        /// </summary>
        /// <returns>A geometry.</returns>
        private Geometry CreateWKBGeometryCollection()
        {
            //The next byte in the array tells the number of geometries in this collection.
            int numGeometries = (int)_bReader.ReadUInt32();

            //Create a new array for the geometries.
            Geometry[] geometries = new Geometry[numGeometries];

            //Loop on the number of geometries.
            for (int i = 0; i < numGeometries; i++)
            {
                //Call the main create function with the next geometry.
                geometries[i] = Create();
            }
            //Create and return the next geometry.
            return(_geometryFactory.CreateGeometryCollection(geometries));
        }
示例#30
0
        private static Geometry CreateWKBGeometryCollection(BinaryReader reader, WkbByteOrder byteOrder, GeometryFactory factory)
        {
            // The next byte in the array tells the number of geometries in this collection.
            var numGeometries = (int)ReadUInt32(reader, byteOrder);

            // Create a new array for the geometries.
            var geometries = new Geometry[numGeometries];

            // Loop on the number of geometries.
            for (var i = 0; i < numGeometries; i++)
            {
                // Call the main create function with the next geometry.
                geometries[i] = Parse(reader, factory);
            }

            // Create and return the next geometry.
            return(factory.CreateGeometryCollection(geometries));
        }