Exemplo n.º 1
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 IGeometry[] {}).Boundary;
         Assert.IsTrue(false);
     }
     catch (ArgumentException e)
     {
     }
 }
Exemplo n.º 2
0
        private void MergeFeatures(IFeature featureToMergeTo, IFeature feature)
        {
            if (featureToMergeTo.Attributes[FeatureAttributes.ID].Equals(feature.Attributes[FeatureAttributes.ID]))
            {
                return;
            }
            if (featureToMergeTo.Geometry is GeometryCollection geometryCollection)
            {
                if (feature.Geometry is GeometryCollection geometryCollectionSource)
                {
                    featureToMergeTo.Geometry = _geometryFactory.CreateGeometryCollection(geometryCollection.Geometries.Concat(geometryCollectionSource.Geometries).ToArray());
                }
                else
                {
                    featureToMergeTo.Geometry = _geometryFactory.CreateGeometryCollection(geometryCollection.Geometries.Concat(new[] { feature.Geometry }).ToArray());
                }
            }
            else
            {
                featureToMergeTo.Geometry = _geometryFactory.CreateGeometryCollection(new[] { featureToMergeTo.Geometry, feature.Geometry });
            }

            if (featureToMergeTo.Attributes[FeatureAttributes.POI_CATEGORY].Equals(Categories.NONE))
            {
                featureToMergeTo.Attributes[FeatureAttributes.POI_CATEGORY] =
                    feature.Attributes[FeatureAttributes.POI_CATEGORY];
            }

            if (double.Parse(featureToMergeTo.Attributes[FeatureAttributes.SEARCH_FACTOR].ToString()) <
                double.Parse(feature.Attributes[FeatureAttributes.SEARCH_FACTOR].ToString()))
            {
                featureToMergeTo.Attributes[FeatureAttributes.SEARCH_FACTOR] =
                    feature.Attributes[FeatureAttributes.SEARCH_FACTOR];
            }

            if (string.IsNullOrWhiteSpace(featureToMergeTo.Attributes[FeatureAttributes.ICON].ToString()))
            {
                featureToMergeTo.Attributes[FeatureAttributes.ICON] =
                    feature.Attributes[FeatureAttributes.ICON];
                featureToMergeTo.Attributes[FeatureAttributes.ICON_COLOR] =
                    feature.Attributes[FeatureAttributes.ICON_COLOR];
            }

            // adding names of merged feature
            featureToMergeTo.MergeTitles(feature);

            if (!featureToMergeTo.Attributes[FeatureAttributes.POI_SOURCE]
                .Equals(feature.Attributes[FeatureAttributes.POI_SOURCE]) ||
                !feature.Attributes[FeatureAttributes.POI_SOURCE].Equals(Sources.OSM))
            {
                // do not merge OSM elements to each other since they won't exists in the database for fetching
                featureToMergeTo.AddIdToCombinedPoi(feature);
            }
            featureToMergeTo.MergeCombinedPoiIds(feature);
        }
        /// <summary>
        /// Finalizes the result.
        /// </summary>
        protected override IGeometry FinalizeResult()
        {
            if (Source.VertexCount == 0)
            {
                return(null);
            }

            // if only points are in the graph
            if (_lines.Count == 0 && _polygons.Count == 0)
            {
                if (_points.Count == 1)
                {
                    return(_points.First());
                }

                return(_factory.CreateMultiPoint(_points));
            }
            // if no faces are extracted
            else if (_polygons.Count == 0)
            {
                if (_points.Count == 0)
                {
                    if (_lines.Count == 1)
                    {
                        return(_lines.First());
                    }

                    return(_factory.CreateMultiLineString(_lines));
                }

                return(_factory.CreateGeometryCollection(_points.Concat <IGeometry>(_lines)));
            }

            // if faces are extracted
            if (_points.Count == 0 && _lines.Count == 0)
            {
                if (_polygons.Count == 1)
                {
                    return(_polygons.First());
                }
                else
                {
                    return(_factory.CreateMultiPolygon(_polygons));
                }
            }
            else
            {
                return(_factory.CreateGeometryCollection(_points.Concat <IGeometry>(_lines).Concat <IGeometry>(_polygons)));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public IGeometry Buffer(IGeometry g, double distance)
        {
            PrecisionModel precisionModel = _workingPrecisionModel ?? new PrecisionModel(g.PrecisionModel);

            // factory must be the same as the one used by the input
            _geomFact = g.Factory;

            OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, _quadrantSegments);

            curveBuilder.EndCapStyle = _endCapStyle;
            OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);

            IList bufferSegStrList = curveSetBuilder.GetCurves();

            // short-circuit test
            if (bufferSegStrList.Count <= 0)
            {
                IGeometry emptyGeom = _geomFact.CreateGeometryCollection(new Geometry[0]);
                return(emptyGeom);
            }

            ComputeNodedEdges(bufferSegStrList, precisionModel);
            _graph = new PlanarGraph(new OverlayNodeFactory());
            _graph.AddEdges(_edgeList.Edges);

            IList          subgraphList = CreateSubgraphs(_graph);
            PolygonBuilder polyBuilder  = new PolygonBuilder(_geomFact);

            BuildSubgraphs(subgraphList, polyBuilder);
            IList resultPolyList = polyBuilder.Polygons;

            IGeometry resultGeom = _geomFact.BuildGeometry(resultPolyList);

            return(resultGeom);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the computed variable-width line buffer.
        /// </summary>
        /// <returns>A polygon</returns>
        public IGeometry GetResult()
        {
            Utilities.Assert.IsTrue(_line.NumPoints == _width.Length);

            var parts = new List <IGeometry>();

            var pts = _line.Coordinates;

            for (var i = 0; i < _line.NumPoints; i++)
            {
                var 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);
        }
        // see: https://github.com/NetTopologySuite/NetTopologySuite/issues/111
        public void issue_111_polygonhandler_with_invalid_values()
        {
            IGeometryFactory factory = GeometryFactory.Default;

            Coordinate[] points = new Coordinate[5];
            points[0] = new Coordinate(0, 0);
            points[1] = new Coordinate(1, 0);
            points[2] = new Coordinate(1, 1);
            points[3] = new Coordinate(0, 1);
            points[4] = new Coordinate(0, 0);
            IPolygon poly = factory.CreatePolygon(points);

            IMultiPolygon mpoly = factory.CreateMultiPolygon(new[] { poly });

            IGeometry[]         arr        = new[] { mpoly, GeometryCollection.Empty };
            IGeometryCollection geometries = factory.CreateGeometryCollection(arr);

            ShapeGeometryType shapeType = Shapefile.GetShapeType(geometries);

            Assert.AreEqual(ShapeGeometryType.PolygonZM, shapeType);

            string          tempPath = Path.GetTempFileName();
            ShapefileWriter sfw      = new ShapefileWriter(Path.GetFileNameWithoutExtension(tempPath), shapeType);

            sfw.Write(geometries);
        }
        /// <summary>
        /// Creates the result of the overlay operation.
        /// </summary>
        /// <param name="geometry">The geometry.</param>
        /// <param name="otherGeometry">The other geometry.</param>
        /// <param name="predicate">The overlay predicate.</param>
        /// <returns>The result of the overlay.</returns>
        private IGeometry CreateResult(IGeometry geometry, IGeometry otherGeometry, Func <IFace, Boolean> predicate)
        {
            // merge the geometries into a single graph
            HalfedgeGraph graph = new HalfedgeGraph(new HalfedgeGraph.FixedIdentifierProvider(1));

            graph.MergeGeometry(geometry);
            _aIdentifiers = new HashSet <Int32>(graph.Vertices.SelectMany(v => v.Identifiers));

            HalfedgeGraph otherGraph = new HalfedgeGraph(new HalfedgeGraph.FixedIdentifierProvider(2));

            otherGraph.MergeGeometry(otherGeometry);
            _bIdentifiers = new HashSet <Int32>(otherGraph.Vertices.SelectMany(v => v.Identifiers));

            graph.MergeGraph(otherGraph);

            // query the results
            IGeometryFactory factory = _geometryFactory ?? geometry.Factory;
            List <IPolygon>  result  = graph.Faces.Where(predicate).Select(face => face.ToGeometry(factory)).ToList();

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

            return(factory.CreateGeometryCollection(result));
        }
 public object ToGeometryCollection(object[] geometries)
 {
     if (geometries.Length == 0)
     {
         return(GeometryCollection.Empty);
     }
     return(_geometryFactory.CreateGeometryCollection(geometries.Cast <IGeometry>().ToArray()));
 }
        /// <summary>
        /// Reads a <see cref="IGeometryCollection"/> 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 IGeometryCollection ReadGeometryCollection(BinaryReader reader, IGeometryFactory factory)
        {
            int numGeometries = reader.ReadInt32();
            var geometries    = new IGeometry[numGeometries];

            ReadGeometryArray(reader, geometries);
            return(factory.CreateGeometryCollection(geometries));
        }
Exemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geom"></param>
        public static void UnionUsingBufferOp(IGeometry[] geom)
        {
            IGeometryFactory fact     = geom[0].Factory;
            IGeometry        geomColl = fact.CreateGeometryCollection(geom);
            IGeometry        union    = geomColl.Buffer(0.0);

            Console.WriteLine(union);
        }
Exemplo n.º 11
0
        private IGeometry BufferUnion(IGeometry g0, IGeometry g1)
        {
            IGeometryFactory factory  = g0.Factory;
            IGeometry        gColl    = factory.CreateGeometryCollection(new IGeometry[] { g0, g1 });
            IGeometry        unionAll = gColl.Buffer(0.0);

            return(unionAll);
        }
Exemplo n.º 12
0
        ///<summary>
        /// Gets the union of the input geometries.
        /// If no input geometries were provided, a POINT EMPTY is returned.
        ///</summary>
        ///<returns>a Geometry containing the union</returns>
        /// <returns>an empty GEOMETRYCOLLECTION if no geometries were provided in the input</returns>
        public IGeometry Union()
        {
            if (_geomFact == null)
            {
                return(null);
            }

            IGeometry unionPoints = null;

            if (_points.Count > 0)
            {
                IGeometry ptGeom =
                    _geomFact.BuildGeometry(convertPoints(_points).ToList());
                unionPoints = UnionNoOpt(ptGeom);
            }

            IGeometry unionLines = null;

            if (_lines.Count > 0)
            {
                IGeometry lineGeom = _geomFact.BuildGeometry(convertLineStrings(_lines).ToList());
                unionLines = UnionNoOpt(lineGeom);
            }

            IGeometry unionPolygons = null;

            if (_polygons.Count > 0)
            {
                unionPolygons = CascadedPolygonUnion.Union(_polygons);
            }

            /**
             * Performing two unions is somewhat inefficient,
             * but is mitigated by unioning lines and points first
             */
            IGeometry unionLA = UnionWithNull(unionLines, unionPolygons);
            IGeometry union   = null;

            if (unionPoints == null)
            {
                union = unionLA;
            }
            else if (unionLA == null)
            {
                union = unionPoints;
            }
            else
            {
                union = PointGeometryUnion.Union((IPoint)unionPoints, unionLA);
            }

            if (union == null)
            {
                return(_geomFact.CreateGeometryCollection(null));
            }

            return(union);
        }
Exemplo n.º 13
0
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
        {
            reader.Read();
            if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "type"))
            {
                throw new ArgumentException("invalid tokentype: " + reader.TokenType);
            }
            reader.Read();
            if (reader.TokenType != JsonToken.String)
            {
                throw new ArgumentException("invalid tokentype: " + reader.TokenType);
            }
            GeoJsonObjectType geometryType = (GeoJsonObjectType)Enum.Parse(typeof(GeoJsonObjectType), (string)reader.Value);

            switch (geometryType)
            {
            case GeoJsonObjectType.Point:
                Coordinate coordinate = _geoJsonSerializer.Deserialize <Coordinate>(reader);
                return(_factory.CreatePoint(coordinate));

            case GeoJsonObjectType.LineString:
                Coordinate[] coordinates = _geoJsonSerializer.Deserialize <Coordinate[]>(reader);
                return(_factory.CreateLineString(coordinates));

            case GeoJsonObjectType.Polygon:
                List <Coordinate[]> coordinatess = _geoJsonSerializer.Deserialize <List <Coordinate[]> >(reader);
                return(CreatePolygon(coordinatess));

            case GeoJsonObjectType.MultiPoint:
                coordinates = _geoJsonSerializer.Deserialize <Coordinate[]>(reader);
                return(_factory.CreateMultiPoint(coordinates));

            case GeoJsonObjectType.MultiLineString:
                coordinatess = _geoJsonSerializer.Deserialize <List <Coordinate[]> >(reader);
                List <ILineString> strings = new List <ILineString>();
                for (int i = 0; i < coordinatess.Count; i++)
                {
                    strings.Add(_factory.CreateLineString(coordinatess[i]));
                }
                return(_factory.CreateMultiLineString(strings.ToArray()));

            case GeoJsonObjectType.MultiPolygon:
                List <List <Coordinate[]> > coordinatesss = _geoJsonSerializer.Deserialize <List <List <Coordinate[]> > >(reader);
                List <IPolygon>             polygons      = new List <IPolygon>();
                foreach (List <Coordinate[]> coordinateses in coordinatesss)
                {
                    polygons.Add(CreatePolygon(coordinateses));
                }
                return(_factory.CreateMultiPolygon(polygons.ToArray()));

            case GeoJsonObjectType.GeometryCollection:
                List <IGeometry> geoms = _geoJsonSerializer.Deserialize <List <IGeometry> >(reader);
                return(_factory.CreateGeometryCollection(geoms.ToArray()));
            }
            return(null);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Converts the geometry from Geography Markup Language (GML) representation.
        /// </summary>
        /// <param name="source">The source collection of XML elements.</param>
        /// <param name="geometryFactory">The geometry factory.</param>
        /// <param name="referenceSystemFactory">The reference system factory.</param>
        /// <returns>The converted geometry.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// The source is null.
        /// or
        /// The geometry factory is null.
        /// or
        /// The reference system factory is null.
        /// </exception>
        /// <exception cref="System.ArgumentException">The specified source is invalid.</exception>
        public static IGeometry ToGeometry(this IEnumerable <XElement> source, IGeometryFactory geometryFactory, IReferenceSystemFactory referenceSystemFactory)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException(nameof(geometryFactory));
            }
            if (referenceSystemFactory == null)
            {
                throw new ArgumentNullException(nameof(referenceSystemFactory));
            }

            try
            {
                List <IGeometry> geometries = new List <IGeometry>();

                foreach (XElement element in source)
                {
                    geometries.Add(ToGeometry(element, geometryFactory, referenceSystemFactory));
                }

                if (geometries.Count == 0)
                {
                    return(null);
                }

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

                if (geometries.All(geometry => geometry is IPoint))
                {
                    return(geometryFactory.CreateMultiPoint(geometries.Cast <IPoint>()));
                }

                if (geometries.All(geometry => geometry is ILineString))
                {
                    return(geometryFactory.CreateMultiLineString(geometries.Cast <ILineString>()));
                }

                if (geometries.All(geometry => geometry is IPolygon))
                {
                    return(geometryFactory.CreateMultiPolygon(geometries.Cast <IPolygon>()));
                }

                return(geometryFactory.CreateGeometryCollection(geometries));
            }
            catch (Exception ex)
            {
                throw new ArgumentException(CoreMessages.SourceIsInvalid, nameof(source), ex);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Transforms a <see cref="GeoAPI.Geometries.IGeometryCollection"/>.
        /// </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 IGeometryCollection TransformGeometryCollection(IGeometryCollection geoms, IMathTransform transform, IGeometryFactory targetFactory)
        {
            var geomList = new IGeometry[geoms.NumGeometries];

            for (var i = 0; i < geoms.NumGeometries; i++)
            {
                geomList[i] = TransformGeometry(geoms[i], transform, targetFactory);
            }
            return(targetFactory.CreateGeometryCollection(geomList));
        }
Exemplo n.º 16
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 IGeometryCollection ReadGeometryCollectionText(WktStreamTokenizer tokenizer, IGeometryFactory factory)
        {
            var nextToken = GetNextEmptyOrOpener(tokenizer);

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

            geometries.Add(ReadGeometryTaggedText(tokenizer));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken.Equals(","))
            {
                geometries.Add(ReadGeometryTaggedText(tokenizer));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return(factory.CreateGeometryCollection(geometries.ToArray()));
        }
Exemplo n.º 17
0
        private IGeometry ReadGeometryCollection(int dim, int lrsDim, SdoGeometry sdoGeom)
        {
            List <IGeometry> geometries = new List <IGeometry>();

            foreach (SdoGeometry elemGeom in sdoGeom.getElementGeometries())
            {
                geometries.Add(ReadGeometry(elemGeom));
            }
            return(factory.CreateGeometryCollection(geometries.ToArray()));
        }
Exemplo n.º 18
0
        /**
         * Reads one or more WKT geometries from a string.
         * 
         * @param wkt
         * @param geomFact
         * @return
         * @throws ParseException
         * @throws IOException
         */

        public static IGeometry ReadGeometriesFromWktString(String wkt, IGeometryFactory geomFact)
        {
            var reader = new WKTReader(geomFact);
            WKTFileReader fileReader = new WKTFileReader(new StringReader(wkt), reader);
            var geomList = fileReader.Read();

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

            return geomFact.CreateGeometryCollection(GeometryFactory.ToGeometryArray(geomList));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Transforms a <see cref="GeoAPI.Geometries.IGeometryCollection"/>.
        /// </summary>
        /// <param name="geoms">GeometryCollection to transform</param>
        /// <param name="from">Source Projection</param>
        /// <param name="to">Target Projection</param>
        /// <param name="toFactory">The factory to create geometries for <paramref name="to"/></param>
        /// <returns>Transformed GeometryCollection</returns>
        public static IGeometryCollection TransformGeometryCollection(IGeometryCollection geoms, ProjectionInfo from, ProjectionInfo to, IGeometryFactory toFactory)
        {
            var gOut = new IGeometry[geoms.Count];

            for (var i = 0; i < geoms.Count; i++)
            {
                gOut[i] = TransformGeometry(geoms.GetGeometryN(i), from, to, toFactory);
            }

            return(toFactory.CreateGeometryCollection(gOut));
        }
Exemplo n.º 20
0
        internal static NTSGeometryCollection ToNTSGeometryCollection(Geometries.GeometryCollection geom,
                                                                      IGeometryFactory factory)
        {
            NTSGeometry[] geometries = new NTSGeometry[geom.Collection.Count];
            int           index      = 0;

            foreach (Geometries.Geometry geometry in geom.Collection)
            {
                geometries[index++] = ToNTSGeometry(geometry, factory);
            }
            return(factory.CreateGeometryCollection(geometries) as NTSGeometryCollection);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Transforms a <see cref="GeometryCollection" /> object.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="geoms"></param>
        /// <param name="transform"></param>
        /// <returns></returns>
        public static IGeometryCollection TransformGeometryCollection(IGeometryFactory factory,
                                                                      GeometryCollection geoms, IMathTransform transform)
        {
            List <IGeometry> coll = new List <IGeometry>(geoms.Geometries.Length);

            foreach (IGeometry g in geoms.Geometries)
            {
                IGeometry item = TransformGeometry(factory, g, transform);
                coll.Add(item);
            }
            return(factory.CreateGeometryCollection(coll.ToArray()));
        }
Exemplo n.º 22
0
        /// <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>
        /// <param name="factory"> </param>
        /// <returns>
        /// A <c>GeometryCollection</c> specified by the
        /// next token in the stream.</returns>
        private IGeometryCollection ReadGeometryCollectionText(IEnumerator <Token> tokens, IGeometryFactory factory)
        {
            string nextToken = GetNextEmptyOrOpener(tokens);

            if (nextToken.Equals("EMPTY"))
            {
                return(factory.CreateGeometryCollection());
            }

            var geometries = new List <IGeometry>();
            var geometry   = ReadGeometryTaggedText(tokens);

            geometries.Add(geometry);
            nextToken = GetNextCloserOrComma(tokens);
            while (nextToken.Equals(","))
            {
                geometry = ReadGeometryTaggedText(tokens);
                geometries.Add(geometry);
                nextToken = GetNextCloserOrComma(tokens);
            }
            return(factory.CreateGeometryCollection(geometries.ToArray()));
        }
        private IGeometry ReadGeometryCollection(int dim, int lrsDim, SdoGeometry sdoGeom)
        {
            List <IGeometry> geometries = new List <IGeometry>();

            //foreach (SdoGeometry elemGeom in sdoGeom.getElementGeometries())
            //{
            //    geometries.Add(ReadGeometry(elemGeom));
            //}
            // TODO : Check if this will work SdoGeometry does not
            // have a getElementgeometries method anymore
            geometries.Add(ReadGeometry(sdoGeom));
            return(factory.CreateGeometryCollection(geometries.ToArray()));
        }
Exemplo n.º 24
0
        /**
         * Reads one or more WKT geometries from a string.
         *
         * @param wkt
         * @param geomFact
         * @return
         * @throws ParseException
         * @throws IOException
         */

        public static IGeometry ReadGeometriesFromWktString(string wkt, IGeometryFactory 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)));
        }
Exemplo n.º 25
0
        /// <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 IGeometryCollection ReadGeometryCollectionText(IList tokens)
        {
            string nextToken = GetNextEmptyOrOpener(tokens);

            if (nextToken.Equals("EMPTY"))
            {
                return(geometryFactory.CreateGeometryCollection(new IGeometry[] { }));
            }

            List <IGeometry> geometries = new List <IGeometry>();
            IGeometry        geometry   = ReadGeometryTaggedText(tokens);

            geometries.Add(geometry);
            nextToken = GetNextCloserOrComma(tokens);
            while (nextToken.Equals(","))
            {
                geometry = ReadGeometryTaggedText(tokens);
                geometries.Add(geometry);
                nextToken = GetNextCloserOrComma(tokens);
            }
            return(geometryFactory.CreateGeometryCollection(geometries.ToArray()));
        }
Exemplo n.º 26
0
        public void SetUp()
        {
            IPoint      point      = factory.CreatePoint(new Coordinate(1, 1));
            ILineString linestring = factory.CreateLineString(new[] { new Coordinate(1, 1), new Coordinate(2, 2), new Coordinate(3, 3), });
            ILinearRing shell      = factory.CreateLinearRing(new[] { new Coordinate(1, 1), new Coordinate(2, 2), new Coordinate(3, 3), new Coordinate(1, 1) });
            IPolygon    polygon    = factory.CreatePolygon(shell);

            geometries           = new IGeometry[] { 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]]]}]";

            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]]]}]}";
        }
Exemplo n.º 27
0
 /// <summary>
 /// Gets a geometry representing the polygons formed by the polygonization.
 /// If a valid polygonal geometry was extracted the result is a <see cref="IPolygonal"/> geometry.
 /// </summary>
 /// <returns>A geometry containing the polygons</returns>
 public IGeometry GetGeometry()
 {
     if (_geomFactory == null)
     {
         _geomFactory = new Geometries.GeometryFactory();
     }
     Polygonize();
     if (_extractOnlyPolygonal)
     {
         return(_geomFactory.BuildGeometry(_polyList));
     }
     // result may not be valid Polygonal, so return as a GeometryCollection
     return(_geomFactory.CreateGeometryCollection(Geometries.GeometryFactory.ToGeometryArray(_polyList)));
 }
Exemplo n.º 28
0
        /// <summary>
        /// Gets the geometry for the triangles in a triangulated subdivision as a <see cref="IGeometryCollection"/>
        /// of triangular <see cref="IPolygon"/>s.
        /// </summary>
        /// <param name="geomFact">the GeometryFactory to use</param>
        /// <returns>a GeometryCollection of triangular Polygons</returns>
        public IGeometryCollection GetTriangles(IGeometryFactory geomFact)
        {
            var triPtsList = GetTriangleCoordinates(false);

            IPolygon[] tris = new Polygon[triPtsList.Count];
            int        i    = 0;

            foreach (var triPt in triPtsList)
            {
                tris[i++] = geomFact
                            .CreatePolygon(geomFact.CreateLinearRing(triPt), null);
            }
            return(geomFact.CreateGeometryCollection(tris));
        }
Exemplo n.º 29
0
        ///<summary>
        /// Computes the combination of the input geometries to produce the most appropriate <see cref="IGeometry"/> or <see cref="IGeometryCollection"/>
        ///</summary>
        /// <returns>A Geometry which is the combination of the inputs</returns>
        /// <returns></returns>
        public IGeometry Combine()
        {
            var elems = new List <IGeometry>();

            foreach (var geom in _inputGeoms)
            {
                ExtractElements(geom, elems);
            }

            if (elems.Count == 0)
            {
                return(_geomFactory != null?_geomFactory.CreateGeometryCollection() : null);
            }
            return(_geomFactory.BuildGeometry(elems));
        }
        private static IGeometryCollection ParseWkbGeometryCollection(byte[] blob, ref int offset, IGeometryFactory factory, GaiaImport gaiaImport)
        {
            var number     = gaiaImport.GetInt32(blob, ref offset);
            var geometries = new IGeometry[number];

            for (var i = 0; i < number; i++)
            {
                if (blob[offset++] != (byte)GaiaGeoBlobMark.GAIA_MARK_ENTITY)
                {
                    throw new Exception();
                }

                geometries[i] = ParseWkbGeometry((GaiaGeoGeometry)gaiaImport.GetInt32(blob, ref offset), blob, ref offset, factory, gaiaImport);
            }
            return(factory.CreateGeometryCollection(geometries));
        }
        // see: https://github.com/NetTopologySuite/NetTopologySuite/issues/111
        public void issue_111_pointhandler_with_invalid_values()
        {
            IGeometryFactory factory = GeometryFactory.Default;

            IPoint p = factory.CreatePoint(new Coordinate(0, 0));

            IGeometry[]         arr        = { p, GeometryCollection.Empty };
            IGeometryCollection geometries = factory.CreateGeometryCollection(arr);

            ShapeGeometryType shapeType = Shapefile.GetShapeType(geometries);

            Assert.AreEqual(ShapeGeometryType.PointZM, shapeType);

            string          tempPath = Path.GetTempFileName();
            ShapefileWriter sfw      = new ShapefileWriter(Path.GetFileNameWithoutExtension(tempPath), shapeType);

            sfw.Write(geometries);
        }
Exemplo n.º 32
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        /// <param name="distance"></param>
        /// <returns></returns>
        public IGeometry Buffer(IGeometry g, double distance)
        {
            IPrecisionModel precisionModel = workingPrecisionModel;
            if (precisionModel == null)
                precisionModel = g.PrecisionModel;

            // factory must be the same as the one used by the input
            geomFact = g.Factory;

            OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, quadrantSegments);
            curveBuilder.EndCapStyle = endCapStyle;
            OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);

            IList bufferSegStrList = curveSetBuilder.GetCurves();

            // short-circuit test
            if (bufferSegStrList.Count <= 0)
            {
                IGeometry emptyGeom = geomFact.CreateGeometryCollection(new IGeometry[0]);
                return emptyGeom;
            }

            ComputeNodedEdges(bufferSegStrList, precisionModel);
            graph = new PlanarGraph(new OverlayNodeFactory());
            graph.AddEdges(edgeList.Edges);

            IList subgraphList = CreateSubgraphs(graph);
            PolygonBuilder polyBuilder = new PolygonBuilder(geomFact);
            BuildSubgraphs(subgraphList, polyBuilder);
            IList resultPolyList = polyBuilder.Polygons;

            IGeometry resultGeom = geomFact.BuildGeometry(resultPolyList);
            return resultGeom;
        }
        /// <summary>
        /// Transforms a <see cref="GeoAPI.Geometries.IGeometryCollection"/>.
        /// </summary>
        /// <param name="geoms">GeometryCollection to transform</param>
        /// <param name="from">Source Projection</param>
        /// <param name="to">Target Projection</param>
        /// <param name="toFactory">The factory to create geometries for <paramref name="to"/></param>
        /// <returns>Transformed GeometryCollection</returns>
        public static IGeometryCollection TransformGeometryCollection(IGeometryCollection geoms, ProjectionInfo from, ProjectionInfo to, IGeometryFactory toFactory)
        {
            var gOut = new IGeometry[geoms.Count];
            for (var i = 0; i < geoms.Count; i++)
                gOut[i] = TransformGeometry(geoms.GetGeometryN(i), from, to, toFactory);

            return toFactory.CreateGeometryCollection(gOut);
        }
 /// <summary>
 /// Gets the geometry for the triangles in a triangulated subdivision as a <see cref="IGeometryCollection"/>
 /// of triangular <see cref="IPolygon"/>s.
 /// </summary>
 /// <param name="geomFact">the GeometryFactory to use</param>
 /// <returns>a GeometryCollection of triangular Polygons</returns>
 public IGeometryCollection GetTriangles(IGeometryFactory geomFact)
 {
     var triPtsList = GetTriangleCoordinates(false);
     IPolygon[] tris = new Polygon[triPtsList.Count];
     int i = 0;
     foreach (var triPt in triPtsList)
     {
         tris[i++] = geomFact
                     .CreatePolygon(geomFact.CreateLinearRing(triPt), null);
     }
     return geomFact.CreateGeometryCollection(tris);
 }
Exemplo n.º 35
0
 /// <summary>
 /// Transforms a <see cref="GeoAPI.Geometries.IGeometryCollection"/>.
 /// </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 IGeometryCollection TransformGeometryCollection(IGeometryCollection geoms, IMathTransform transform, IGeometryFactory targetFactory)
 {
     var geomList = new IGeometry[geoms.NumGeometries];
     for(var i = 0; i < geoms.NumGeometries; i++)
     {
         geomList[i] = TransformGeometry(geoms[i], transform, targetFactory);
     }
     return targetFactory.CreateGeometryCollection(geomList);
 }
Exemplo n.º 36
0
        public static IGeometry ReadGeometriesFromWkbHexString(String wkb, IGeometryFactory geomFact)
        {
            var reader = new WKBReader(geomFact);
            var fileReader = new WKBHexFileReader(reader);
            var geomList = new List<IGeometry>();
            using (var ms = new MemoryStream())
            {
                new StreamWriter(ms).Write(wkb);
                geomList.AddRange(fileReader.Read(ms));
            }

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

            return geomFact.CreateGeometryCollection(GeometryFactory.ToGeometryArray(geomList));
        }
Exemplo n.º 37
0
 /// <summary>
 /// Creates an empty result geometry of the appropriate dimension,
 /// based on the given overlay operation and the dimensions of the inputs.
 /// The created geometry is always an atomic geometry, 
 /// not a collection.
 /// <para/>
 /// The empty result is constructed using the following rules:
 /// <list type="Bullet">
 /// <item><see cref="SpatialFunction.Intersection"/> - result has the dimension of the lowest input dimension</item>
 /// <item><see cref="SpatialFunction.Union"/> - result has the dimension of the highest input dimension</item>
 /// <item><see cref="SpatialFunction.Difference"/> - result has the dimension of the left-hand input</item>
 /// <item><see cref="SpatialFunction.SymDifference"/> - result has the dimension of the highest input dimension
 /// (since symDifference is the union of the differences).</item>
 /// </list>
 /// </summary>
 /// <param name="overlayOpCode">The overlay operation being performed</param>
 /// <param name="a">An input geometry</param>
 /// <param name="b">An input geometry</param>
 /// <param name="geomFact">The geometry factory being used for the operation</param>
 /// <returns>An empty atomic geometry of the appropriate dimension</returns>
 public static IGeometry CreateEmptyResult(SpatialFunction overlayOpCode, IGeometry a, IGeometry b, IGeometryFactory geomFact)
 {
     IGeometry result = null;
     switch (ResultDimension(overlayOpCode, a, b))
     {
         case Dimension.False:
             result = geomFact.CreateGeometryCollection(new IGeometry[0]);
             break;
         case Dimension.Point:
             result = geomFact.CreatePoint((Coordinate)null);
             break;
         case Dimension.Curve:
             result = geomFact.CreateLineString((Coordinate[])null);
             break;
         case Dimension.Surface:
             result = geomFact.CreatePolygon(null, null);
             break;
     }
     return result;
 }
Exemplo n.º 38
0
 internal static NTSGeometryCollection ToNTSGeometryCollection(Geometries.GeometryCollection geom,
     IGeometryFactory factory)
 {
     NTSGeometry[] geometries = new NTSGeometry[geom.Collection.Count];
     int index = 0;
     foreach (Geometries.Geometry geometry in geom.Collection)
         geometries[index++] = ToNTSGeometry(geometry, factory);
     return factory.CreateGeometryCollection(geometries) as NTSGeometryCollection;
 }
Exemplo n.º 39
0
        private static IGeometry CreateWKBGeometryCollection(BinaryReader reader, WkbByteOrder byteOrder, IGeometryFactory 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 IGeometry[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);
        }
Exemplo n.º 40
0
		/// <summary>
		/// Transforms a <see cref="GeometryCollection" /> object.
		/// </summary>
		/// <param name="factory"></param>
		/// <param name="geoms"></param>
		/// <param name="transform"></param>
		/// <returns></returns>
        public static IGeometryCollection TransformGeometryCollection(IGeometryFactory factory, 
            GeometryCollection geoms, IMathTransform transform)
		{
			List<IGeometry> coll = new List<IGeometry>(geoms.Geometries.Length);
			foreach (IGeometry g in geoms.Geometries)
			{
			    IGeometry item = TransformGeometry(factory, g, transform);
			    coll.Add(item);
			}
		    return factory.CreateGeometryCollection(coll.ToArray());
		}
Exemplo n.º 41
0
        private static IGeometryCollection ParseWkbGeometryCollection(byte[] blob, ref int offset, IGeometryFactory factory, GaiaImport gaiaImport)
        {
            var number = gaiaImport.GetInt32(blob, ref offset);
            var geometries = new IGeometry[number];
            for (var i = 0; i < number; i++)
            {
                if (blob[offset++] != (byte)GaiaGeoBlobMark.GAIA_MARK_ENTITY)
                    throw new Exception();

                geometries[i] = ParseWkbGeometry((GaiaGeoGeometry)gaiaImport.GetInt32(blob, ref offset), blob, ref offset, factory, gaiaImport);
            }
            return factory.CreateGeometryCollection(geometries);
        }
Exemplo n.º 42
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 IGeometryCollection ReadGeometryCollectionText(WktStreamTokenizer tokenizer, IGeometryFactory factory)
 {
     var nextToken = GetNextEmptyOrOpener(tokenizer);
     if (nextToken.Equals("EMPTY"))
         return factory.CreateGeometryCollection(null);
     var geometries = new List<IGeometry>();
     geometries.Add(ReadGeometryTaggedText(tokenizer));
     nextToken = GetNextCloserOrComma(tokenizer);
     while (nextToken.Equals(","))
     {
         geometries.Add(ReadGeometryTaggedText(tokenizer));
         nextToken = GetNextCloserOrComma(tokenizer);
     }
     return factory.CreateGeometryCollection(geometries.ToArray());
 }
Exemplo n.º 43
0
        /// <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>
        /// <param name="factory"> </param>
        /// <returns>
        /// A <c>GeometryCollection</c> specified by the
        /// next token in the stream.</returns>
        private IGeometryCollection ReadGeometryCollectionText(IEnumerator<Token> tokens, IGeometryFactory factory)
        {
            string nextToken = GetNextEmptyOrOpener(tokens);
            if (nextToken.Equals("EMPTY"))
                return factory.CreateGeometryCollection(new IGeometry[] { } );

            var geometries = new List<IGeometry>();
            var geometry = ReadGeometryTaggedText(tokens);
            geometries.Add(geometry);
            nextToken = GetNextCloserOrComma(tokens);
            while (nextToken.Equals(","))
            {
                geometry = ReadGeometryTaggedText(tokens);
                geometries.Add(geometry);
                nextToken = GetNextCloserOrComma(tokens);
            }
            return factory.CreateGeometryCollection(geometries.ToArray());
        }
 /// <summary>
 /// Gets the cells in the Voronoi diagram for this triangulation.
 /// The cells are returned as a <see cref="IGeometryCollection" /> of <see cref="IPolygon"/>s
 /// </summary>
 /// <remarks>
 /// The userData of each polygon is set to be the <see cref="Coordinate" />
 /// of the cell site.  This allows easily associating external
 /// data associated with the sites to the cells.
 /// </remarks>
 /// <param name="geomFact">a geometry factory</param>
 /// <returns>a GeometryCollection of Polygons</returns>
 public IGeometryCollection GetVoronoiDiagram(IGeometryFactory geomFact)
 {
     var vorCells = GetVoronoiCellPolygons(geomFact);
     return geomFact.CreateGeometryCollection(GeometryFactory.ToGeometryArray(vorCells));
 }