Beispiel #1
0
 public void Multils()
 {
     var rnd = new Random();
     var ls = new LineString[40];
     var lscheck = new GeoAPI.Geometries.ILineString[40];
     var gf = new NetTopologySuite.Geometries.GeometryFactory();
     for (var ii = 0; ii < 40; ii++)
     {
         var coord = new Coordinate[36];
         var coordcheck = new GeoAPI.Geometries.Coordinate[36];
         for (var i = 0; i < 36; i++)
         {
             coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
             var x = coord[i].X;
             var y = coord[i].Y;
             var c = new GeoAPI.Geometries.Coordinate(x, y);
             coordcheck[i] = c;
         }
         ls[ii] = new LineString(coord);
         lscheck[ii] = gf.CreateLineString(coordcheck);
     }
     var mls = new MultiLineString(ls);
     var mlscheck = gf.CreateMultiLineString(lscheck);
     for (var ii = 0; ii < mls.Coordinates.Count; ii++)
     {
         Assert.AreEqual(mls.Coordinates[ii].X, mlscheck.Coordinates[ii].X);
         Assert.AreEqual(mls.Coordinates[ii].Y, mlscheck.Coordinates[ii].Y);
     }
     Assert.AreEqual(mls.NumGeometries, mlscheck.NumGeometries);
 }
Beispiel #2
0
        private void WriteMultiLineString(MultiLineString multiLineString)
        {
            wkbWriter.Write(multiLineString.LineStrings.Count);

            foreach (LineString lineString in multiLineString.LineStrings)
                WriteInternal(lineString, multiLineString);
        }
Beispiel #3
0
 public void MultiLineString()
 {
     var reader = new GeoJsonReader();
     var geo = new MultiLineString(new LineString(new Coordinate(0, 0), new Coordinate(1, 1)));
     Assert.AreEqual(@"{""type"":""MultiLineString"",""coordinates"":[[[0,0],[1,1]]]}",
         geo.ToGeoJson());
     Assert.AreEqual(geo, reader.Read(geo.ToGeoJson()));
 }
Beispiel #4
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;
        }
Beispiel #5
0
        private void AppendMultiLineString(StringBuilder builder, MultiLineString multiLineString)
        {
            builder.Append("MULTILINESTRING");
            if (multiLineString.IsEmpty)
            {
                builder.Append(" EMPTY");
                return;
            }

            AppendDimensions(builder, multiLineString);
            builder.Append(" (");
            for (var i = 0; i < multiLineString.Geometries.Count; i++)
            {
                if (i > 0)
                    builder.Append(", ");
                AppendLineStringInner(builder, ((LineString)multiLineString.Geometries[i]).Coordinates);
            }
            builder.Append(")");
        }
Beispiel #6
0
        /// <summary>
        /// Converts a MultiLineString to &lt;MultiLineString Text&gt;
        /// format, then Appends it to the writer.
        /// </summary>
        /// <param name="multiLineString">The MultiLineString to process.</param>
        /// <param name="level"></param>
        /// <param name="indentFirst"></param>
        /// <param name="writer">The output stream writer to Append to.</param>
        protected void AppendMultiLineStringText(MultiLineString multiLineString, int level, bool indentFirst, StringWriter writer)
        {
            if ( multiLineString.isEmpty() )
            {
                writer.Write("EMPTY");
            }
            else
            {
                int level2 = level;
                bool doIndent = indentFirst;
                writer.Write("(");

                for (int i = 0; i < multiLineString.getNumGeometries(); i++)
                {
                    if (i > 0)
                    {
                        writer.Write(", ");
                        level2 = level + 1;
                        doIndent = true;
                    }

                    AppendLineStringText((LineString) multiLineString.getGeometryN(i), level2, doIndent, writer);
                }

                writer.Write(")");
            }
        }
Beispiel #7
0
        protected MultiLineString ReadMultiLineString(Dimension dimension)
        {
            MultiLineString multiLineString = new MultiLineString();
            multiLineString.Dimension = dimension;

            ExpectGroupStart();

            do
            {
                multiLineString.LineStrings.Add(ReadLineString(dimension));
            } while (IsMatch(","));

            ExpectGroupEnd();

            return multiLineString;
        }
Beispiel #8
0
        /// <summary>
        /// Generates GeoJson for the given geometry collection.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="geometryCollection"></param>
        internal static void Write(JsonWriter writer, MultiLineString geometryCollection)
        {
            if (writer == null) { throw new ArgumentNullException("writer"); }
            if (geometryCollection == null) { throw new ArgumentNullException("geometryCollection"); }

            writer.WriteStartObject();
            writer.WritePropertyName("type");
            writer.WriteValue("MultiLineString");
            writer.WritePropertyName("coordinates");
            writer.WriteStartArray();
            foreach (var geometry in geometryCollection)
            {
                writer.WriteStartArray();
                foreach (var coordinate in geometry.Coordinates)
                {
                    writer.WriteStartArray();
                    writer.WriteValue(coordinate.Longitude);
                    writer.WriteValue(coordinate.Latitude);
                    writer.WriteEndArray();
                }
                writer.WriteEndArray();
            }
            writer.WriteEndArray();
            writer.WriteEndObject();
        }
Beispiel #9
0
 /// <summary>
 ///     Converts a MultiLineString to &lt;MultiLineString Tagged
 ///     Text&gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiLineString">The MultiLineString to process</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 private static void AppendMultiLineStringTaggedText(MultiLineString multiLineString, StringWriter writer)
 {
     writer.Write("MULTILINESTRING ");
     AppendMultiLineStringText(multiLineString, writer);
 }
Beispiel #10
0
        public void Test()
        {
            var route      = new Route();
            var collection = new FeatureCollection();
            var multi      = route.Coordinates.Split("###").ToList();
            var lines      = new List <GeoJSON.Net.Geometry.LineString>();

            multi.ForEach(block =>
            {
                var coordinates = block.Split('\n').Where(a => !string.IsNullOrWhiteSpace(a)).ToList();
                var coords      = coordinates.Select(r => new Position(double.Parse(r.Split(',')[1], CultureInfo.InvariantCulture), double.Parse(r.Split(',')[0], CultureInfo.InvariantCulture))).ToList();
                if (coords.Count >= 2)
                {
                    var geo = new GeoJSON.Net.Geometry.LineString(coords);
                    lines.Add(geo);
                }
            });
            GeoJSON.Net.Feature.Feature feature;
            if (lines.Count == 1)
            {
                feature = new GeoJSON.Net.Feature.Feature(lines.Single());
            }
            else
            {
                var multiLineString = new MultiLineString(lines);
                feature = new GeoJSON.Net.Feature.Feature(multiLineString);
            }
            if (!string.IsNullOrWhiteSpace(route.Name))
            {
                feature.Properties.Add("name", route.Name);
            }
            if (!string.IsNullOrWhiteSpace(route.NameNL))
            {
                feature.Properties.Add("nameNL", route.NameNL);
            }
            if (!string.IsNullOrWhiteSpace(route.Description))
            {
                feature.Properties.Add("description", route.Description);
            }
            if (!string.IsNullOrWhiteSpace(route.DescriptionNL))
            {
                feature.Properties.Add("descriptionNL", route.DescriptionNL);
            }
            if (route.FirstDateTime.HasValue)
            {
                feature.Properties.Add("firstDateTime", route.FirstDateTime.Value.ToString("o"));
            }
            if (!string.IsNullOrWhiteSpace(route.LineNumber))
            {
                feature.Properties.Add("lineNumber", route.LineNumber);
            }
            if (!string.IsNullOrWhiteSpace(route.OperatingCompany))
            {
                feature.Properties.Add("operatingCompany", route.OperatingCompany);
            }
            if (!string.IsNullOrWhiteSpace(route.OverrideColour))
            {
                feature.Properties.Add("name", route.OverrideColour);
            }
            if (route.RouteCountries.Any())
            {
                feature.Properties.Add("countries", string.Join(',', route.RouteCountries.Select(c => c.Country.Name)));
            }
            if (route.RouteMaps.Any())
            {
                feature.Properties.Add("maps", string.Join(',', route.RouteMaps.Select(c => c.Map.Name)));
            }
            if (route.RouteTypeId.HasValue)
            {
                feature.Properties.Add("type", route.RouteType.Name);
            }
            collection.Features.Add(feature);
        }
Beispiel #11
0
        private static async Task <Geometry> ParseGmlNode(XElement node, bool optimize, double tolerance)
        {
            Geometry        geom = null;
            List <Geometry> geoms;
            Coordinate      tempCoord;

            if (node != null && node.Name.Namespace == gmlNS)
            {
                string nodeName = node.Name.LocalName.ToLowerInvariant();
                switch (nodeName)
                {
                case "point":
                    var cNode = XmlUtilities.GetChildNode(node, "pos");

                    if (cNode == null)
                    {
                        cNode = XmlUtilities.GetChildNode(node, "coordinates");
                    }

                    if (cNode != null)
                    {
                        tempCoord = ParsePos(cNode);
                        if (!double.IsNaN(tempCoord.Latitude) && !double.IsNaN(tempCoord.Longitude))
                        {
                            geom = new Point(tempCoord);
                        }
                    }
                    break;

                case "linestring":
                    var pos = XmlUtilities.GetChildNodes(node, "poslist");
                    if (pos == null)
                    {
                        pos = XmlUtilities.GetChildNodes(node, "coordinates");
                    }

                    var lineCoords = new List <CoordinateCollection>();

                    foreach (var c in pos)
                    {
                        lineCoords.Add(await ParsePosList(c, optimize, tolerance));
                    }

                    var lines = new List <LineString>();

                    foreach (var l in lineCoords)
                    {
                        if (l != null && l.Count >= 2)
                        {
                            lines.Add(new LineString(l));
                        }
                    }

                    if (lines.Count == 1)
                    {
                        geom = lines[0];
                    }
                    else if (lines.Count > 1)
                    {
                        geom = new MultiLineString(lines);
                    }
                    break;

                case "polygon":
                    CoordinateCollection exRing = null;
                    var inRings = new List <CoordinateCollection>();

                    foreach (var c in node.Elements())
                    {
                        nodeName = c.Name.LocalName.ToLowerInvariant();
                        switch (nodeName)
                        {
                        case "exterior":
                        case "outerboundaryis":
                            var exR = await ParseLinearRings(c, optimize, tolerance);

                            if (exR != null)
                            {
                                exRing = exR;
                            }
                            break;

                        case "interior":
                        case "innerboundaryis":
                            var inR = await ParseLinearRings(c, optimize, tolerance);

                            if (inR != null)
                            {
                                inRings.Add(inR);
                            }
                            break;

                        default:
                            break;
                        }
                    }

                    if (exRing != null && exRing.Count >= 3)
                    {
                        geom = new Polygon(exRing);

                        if (inRings.Count > 0)
                        {
                            (geom as Polygon).InteriorRings = inRings;
                        }
                    }
                    break;

                case "multipoint":
                    var mp = new MultiPoint();
                    geoms = await ParseGmlMembers(node, optimize, tolerance);

                    foreach (var p in geoms)
                    {
                        if (p is Point)
                        {
                            mp.Geometries.Add(p as Point);
                        }
                    }
                    geom = mp;
                    break;

                case "multilintstring":
                    var mline = new MultiLineString();
                    geoms = await ParseGmlMembers(node, optimize, tolerance);

                    foreach (var p in geoms)
                    {
                        if (p is LineString)
                        {
                            mline.Geometries.Add(p as LineString);
                        }
                    }
                    geom = mline;
                    break;

                case "multipolygon":
                    var mpoly = new MultiPolygon();
                    geoms = await ParseGmlMembers(node, optimize, tolerance);

                    foreach (var p in geoms)
                    {
                        if (p is Polygon)
                        {
                            mpoly.Geometries.Add(p as Polygon);
                        }
                    }
                    geom = mpoly;
                    break;

                case "multigeometry":
                    geom = new GeometryCollection(await ParseGmlMembers(node, optimize, tolerance));
                    break;

                default:
                    break;
                }
            }

            return(geom);
        }
Beispiel #12
0
        /// <summary>
        /// Reads and parses the geometry with ID 'oid' from the ShapeFile
        /// </summary>
        /// <remarks><see cref="FilterDelegate">Filtering</see> is not applied to this method</remarks>
        /// <param name="oid">Object ID</param>
        /// <returns>geometry</returns>
        // ReSharper disable once CyclomaticComplexity // Fix when changes need to be made here
        private Geometry ReadGeometry(uint oid)
        {
            _brShapeFile.BaseStream.Seek(GetShapeIndex(oid) + 8, 0); //Skip record number and content length
            var type = (ShapeType)_brShapeFile.ReadInt32();          //Shape type

            if (type == ShapeType.Null)
            {
                return(null);
            }
            if (_shapeType == ShapeType.Point || _shapeType == ShapeType.PointM || _shapeType == ShapeType.PointZ)
            {
                return(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble()));
            }
            if (_shapeType == ShapeType.Multipoint || _shapeType == ShapeType.MultiPointM ||
                _shapeType == ShapeType.MultiPointZ)
            {
                _brShapeFile.BaseStream.Seek(32 + _brShapeFile.BaseStream.Position, 0); //skip min/max box
                var feature = new MultiPoint();
                int nPoints = _brShapeFile.ReadInt32();                                 // get the number of points
                if (nPoints == 0)
                {
                    return(null);
                }
                for (int i = 0; i < nPoints; i++)
                {
                    feature.Points.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble()));
                }

                return(feature);
            }
            if (_shapeType == ShapeType.PolyLine || _shapeType == ShapeType.Polygon ||
                _shapeType == ShapeType.PolyLineM || _shapeType == ShapeType.PolygonM ||
                _shapeType == ShapeType.PolyLineZ || _shapeType == ShapeType.PolygonZ)
            {
                _brShapeFile.BaseStream.Seek(32 + _brShapeFile.BaseStream.Position, 0); //skip min/max box

                int nParts = _brShapeFile.ReadInt32();                                  // get number of parts (segments)
                if (nParts == 0)
                {
                    return(null);
                }
                int nPoints = _brShapeFile.ReadInt32(); // get number of points

                var segments = new int[nParts + 1];
                //Read in the segment indexes
                for (int b = 0; b < nParts; b++)
                {
                    segments[b] = _brShapeFile.ReadInt32();
                }
                //add end point
                segments[nParts] = nPoints;

                if ((int)_shapeType % 10 == 3)
                {
                    var mline = new MultiLineString();
                    for (int lineId = 0; lineId < nParts; lineId++)
                    {
                        var line = new LineString();
                        for (int i = segments[lineId]; i < segments[lineId + 1]; i++)
                        {
                            line.Vertices.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble()));
                        }
                        mline.LineStrings.Add(line);
                    }
                    if (mline.LineStrings.Count == 1)
                    {
                        return(mline[0]);
                    }
                    return(mline);
                }
                else //(_ShapeType == ShapeType.Polygon etc...)
                {
                    //First read all the rings
                    var rings = new List <LinearRing>();
                    for (int ringId = 0; ringId < nParts; ringId++)
                    {
                        var ring = new LinearRing();
                        for (int i = segments[ringId]; i < segments[ringId + 1]; i++)
                        {
                            ring.Vertices.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble()));
                        }
                        rings.Add(ring);
                    }
                    var isCounterClockWise = new bool[rings.Count];
                    int polygonCount       = 0;
                    for (int i = 0; i < rings.Count; i++)
                    {
                        isCounterClockWise[i] = rings[i].IsCCW();
                        if (!isCounterClockWise[i])
                        {
                            polygonCount++;
                        }
                    }
                    if (polygonCount == 1) //We only have one polygon
                    {
                        var poly = new Polygon {
                            ExteriorRing = rings[0]
                        };
                        if (rings.Count > 1)
                        {
                            for (int i = 1; i < rings.Count; i++)
                            {
                                poly.InteriorRings.Add(rings[i]);
                            }
                        }
                        return(poly);
                    }
                    else
                    {
                        var mpoly = new MultiPolygon();
                        var poly  = new Polygon {
                            ExteriorRing = rings[0]
                        };
                        for (var i = 1; i < rings.Count; i++)
                        {
                            if (!isCounterClockWise[i])
                            {
                                mpoly.Polygons.Add(poly);
                                poly = new Polygon(rings[i]);
                            }
                            else
                            {
                                poly.InteriorRings.Add(rings[i]);
                            }
                        }
                        mpoly.Polygons.Add(poly);
                        return(mpoly);
                    }
                }
            }

            throw (new ApplicationException("Shapefile type " + _shapeType.ToString() + " not supported"));
        }
        /// <summary>
        /// This function lets the user set up whether the shape should be regular, type M or type Z.
        /// This will not interfere with existing shapes in the geometry, but will simply
        /// add the specified geometry to the end of the existing information.  Sending a null shape
        /// will create a new shape of the appropriate kind.
        /// </summary>
        /// <param name="geom">A Geometries.Geometry specifying what to append to the shape.
        /// Simply returns mwShape unchanged if geom is null.</param>
        /// <param name="mwShape">An existing shape with a shapetype already specified.</param>
        public static void AppendGeometryToShape(IGeometry geom, ref MapWinGIS.Shape mwShape)
        {
            // we don't need to throw an error if geom is null, there is simply nothing to add.
            if (geom == null)
            {
                return;
            }

            // If we have to set up a new shape object, we will also have to specify a shape type.
            bool SpecifyShapeType = false;

            if (mwShape == null)
            {
                mwShape          = new MapWinGIS.Shape();
                SpecifyShapeType = true;
            }
            MapWinGIS.Point mwPoint;
            int             rfPt  = mwShape.numPoints; // Flexible Point Index
            int             rfPrt = mwShape.NumParts;  // Flexible Part Index

            if (rfPt > 0 && rfPrt == 0)
            {
                //Change single part to a multipart shapefile
                mwShape.InsertPart(0, ref rfPrt);
                rfPrt++;
            }

            #region -------------------------- POINT -------------------------------------------

            if (geom.GetType() == typeof(Point))
            {
                if (SpecifyShapeType == true)
                {
                    mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_POINT;
                }
                // Only allow appending to a point shape type if there isn't a point defined yet.
                if ((mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINT ||
                     mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINTM ||
                     mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINTZ) ||
                    ((mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINT ||
                      mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINTM ||
                      mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINTZ) && rfPt == 0))
                {
                    Point newPoint = geom as Point;
                    mwPoint   = new MapWinGIS.Point();
                    mwPoint.x = newPoint.X;
                    mwPoint.y = newPoint.Y;
                    mwShape.InsertPoint(mwPoint, ref rfPt);
                    return;
                }
                else
                {
                    if ((mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINT ||
                         mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINTM ||
                         mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POINTZ))
                    {
                        throw new ArgumentException("The Shape type of mwShape must be MultiPoint, MultiPointM, or MultiPointZ in order to Append a Point Geometry to a shape that already contains a point.");
                    }
                    else
                    {
                        throw new ArgumentException("mwShape had a shape type that did not correspond to Point or MultiPoint.  Point geometry not added.");
                    }
                }
            }

            #endregion

            #region -------------------------- MULTI POINT--------------------------------------

            if (geom.GetType() == typeof(MultiPoint))
            {
                if (SpecifyShapeType == true)
                {
                    mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_MULTIPOINT;
                }

                if (mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINT ||
                    mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINTM ||
                    mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_MULTIPOINTZ)
                {
                    MultiPoint newPoints = geom as MultiPoint;
                    for (int iPoint = 0; iPoint < newPoints.Count; iPoint++)
                    {
                        Point CurPoint = newPoints.Geometries[iPoint] as Point;
                        mwPoint   = new MapWinGIS.Point();
                        mwPoint.x = CurPoint.X;
                        mwPoint.y = CurPoint.Y;
                        mwShape.InsertPoint(mwPoint, ref rfPt);
                        rfPt++;  // I don't think we can have multi-parts in a multipoint shape
                    }
                    return;
                }
                else
                {
                    throw new ArgumentException("The shape type must be one of the multipoint types to add a multipoint geometry.");
                }
            }

            #endregion

            #region -------------------------- LINE STRING -------------------------------------

            if (geom.GetType() == typeof(LineString) || geom.GetType() == typeof(LinearRing))
            {
                if (SpecifyShapeType == true)
                {
                    mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_POLYLINE;
                }

                if (mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINE ||
                    mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINEM ||
                    mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINEZ)
                {
                    LineString newPoints = geom as LineString; // Polymorphism should allow linear rings to be line strings
                    for (int iPoint = 0; iPoint < newPoints.Count; iPoint++)
                    {
                        ICoordinate CurPoint = newPoints.Coordinates[iPoint];
                        mwPoint   = new MapWinGIS.Point();
                        mwPoint.x = CurPoint.X;
                        mwPoint.y = CurPoint.Y;
                        mwShape.InsertPoint(mwPoint, ref rfPt);
                        rfPt++;  // I don't think we can have multi-parts in a multipoint shape
                    }
                    return;
                }
                else
                {
                    throw new ArgumentException("The shape type must be one of the polyline types to add a LineString geometry.");
                }
            }
            #endregion

            #region -------------------------- MULTI LINESTRING --------------------------------

            if (geom.GetType() == typeof(MultiLineString))
            {
                if (SpecifyShapeType == true)
                {
                    mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_POLYLINE;
                }

                MultiLineString MLS = geom as MultiLineString;

                if (mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINE ||
                    mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINEM ||
                    mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYLINEZ)
                {
                    for (int iGeom = 0; iGeom < MLS.NumGeometries; iGeom++)
                    {
                        LineString LS = MLS.Geometries[iGeom] as LineString;
                        AppendGeometryToShape(LS, ref mwShape); // prevents a lot of code duplication
                    }
                    return;
                }
                else
                {
                    throw new ArgumentException("Cannot append a MultiLineString geometry to a " + mwShape.ShapeType.ToString() + " shape.");
                }
            }

            #endregion

            #region -------------------------- POLYGON -----------------------------------------
            if (geom.GetType() == typeof(Polygon))
            {
                Polygon newPolygon = geom as Polygon;
                if (SpecifyShapeType == true)
                {
                    mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_POLYGON;
                }


                if (mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGON ||
                    mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGONM ||
                    mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGONZ)
                {
                    mwShape.InsertPart(rfPt, ref rfPrt);
                    rfPrt++;
                    ILinearRing Shell = newPolygon.Shell;
                    for (int iPoint = 0; iPoint < Shell.NumPoints; iPoint++)
                    {
                        ICoordinate Coord = Shell.Coordinates[iPoint];
                        mwPoint   = new MapWinGIS.Point();
                        mwPoint.x = Coord.X;
                        mwPoint.y = Coord.Y;
                        mwShape.InsertPoint(mwPoint, ref rfPt);
                        rfPt++;
                    }

                    // The same hole may appear multiple times in overlapping polygons.
                    // Create a list of holes in order to test clockwise.
                    if (newPolygon.NumInteriorRings > 0)
                    {
                        List <ILinearRing> UniqueHoles = new List <ILinearRing>();
                        List <ILinearRing> Holes       = GetHoles(mwShape); //holes in the existing shape

                        for (int iHole = 0; iHole < newPolygon.NumInteriorRings; iHole++)
                        {
                            if (Holes.Count > 0)
                            {
                                for (int jHole = 0; jHole < Holes.Count; jHole++)
                                {
                                    if (newPolygon.Holes[iHole] == Holes[jHole])
                                    {
                                        continue;
                                    }
                                    // if we get here, the new hole is unique and should be added
                                    UniqueHoles.Add(newPolygon.Holes[iHole]);
                                    // Also add it to the list to compare against other future holes
                                    Holes.Add(newPolygon.Holes[iHole]); // Holes.Count is re-evaluated each time so this should be ok
                                }
                            }
                            //else
                            //{
                            //    //make sure holes are added to a shape with no holes
                            //    UniqueHoles.Add(newPolygon.Holes[iHole]);
                            //    Holes.Add(newPolygon.Holes[iHole]);
                            //}
                        }

                        for (int iHole = 0; iHole < UniqueHoles.Count; iHole++)
                        {
                            mwShape.InsertPart(rfPt, ref rfPrt);
                            rfPrt++;
                            ICoordinate[] Hole;
                            if (IsClockwise(UniqueHoles[iHole].Coordinates))
                            {
                                // Holes should be counter clockwise
                                Hole = UniqueHoles[iHole].Reverse().Coordinates;
                            }
                            else
                            {
                                Hole = UniqueHoles[iHole].Coordinates;
                            }

                            int Count = Hole.GetUpperBound(0) + 1;
                            for (int iPoint = 0; iPoint < Count; iPoint++)
                            {
                                ICoordinate Coord = Hole[iPoint];
                                mwPoint   = new MapWinGIS.Point();
                                mwPoint.x = Coord.X;
                                mwPoint.y = Coord.Y;
                                mwShape.InsertPoint(mwPoint, ref rfPt);
                                rfPt++;
                            }
                        }
                    }
                }
            }

            #endregion

            #region -------------------------- MULTI POLYGON------------------------------------

            // The reason not to just Call Add Polygon recursively with this is that we only
            // want to test for unique holes once.  Doing so each and every time we add a polygon
            // would be a major inefficiency, plus the overhead from converting back and forth
            // to a shape object.

            if (geom.GetType() == typeof(MultiPolygon))
            {
                MultiPolygon MPG = geom as MultiPolygon;

                if (SpecifyShapeType == true)
                {
                    mwShape.ShapeType = MapWinGIS.ShpfileType.SHP_POLYGON;
                }

                if (mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGON ||
                    mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGONM ||
                    mwShape.ShapeType == MapWinGIS.ShpfileType.SHP_POLYGONZ)
                {
                    // By doing this one time up here, we prevent a lot of duplication
                    List <ILinearRing> Holes = Holes = GetHoles(mwShape);

                    for (int iPolygon = 0; iPolygon < MPG.NumGeometries; iPolygon++)
                    {
                        Polygon newPolygon = MPG.Geometries[iPolygon] as Polygon;
                        mwShape.InsertPart(rfPt, ref rfPrt);
                        rfPrt++;
                        ILinearRing Shell = newPolygon.Shell;
                        for (int iPoint = 0; iPoint < Shell.NumPoints; iPoint++)
                        {
                            ICoordinate Coord = Shell.Coordinates[iPoint];
                            mwPoint   = new MapWinGIS.Point();
                            mwPoint.x = Coord.X;
                            mwPoint.y = Coord.Y;
                            mwShape.InsertPoint(mwPoint, ref rfPt);
                            rfPt++;
                        }

                        // The same hole may appear multiple times in overlapping polygons.
                        // Create a list of holes in order to test clockwise.
                        if (newPolygon.NumInteriorRings > 0)
                        {
                            List <ILinearRing> UniqueHoles = new List <ILinearRing>();


                            for (int iHole = 0; iHole < newPolygon.NumInteriorRings; iHole++)
                            {
                                for (int jHole = 0; jHole < Holes.Count; jHole++)
                                {
                                    if (newPolygon.Holes[iHole] == Holes[jHole])
                                    {
                                        continue;
                                    }
                                    // if we get here, the new hole is unique and should be added
                                    UniqueHoles.Add(newPolygon.Holes[iHole]);
                                    // Also add it to the list to compare against other future holes
                                    Holes.Add(newPolygon.Holes[iHole]); // Holes.Count is re-evaluated each time so this should be ok
                                }
                            }

                            for (int iHole = 0; iHole < UniqueHoles.Count; iHole++)
                            {
                                mwShape.InsertPart(rfPt, ref rfPrt);
                                rfPrt++;
                                ICoordinate[] Hole;
                                if (IsClockwise(UniqueHoles[iHole].Coordinates))
                                {
                                    // Holes should be counter clockwise
                                    Hole = UniqueHoles[iHole].Reverse().Coordinates;
                                }
                                else
                                {
                                    Hole = UniqueHoles[iHole].Coordinates;
                                }

                                int Count = Hole.GetUpperBound(0) + 1;
                                for (int iPoint = 0; iPoint < Count; iPoint++)
                                {
                                    ICoordinate Coord = Hole[iPoint];
                                    mwPoint   = new MapWinGIS.Point();
                                    mwPoint.x = Coord.X;
                                    mwPoint.y = Coord.Y;
                                    mwShape.InsertPoint(mwPoint, ref rfPt);
                                    rfPt++;
                                }
                            }
                        }
                    }
                }
            }

            #endregion
        }
Beispiel #14
0
 public MultiLineString GetEchoMultiLineString(MultiLineString geom)
 {
     return(geom);
 }
Beispiel #15
0
        public void TestMultiLineStringEqualsHashCode()
        {
            var multiLineString1 = new MultiLineString(
                new[]
            {
                new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 40) }),
                new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) })
            },
                new GeometryParams
            {
                AdditionalProperties = new Dictionary <string, object> {
                    { "a", "b" }
                },
                BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)),
                Crs         = Crs.Named("SomeCrs")
            });

            var multiLineString2 = new MultiLineString(
                new[]
            {
                new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 40) }),
                new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) })
            },
                new GeometryParams
            {
                AdditionalProperties = new Dictionary <string, object> {
                    { "a", "b" }
                },
                BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)),
                Crs         = Crs.Named("SomeCrs")
            });

            var multiLineString3 = new MultiLineString(
                new[]
            {
                new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 41) }),
                new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) })
            },
                new GeometryParams
            {
                AdditionalProperties = new Dictionary <string, object> {
                    { "a", "b" }
                },
                BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)),
                Crs         = Crs.Named("SomeCrs")
            });

            var multiLineString4 = new MultiLineString(
                new[]
            {
                new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 40) }),
                new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) })
            },
                new GeometryParams
            {
                AdditionalProperties = new Dictionary <string, object> {
                    { "b", "c" }
                },
                BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)),
                Crs         = Crs.Named("SomeCrs")
            });

            var multiLineString5 = new MultiLineString(
                new[]
            {
                new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 40) }),
                new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) })
            },
                new GeometryParams
            {
                AdditionalProperties = new Dictionary <string, object> {
                    { "a", "b" }
                },
                BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 41)),
                Crs         = Crs.Named("SomeCrs")
            });

            var multiLineString6 = new MultiLineString(
                new[]
            {
                new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 40) }),
                new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) })
            },
                new GeometryParams
            {
                AdditionalProperties = new Dictionary <string, object> {
                    { "a", "b" }
                },
                BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)),
                Crs         = Crs.Named("SomeCrs1")
            });

            Assert.AreEqual(multiLineString1, multiLineString2);
            Assert.AreEqual(multiLineString1.GetHashCode(), multiLineString2.GetHashCode());

            Assert.AreNotEqual(multiLineString1, multiLineString3);
            Assert.AreNotEqual(multiLineString1.GetHashCode(), multiLineString3.GetHashCode());

            Assert.AreNotEqual(multiLineString1, multiLineString4);
            Assert.AreNotEqual(multiLineString1.GetHashCode(), multiLineString4.GetHashCode());

            Assert.AreNotEqual(multiLineString1, multiLineString5);
            Assert.AreNotEqual(multiLineString1.GetHashCode(), multiLineString5.GetHashCode());

            Assert.AreNotEqual(multiLineString1, multiLineString6);
            Assert.AreNotEqual(multiLineString1.GetHashCode(), multiLineString6.GetHashCode());
        }
        /// <summary>
        /// This creates a new shapefile that has Z values and follows along the same line segments.
        /// The boundaries for grid cells are marked with vertices and the segment is given a Z value
        /// that corresponds to the grid elevation it intersects.
        /// </summary>
        /// <param name="mwElevGrid">A MapWinGIS Grid that contains the elevations.</param>
        /// <param name="mwPolyLine">A MapWinGIS Shapefile that shows the pathways of the cross sections in the X-Y direction.</param>
        /// <param name="OutFileName">A string containing the full path of the desired output shapefile.  The extension should be *.shp</param>
        /// <param name="CrossSectionType">Clarifies the type of output.  default = PolyLineWithZ</param>
        /// <param name="ICallBack">A MapWinGIS.ICallback for progress messages. [Optional]</param>
        /// <remarks>This function throws Argument or Application exceptions on errors, so it's recommended that coders enclose it in a try catch block.</remarks>
        public static void GetCrossSection(MapWinGIS.Grid mwElevGrid, MapWinGIS.Shapefile mwPolyLine, string OutFileName, CrossSectionTypes CrossSectionType, MapWinGIS.ICallback ICallBack)
        {
            MapWinUtility.Logger.Dbg("GetCrossSection(mwElevGrid: " + Macro.ParamName(mwElevGrid) + ",\n" +
                                     "                mwPolyLine: " + Macro.ParamName(mwPolyLine) + ",\n" +
                                     "                OutFileName: " + OutFileName + ",\n" +
                                     "                CrossSectionType: " + CrossSectionType.ToString() + ",\n" +
                                     "                ICallback)");
            bool   res;
            int    Prog = 0;
            int    OldProg = 0;
            double dS, dX, dY, XllCenter, YllCenter;
            int    NumRows, NumCols, ElevField, IDField;

            ElevField = 1;
            IDField   = 0;
            // Test to be sure that the elevation grid and shapefile are not null
            if (mwElevGrid == null)
            {
                MapWinUtility.Logger.Dbg("Argument Exception: Elevation grid mwElevGrid can't be null.");
                throw new ArgumentException("Elevation grid mwElevGrid can't be null.");
            }
            if (mwPolyLine == null)
            {
                MapWinUtility.Logger.Dbg("Argument Exception: The shapefile of input cross sections mwPolyLine can't be null.");
                throw new ArgumentException("The shapefile of input cross sections mwPolyLine can't be null.");
            }

            // Clear any existing shapefile output filenames that might cause problems if they exist.
            string fn;

            if (System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(OutFileName)) == false)
            {
                System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(OutFileName));
            }
            if (System.IO.File.Exists(OutFileName))
            {
                System.IO.File.Delete(OutFileName);
            }
            fn = System.IO.Path.ChangeExtension(OutFileName, ".dbf");
            if (System.IO.File.Exists(fn))
            {
                System.IO.File.Delete(fn);
            }
            fn = System.IO.Path.ChangeExtension(OutFileName, ".shx");
            if (System.IO.File.Exists(fn))
            {
                System.IO.File.Delete(fn);
            }
            fn = System.IO.Path.ChangeExtension(OutFileName, ".prj");
            if (System.IO.File.Exists(fn))
            {
                System.IO.File.Delete(fn);
            }
            // Since we are given the lower left coordinate, just make sure dX and dY are positive
            dX = Math.Abs(mwElevGrid.Header.dX);
            if (dX == 0)
            {
                throw new ApplicationException("mwElevGrid.Header.dX cannot be 0.");
            }
            dY = Math.Abs(mwElevGrid.Header.dY);
            if (dY == 0)
            {
                throw new ApplicationException("mwElevGrid.Header.dY cannot be 0.");
            }

            // Determine the stepping distance from the grid coordintes
            dS = dX / 2;
            if (dY < dX)
            {
                dS = dY / 2;
            }


            XllCenter = mwElevGrid.Header.XllCenter;
            YllCenter = mwElevGrid.Header.YllCenter;
            NumRows   = mwElevGrid.Header.NumberRows;
            NumCols   = mwElevGrid.Header.NumberCols;

            // Test for intersection between the entire shapefile and the grid
            double left, right, top, bottom;

            left   = XllCenter - dX / 2;
            right  = XllCenter + NumCols * dX - dX / 2;
            bottom = YllCenter - dY / 2;
            top    = YllCenter + NumRows * dY - dY / 2;
            MapWinGeoProc.Topology2D.Envelope gExt = new MapWinGeoProc.Topology2D.Envelope(left, right, bottom, top);
            MapWinGeoProc.Topology2D.Envelope pExt = new MapWinGeoProc.Topology2D.Envelope(mwPolyLine.Extents);
            if (gExt.Intersects(pExt) == false)
            {
                MapWinUtility.Logger.Dbg("Application Exception: The shapefile doesn't overlap the grid, so no cross sections were found.");
                throw new ApplicationException("The shapefile doesn't overlap the grid, so no cross sections were found.");
            }


            // Setup the output shapefile and the basic shape objects
            MapWinGIS.Shape     mwShape;
            MapWinGIS.Shapefile sfOut = new MapWinGIS.Shapefile();
            sfOut.Projection = mwPolyLine.Projection;

            if (CrossSectionType == CrossSectionTypes.PointsWithZAndElevField)
            {
                res = sfOut.CreateNew(OutFileName, MapWinGIS.ShpfileType.SHP_POINTZ);
                if (res != true)
                {
                    MapWinUtility.Logger.Dbg("Application Exception: " + sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                }
                res = sfOut.StartEditingShapes(true, ICallBack);
                if (res != true)
                {
                    MapWinUtility.Logger.Dbg("Application Exception: " + sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                }
                MapWinGIS.Field ID = new MapWinGIS.Field();
                ID.Name = "ID";
                ID.Type = MapWinGIS.FieldType.INTEGER_FIELD;
                res     = sfOut.EditInsertField(ID, ref IDField, ICallBack);
                if (res != true)
                {
                    MapWinUtility.Logger.Dbg("Application Exception: " + sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                }
                MapWinGIS.Field Elev = new MapWinGIS.Field();
                Elev.Name = "Elevation";
                Elev.Type = MapWinGIS.FieldType.DOUBLE_FIELD;
                res       = sfOut.EditInsertField(Elev, ref ElevField, ICallBack);
                if (res != true)
                {
                    MapWinUtility.Logger.Dbg("Application Exception: " + sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                }
            }
            else
            {
                res = sfOut.CreateNew(OutFileName, MapWinGIS.ShpfileType.SHP_POLYLINEZ);
                if (res != true)
                {
                    MapWinUtility.Logger.Dbg("Application Exception: " + sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                }
                res = sfOut.StartEditingShapes(true, ICallBack);
                if (res != true)
                {
                    MapWinUtility.Logger.Dbg("Application Exception: " + sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                }
                MapWinGIS.Field ID = new MapWinGIS.Field();
                ID.Name = "ID";
                ID.Type = MapWinGIS.FieldType.INTEGER_FIELD;
                res     = sfOut.EditInsertField(ID, ref IDField, ICallBack);
                if (res != true)
                {
                    MapWinUtility.Logger.Dbg("Application Exception: " + sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                }
            }



            MapWinGIS.Shape mwOutShape;
            // Loop through all the shapes in the polyline shapefile
            int shIndx = -1;

            for (int shp = 0; shp < mwPolyLine.NumShapes; shp++)
            {
                mwShape = mwPolyLine.get_Shape(shp);

                // By turning multi-part polylines into multiple linestrings, we avoid the annoying multi-part logic
                MultiLineString MLS = GeometryFactory.CreateMultiLineString(mwShape);

                for (int ls = 0; ls < MLS.NumGeometries; ls++)
                {
                    LineString lsSource = MLS.GeometryN[ls] as LineString;
                    for (int pt = 0; pt < lsSource.Coordinates.Count - 1; pt++)
                    {
                        Coordinate start = lsSource.Coordinates[pt];
                        Coordinate end   = lsSource.Coordinates[pt + 1];

                        // Crop the parts of each segment that do not overlap with the grid.
                        if (start.X < left)
                        {
                            if (end.X < left)
                            {
                                // this segment is outside the grid
                                continue;
                            }
                            // crop this segment to only the portion on the grid
                            start.X = left;
                        }
                        if (end.X < left)
                        {
                            // crop this segment to only the portion on the grid
                            end.X = left;
                        }
                        if (start.X > right)
                        {
                            if (end.X > right)
                            {
                                // this segment is outside the grid
                                continue;
                            }
                            // crop to grid
                            start.X = right;
                        }
                        if (end.X > right)
                        {
                            // crop to the grid
                            end.X = right;
                        }


                        double length   = Math.Sqrt((end.X - start.X) * (end.X - start.X) + (end.Y - start.Y) * (end.Y - start.Y));
                        int    NumSteps = (int)Math.Floor(length / dS);
                        double segDx    = (end.X - start.X) / NumSteps;
                        double segDy    = (end.Y - start.Y) / NumSteps;
                        mwOutShape = new MapWinGIS.Shape();
                        if (CrossSectionType == CrossSectionTypes.PolyLineWithZ)
                        {
                            mwOutShape.Create(MapWinGIS.ShpfileType.SHP_POLYLINEZ);
                        }

                        // step by dS and get the grid value at that point at each step
                        int p = 0;
                        for (int I = 0; I < NumSteps; I++)
                        {
                            int    row, col;
                            object Elev;
                            double X = start.X + segDx * I;
                            double Y = start.Y + segDy * I;
                            mwElevGrid.ProjToCell(X, Y, out col, out row);
                            Elev = mwElevGrid.get_Value(col, row);
                            MapWinGIS.Point pnt = new MapWinGIS.Point();
                            pnt.x = X;
                            pnt.y = Y;
                            pnt.Z = (double)Elev;
                            if (CrossSectionType == CrossSectionTypes.PointsWithZAndElevField)
                            {
                                p          = 0;
                                mwOutShape = new MapWinGIS.Shape();
                                mwOutShape.Create(MapWinGIS.ShpfileType.SHP_POINTZ);
                                res = mwOutShape.InsertPoint(pnt, ref p);
                                if (res == false)
                                {
                                    throw new ApplicationException(mwOutShape.get_ErrorMsg(mwOutShape.LastErrorCode));
                                }
                                res = sfOut.EditInsertShape(mwOutShape, ref shIndx);
                                if (res != true)
                                {
                                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                                }
                                res = sfOut.EditCellValue(IDField, shIndx, shIndx);
                                if (res != true)
                                {
                                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                                }
                                res = sfOut.EditCellValue(ElevField, shIndx, Elev);
                                if (res != true)
                                {
                                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                                }
                                shIndx++;
                            }
                            else
                            {
                                res = mwOutShape.InsertPoint(pnt, ref p);
                                p++;
                                if (res == false)
                                {
                                    throw new ApplicationException(mwOutShape.get_ErrorMsg(mwOutShape.LastErrorCode));
                                }
                            }
                        }
                        if (CrossSectionType == CrossSectionTypes.PolyLineWithZ)
                        {
                            if (mwOutShape.numPoints > 0)
                            {
                                res = sfOut.EditInsertShape(mwOutShape, ref shIndx);
                                if (res != true)
                                {
                                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                                }
                                res = sfOut.EditCellValue(IDField, shIndx, shIndx);
                                if (res != true)
                                {
                                    throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                                }
                                shIndx++;
                            }
                        }
                    }
                }
                Prog = Convert.ToInt32(shp * 100 / mwPolyLine.NumShapes);
                if (Prog > OldProg)
                {
                    MapWinUtility.Logger.Progress("Evaluating Cross Section..." + Prog.ToString() + "% Complete.", Prog, OldProg);
                    OldProg = Prog;
                }
            }
            res = sfOut.StopEditingShapes(true, true, ICallBack);
            if (res != true)
            {
                MapWinUtility.Logger.Dbg("Application Exception: " + sfOut.get_ErrorMsg(sfOut.LastErrorCode));
                throw new ApplicationException(sfOut.get_ErrorMsg(sfOut.LastErrorCode));
            }
        }
Beispiel #17
0
 int INpgsqlTypeHandler <MultiLineString> .ValidateAndGetLength(MultiLineString value, ref NpgsqlLengthCache?lengthCache, NpgsqlParameter?parameter)
 => ValidateAndGetLength(value, ref lengthCache, parameter);
Beispiel #18
0
        public void 引数の文字列を改行で連結する()
        {
            var result = MultiLineString.Join("Hello", "World");

            CustomAssert.AreEqual("Hello\nWorld", result);
        }
        private MultiLineString closedMLS()
        {
            Coordinates     coords     = new Coordinates();
            Coordinate      coord      = new Coordinate();
            GeometryFactory gf         = new GeometryFactory(_precMod, _sRID);
            LineString      lineString = gf.CreateLineString(coords);

            LineString[] ls = new LineString[2];

            coord = new Coordinate(10, 13);
            coords.Add(coord);
            coord = new Coordinate(11, 13);
            coords.Add(coord);
            coord = new Coordinate(12, 13);
            coords.Add(coord);
            coord = new Coordinate(13, 14);
            coords.Add(coord);
            coord = new Coordinate(14, 15);
            coords.Add(coord);
            coord = new Coordinate(15, 16);
            coords.Add(coord);
            coord = new Coordinate(15, 17);
            coords.Add(coord);
            coord = new Coordinate(15, 18);
            coords.Add(coord);
            coord = new Coordinate(14, 19);
            coords.Add(coord);
            coord = new Coordinate(13, 20);
            coords.Add(coord);
            coord = new Coordinate(12, 21);
            coords.Add(coord);
            coord = new Coordinate(11, 21);
            coords.Add(coord);
            coord = new Coordinate(10, 21);
            coords.Add(coord);
            coord = new Coordinate(9, 20);
            coords.Add(coord);
            coord = new Coordinate(8, 19);
            coords.Add(coord);
            coord = new Coordinate(7, 18);
            coords.Add(coord);
            coord = new Coordinate(7, 17);
            coords.Add(coord);
            coord = new Coordinate(7, 16);
            coords.Add(coord);
            coord = new Coordinate(8, 15);
            coords.Add(coord);
            coord = new Coordinate(9, 14);
            coords.Add(coord);
            coord = new Coordinate(10, 13);
            coords.Add(coord);
            ls[0] = gf.CreateLineString(coords);

            coords = new Coordinates();
            coord  = new Coordinate(5, 1);
            coords.Add(coord);
            coord = new Coordinate(6, 2);
            coords.Add(coord);
            coord = new Coordinate(7, 3);
            coords.Add(coord);
            coord = new Coordinate(6, 4);
            coords.Add(coord);
            coord = new Coordinate(5, 5);
            coords.Add(coord);
            coord = new Coordinate(4, 4);
            coords.Add(coord);
            coord = new Coordinate(3, 3);
            coords.Add(coord);
            coord = new Coordinate(4, 2);
            coords.Add(coord);
            coord = new Coordinate(5, 1);
            coords.Add(coord);
            ls[1] = gf.CreateLineString(coords);

            MultiLineString multiLS = gf.CreateMultiLineString(ls);

            return(multiLS);
        }
Beispiel #20
0
 /// <summary>
 /// Determines whether a <see cref="MultiLineString"/> geometry is simple.
 /// </summary>
 /// <param name="geometry">
 /// A <see cref="MultiLineString"/> geometry instance to be tested.
 /// </param>
 /// <returns>
 /// Returns true if the <see cref="MultiLineString"/> geometry is simple,
 /// otherwise returns false.
 /// </returns>
 public bool IsSimple(MultiLineString geometry)
 {
     return(IsSimpleLinearGeometry(geometry));
 }
Beispiel #21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="multiLineString"></param>
 /// <param name="writer"></param>
 protected virtual void Write(MultiLineString multiLineString, XmlTextWriter writer)
 {
     writer.WriteStartElement("MultiLineString");
     for (int i = 0; i < multiLineString.NumGeometries; i++)
     {
         writer.WriteStartElement("lineStringMember");
         Write(multiLineString.Geometries[i] as LineString, writer);
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
Beispiel #22
0
        public static bool Simple(MultiLineString geometry)
        {
            IsSimpleOp isSimpleTester = new IsSimpleOp();

            return(isSimpleTester.IsSimple(geometry));
        }
Beispiel #23
0
        private static MultiLineString CreateWKBMultiLineString(BinaryReader reader, WkbByteOrder byteOrder)
        {
            // Get the number of linestrings in this multilinestring.
            var numLineStrings = (int) ReadUInt32(reader, byteOrder);

            // Create a new array for the linestrings .
            var mline = new MultiLineString();

            // Loop on the number of linestrings.
            for (var i = 0; i < numLineStrings; i++)
            {
                // Read linestring header
                reader.ReadByte();
                ReadUInt32(reader, byteOrder);

                // Create the next linestring and add it to the array.
                mline.LineStrings.Add(CreateWKBLineString(reader, byteOrder));
            }

            // Create and return the MultiLineString.
            return mline;
        }
Beispiel #24
0
 private Dictionary<string, object> WriteMultiLineString(MultiLineString multiLineString)
 {
     return new Dictionary<string, object>
     {
         { "type", "MultiLineString" },
         { "coordinates", multiLineString.Geometries.Cast<LineString>().Select(x=> WriteCoordinates(x.Coordinates)).ToArray() }
     };
 }
Beispiel #25
0
 private void WriteMultiLineString(MultiLineString multiLineString, WkbBinaryWriter writer)
 {
     WriteEncoding(writer, _settings.Encoding);
     WriteGeometryType(multiLineString, WkbGeometryType.MultiLineString, writer);
     writer.Write((uint)multiLineString.Geometries.Count);
     foreach (var linestring in multiLineString.Geometries.Cast<LineString>())
         Write(linestring, writer);
 }
Beispiel #26
0
        /// <summary>
        /// Convert a JTS Geometry to a WayDataBlock list.
        /// </summary>
        /// <param name="geometry">
        ///            a geometry object which should be converted </param>
        /// <returns> a list of WayBlocks which you can use to save the way. </returns>
        public static IList <WayDataBlock> toWayDataBlockList(Geometry geometry)
        {
            IList <WayDataBlock> res = new List <WayDataBlock>();

            if (geometry is MultiPolygon)
            {
                MultiPolygon mp = (MultiPolygon)geometry;
                for (int i = 0; i < mp.NumGeometries; i++)
                {
                    Polygon      p     = (Polygon)mp.getGeometryN(i);
                    IList <int?> outer = toCoordinateList(p.ExteriorRing);
                    if (outer.Count / 2 > 0)
                    {
                        IList <IList <int?> > inner = new List <IList <int?> >();
                        for (int j = 0; j < p.NumInteriorRing; j++)
                        {
                            IList <int?> innr = toCoordinateList(p.getInteriorRingN(j));
                            if (innr.Count / 2 > 0)
                            {
                                inner.Add(innr);
                            }
                        }
                        res.Add(new WayDataBlock(outer, inner));
                    }
                }
            }
            else if (geometry is Polygon)
            {
                Polygon      p     = (Polygon)geometry;
                IList <int?> outer = toCoordinateList(p.ExteriorRing);
                if (outer.Count / 2 > 0)
                {
                    IList <IList <int?> > inner = new List <IList <int?> >();
                    for (int i = 0; i < p.NumInteriorRing; i++)
                    {
                        IList <int?> innr = toCoordinateList(p.getInteriorRingN(i));
                        if (innr.Count / 2 > 0)
                        {
                            inner.Add(innr);
                        }
                    }
                    res.Add(new WayDataBlock(outer, inner));
                }
            }
            else if (geometry is MultiLineString)
            {
                MultiLineString ml = (MultiLineString)geometry;
                for (int i = 0; i < ml.NumGeometries; i++)
                {
                    LineString   l     = (LineString)ml.getGeometryN(i);
                    IList <int?> outer = toCoordinateList(l);
                    if (outer.Count / 2 > 0)
                    {
                        res.Add(new WayDataBlock(outer, null));
                    }
                }
            }
            else if (geometry is LinearRing || geometry is LineString)
            {
                IList <int?> outer = toCoordinateList(geometry);
                if (outer.Count / 2 > 0)
                {
                    res.Add(new WayDataBlock(outer, null));
                }
            }
            else if (geometry is GeometryCollection)
            {
                GeometryCollection gc = (GeometryCollection)geometry;
                for (int i = 0; i < gc.NumGeometries; i++)
                {
                    IList <WayDataBlock> recursiveResult = toWayDataBlockList(gc.getGeometryN(i));
                    foreach (WayDataBlock wayDataBlock in recursiveResult)
                    {
                        IList <int?> outer = wayDataBlock.OuterWay;
                        if (outer.Count / 2 > 0)
                        {
                            res.Add(wayDataBlock);
                        }
                    }
                }
            }

            return(res);
        }
Beispiel #27
0
        public static void Write(MultiLineString lines, JsonTextWriter writer)
        {
            if (lines == null)
                return;
            if (writer == null)
                throw new ArgumentNullException("writer", "A valid JSON writer object is required");

            writer.WriteStartObject();
            writer.WritePropertyName("type");
            writer.WriteValue("MultiLineString");
            writer.WritePropertyName("coordinates");
            writer.WriteStartArray();
            foreach (LineString line in lines)
            {
                writer.WriteStartArray();
                WriteCoord(line.Vertices, writer);
                writer.WriteEndArray();
            }
            writer.WriteEndArray();
            writer.WriteEndObject();
        }
Beispiel #28
0
        private Geometry ReadGeometry(uint oid)
        {
            _brShapeFile.BaseStream.Seek(_offsetOfRecord[oid] + 8, 0); //Skip record number and content length
            ShapeType type = (ShapeType)_brShapeFile.ReadInt32();      //Shape type

            if (type == ShapeType.Null)
            {
                return(null);
            }
            if (_shapeType == ShapeType.Point || _shapeType == ShapeType.PointM || _shapeType == ShapeType.PointZ)
            {
                Point tempFeature = new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble());
                tempFeature.GeometryId = oid;
                return(tempFeature);
            }
            else if (_shapeType == ShapeType.Multipoint || _shapeType == ShapeType.MultiPointM ||
                     _shapeType == ShapeType.MultiPointZ)
            {
                _brShapeFile.BaseStream.Seek(32 + _brShapeFile.BaseStream.Position, 0); //skip min/max box
                MultiPoint feature = new MultiPoint();
                int        nPoints = _brShapeFile.ReadInt32();                          // get the number of points
                if (nPoints == 0)
                {
                    return(null);
                }
                for (int i = 0; i < nPoints; i++)
                {
                    feature.Points.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble()));
                }
                feature.GeometryId = oid;
                return(feature);
            }
            else if (_shapeType == ShapeType.PolyLine || _shapeType == ShapeType.Polygon ||
                     _shapeType == ShapeType.PolyLineM || _shapeType == ShapeType.PolygonM ||
                     _shapeType == ShapeType.PolyLineZ || _shapeType == ShapeType.PolygonZ)
            {
                _brShapeFile.BaseStream.Seek(32 + _brShapeFile.BaseStream.Position, 0); //skip min/max box

                int nParts = _brShapeFile.ReadInt32();                                  // get number of parts (segments)
                if (nParts == 0 || nParts < 0)
                {
                    return(null);
                }
                int nPoints = _brShapeFile.ReadInt32(); // get number of points

                int[] segments = new int[nParts + 1];
                for (int b = 0; b < nParts; b++)
                {
                    segments[b] = _brShapeFile.ReadInt32();
                }
                segments[nParts] = nPoints;

                if ((int)_shapeType % 10 == 3)
                {
                    MultiLineString mline = new MultiLineString();
                    for (int LineID = 0; LineID < nParts; LineID++)
                    {
                        LineString line = new LineString();
                        for (int i = segments[LineID]; i < segments[LineID + 1]; i++)
                        {
                            line.Vertices.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble()));
                        }
                        mline.LineStrings.Add(line);
                    }
                    if (mline.LineStrings.Count == 1)
                    {
                        mline[0].GeometryId = oid;
                        return(mline[0]);
                    }
                    mline.GeometryId = oid;
                    return(mline);
                }
                else //(_ShapeType == ShapeType.Polygon etc...)
                {
                    List <LinearRing> rings = new List <LinearRing>();
                    for (int RingID = 0; RingID < nParts; RingID++)
                    {
                        LinearRing ring = new LinearRing();
                        for (int i = segments[RingID]; i < segments[RingID + 1]; i++)
                        {
                            ring.Vertices.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble()));
                        }
                        rings.Add(ring);
                    }
                    bool[] IsCounterClockWise = new bool[rings.Count];
                    int    PolygonCount       = 0;
                    for (int i = 0; i < rings.Count; i++)
                    {
                        IsCounterClockWise[i] = rings[i].IsCCW();
                        if (!IsCounterClockWise[i])
                        {
                            PolygonCount++;
                        }
                    }
                    if (PolygonCount == 1) //We only have one polygon
                    {
                        Polygon poly = new Polygon();
                        poly.ExteriorRing = rings[0];
                        if (rings.Count > 1)
                        {
                            for (int i = 1; i < rings.Count; i++)
                            {
                                poly.InteriorRings.Add(rings[i]);
                            }
                        }
                        poly.GeometryId = oid;
                        return(poly);
                    }
                    else
                    {
                        MultiPolygon mpoly = new MultiPolygon();
                        Polygon      poly  = new Polygon();
                        poly.ExteriorRing = rings[0];
                        for (int i = 1; i < rings.Count; i++)
                        {
                            if (!IsCounterClockWise[i])
                            {
                                mpoly.Polygons.Add(poly);
                                poly = new Polygon(rings[i]);
                            }
                            else
                            {
                                poly.InteriorRings.Add(rings[i]);
                            }
                        }
                        mpoly.Polygons.Add(poly);
                        mpoly.GeometryId = oid;
                        return(mpoly);
                    }
                }
            }
            else
            {
                throw (new ApplicationException("Shapefile type " + _shapeType.ToString() + " not supported"));
            }
        }
Beispiel #29
0
        private void WriteMultiLineString(MultiLineString multiLineString)
        {
            wktBuilder.Append("(");

            foreach (LineString lineString in multiLineString.LineStrings)
            {
                WriteLineString(lineString);
                wktBuilder.Append(",");
            }

            wktBuilder.Remove(wktBuilder.Length - 1, 1);
            wktBuilder.Append(")");
        }
Beispiel #30
0
        private MultiPolygon CreateMP1()
        {
            Polygon[]    polygons = new Polygon[2];
            LineString[] rings    = new LineString[2];

            Coordinates coords = new Coordinates();
            Coordinate  coord  = new Coordinate(5, 1);

            coords.Add(coord);
            coord = new Coordinate(6, 2);
            coords.Add(coord);
            coord = new Coordinate(7, 3);
            coords.Add(coord);
            coord = new Coordinate(6, 4);
            coords.Add(coord);
            coord = new Coordinate(5, 5);
            coords.Add(coord);
            coord = new Coordinate(4, 4);
            coords.Add(coord);
            coord = new Coordinate(3, 3);
            coords.Add(coord);
            coord = new Coordinate(4, 2);
            coords.Add(coord);
            coord = new Coordinate(5, 1);
            coords.Add(coord);

            GeometryFactory gf = new GeometryFactory(_precMod, _sRID);

            LinearRing exterior1 = gf.CreateLinearRing(coords);

            polygons[0] = gf.CreatePolygon(exterior1);
            rings[0]    = exterior1 as LineString;

            coords = new Coordinates();
            coord  = new Coordinate(5, 1);
            coords.Add(coord);
            coord = new Coordinate(6, 2);
            coords.Add(coord);
            coord = new Coordinate(7, 3);
            coords.Add(coord);
            coord = new Coordinate(6, 4);
            coords.Add(coord);
            coord = new Coordinate(5, 5);
            coords.Add(coord);
            coord = new Coordinate(4, 4);
            coords.Add(coord);
            coord = new Coordinate(3, 3);
            coords.Add(coord);
            coord = new Coordinate(4, 2);
            coords.Add(coord);
            coord = new Coordinate(5, 1);
            coords.Add(coord);

            LinearRing exterior2 = gf.CreateLinearRing(coords);

            polygons[1] = gf.CreatePolygon(exterior2);
            rings[1]    = exterior2;

            _mls1 = gf.CreateMultiLineString(rings);

            return(gf.CreateMultiPolygon(polygons));
        }
        public void TestMultiLineStringSerialization()
        {
            var geometry1 = new LineString(
                new GeoCoordinate[]
                {
                    new GeoCoordinate(0, 0),
                    new GeoCoordinate(0, 1),
                    new GeoCoordinate(1, 1),
                    new GeoCoordinate(1, 0)
                });
            var geometry2 = new LineString(
                new GeoCoordinate[]
                {
                    new GeoCoordinate(0, 0),
                    new GeoCoordinate(0, 2),
                    new GeoCoordinate(2, 2),
                    new GeoCoordinate(2, 0)
                });
            var geometry3 = new LineString(
                new GeoCoordinate[]
                {
                    new GeoCoordinate(0, 0),
                    new GeoCoordinate(0, 3),
                    new GeoCoordinate(3, 3),
                    new GeoCoordinate(3, 0)
                });
            var geometryCollection = new MultiLineString(new LineString[] { geometry1, geometry2, geometry3 });

            var serialized = geometryCollection.ToGeoJson();
            serialized = serialized.RemoveWhitespace();

            Assert.AreEqual("{\"type\":\"MultiLineString\",\"coordinates\":[[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0]],[[0.0,0.0],[2.0,0.0],[2.0,2.0],[0.0,2.0]],[[0.0,0.0],[3.0,0.0],[3.0,3.0],[0.0,3.0]]]}",
                serialized);
        }
        private void CompareMultiLineStrings(MultiLineString multilinestring, MultiLineString expected)
        {
            Assert.Equal(expected.Geometries.Count, multilinestring.Geometries.Count);

            for (int i = 0; i < expected.Geometries.Count; i++) {
                this.CompareLineStrings(multilinestring.Geometries[i], expected.Geometries[i]);
            }
        }
Beispiel #33
0
 /// <summary>
 /// Converts a MultiLineString to &lt;MultiLineString Tagged
 /// Text&gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiLineString">The MultiLineString to process</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 private static void AppendMultiLineStringTaggedText(MultiLineString multiLineString, StringWriter writer)
 {
     writer.Write("MULTILINESTRING ");
     AppendMultiLineStringText(multiLineString, writer);
 }
 private MultiLineString ConvertMultiLineString(ICoordinateTransformation transformator, MultiLineString multiLineString)
 {
     return(new MultiLineString((from ls in multiLineString.Coordinates select ConvertLineString(transformator, ls)).ToList()));
 }
        private void Search()
        {
            bool allowedit = GetCurrentLayer() != null && GetCurrentLayer() == _EditLayer;

            dataGridView1.ReadOnly = !allowedit;
            btnOk.Enabled          = allowedit;
            txtMessage.ReadOnly    = !allowedit;
            textBox1.ReadOnly      = !allowedit;
            paste.Enabled          = allowedit;

            dataGridView1.Rows.Clear();
            comboBox1.Items.Clear();
            textBox1.Text   = "";
            textBox2.Text   = "";
            textBox3.Text   = "";
            txtMessage.Text = "";
            _LayerId        = GetCurrentLayer().ID;
            _Object         = GetSelectObject();
            _type           = GetCurrentLayerType();
            _Selected       = false;
            comboBox1.Items.Clear();
            comboBox1.Text  = "";
            textBox1.Text   = _Object.Text;
            txtMessage.Text = _Object.Message;
            _table          = MapDBClass.GetPropertyDefine(_type.ToString());
            string    sql       = "select * from " + MapDBClass.GetPropertyTableName(_MapId, _LayerId) + " where 1<>1";
            DataTable temptable = SqlHelper.Select(sql, null);

            for (int i = 4; i < temptable.Columns.Count; i++)
            {
                bool find = false;
                for (int j = 0; j < _table.Rows.Count; j++)
                {
                    if (temptable.Columns[i].ColumnName.ToLower() == _table.Rows[j]["PropertyName"].ToString().ToLower())
                    {
                        find = true;
                        break;
                    }
                }
                if (find)
                {
                    continue;
                }
                _table.Rows.Add(new object[] { i, _type.ToString(), temptable.Columns[i].ColumnName, temptable.Columns[i].DataType.Name, "0", "0", "", "1" });
            }
            SetDateList();
            textBox2.Text = "";
            textBox3.Text = "";
            Geometry selobject = _Object;

            if (selobject is Polygon)
            {
                Polygon polygon = selobject as Polygon;
                textBox2.Text = String.Format("{0:N5}", polygon.Area);
                textBox3.Text = String.Format("{0:N5}", polygon.ExteriorRing.Length);
            }
            else if (selobject is MultiPolygon)
            {
                MultiPolygon multiPolygon = selobject as MultiPolygon;
                textBox2.Text = String.Format("{0:N5}", multiPolygon.Area);
                textBox3.Text = String.Format("{0:N5}", multiPolygon.Length);
            }
            else if (selobject is LinearRing)
            {
                LinearRing line = selobject as LinearRing;
                textBox3.Text = String.Format("{0:N5}", line.Length);
            }
            else if (selobject is LineString)
            {
                LineString line = selobject as LineString;
                textBox3.Text = String.Format("{0:N5}", line.Length);
            }
            else if (selobject is MultiLineString)
            {
                MultiLineString line = selobject as MultiLineString;
                textBox3.Text = String.Format("{0:N5}", line.Length);
            }
        }
        public ToSqlGeographyTests()
        {
            point = new Point(new Position(53.2455662, 90.65464646));

            multiPoint = new MultiPoint(new List <Point>
            {
                new Point(new Position(52.379790828551016, 5.3173828125)),
                new Point(new Position(52.36721467920585, 5.456085205078125)),
                new Point(new Position(52.303440474272755, 5.386047363281249, 4.23))
            });
            lineString = new LineString(new List <IPosition>
            {
                new Position(52.379790828551016, 5.3173828125),
                new Position(52.36721467920585, 5.456085205078125),
                new Position(52.303440474272755, 5.386047363281249, 4.23)
            });
            multiLineString = new MultiLineString(new List <LineString>
            {
                new LineString(new List <IPosition>
                {
                    new Position(52.379790828551016, 5.3173828125),
                    new Position(52.36721467920585, 5.456085205078125),
                    new Position(52.303440474272755, 5.386047363281249, 4.23)
                }),
                new LineString(new List <IPosition>
                {
                    new Position(52.379790828551016, 5.3273828125),
                    new Position(52.36721467920585, 5.486085205078125),
                    new Position(52.303440474272755, 5.426047363281249, 4.23)
                })
            });

            /*
             * POLYGON (
             *	new Position(5.6718750056992775 43.179268827576763),
             *	new Position(5.7627938771963274 43.282358019007539),
             *	new Position(5.6827878158334473 43.399165901196014),
             *	new Position(5.7883490332690677 43.420263481346808),
             *	new Position(5.6569195891695419 43.575280226136485),
             *	new Position(5.7992059672926253 43.659928964120652),
             *	new Position(5.772453944482355 43.722182053435269),
             *	new Position(5.5305079449053451 43.659231446664869),
             *	new Position(4.7390611308576647 43.924068511657794),
             *	new Position(4.641909591242106 43.867477587972004),
             *	new Position(4.6268107341244811 43.688132623094383),
             *	new Position(4.4864081749462246 43.698853136943086),
             *	new Position(4.4608683979209367 43.58945970637793),
             *	new Position(4.2379330762447731 43.49708004345662),
             *	new Position(4.55238424144851 43.446971295015622),
             *	new Position(4.6618166942350943 43.346294896388663),
             *	new Position(4.8579247842437638 43.334654947962143),
             *	new Position(4.861467735270022 43.455412079597927),
             *	new Position(5.0545884574514082 43.326670147834825),
             *	new Position(5.3160671845314269 43.359760733800755),
             *	new Position(5.3405286722678431 43.214414007811236),
             *	new Position(5.6718750056992775 43.179268827576763),
             *
             *  new Position(5.0144408111937375, 43.555545986597537),
             *	new Position( 5.2267178460469337, 43.453922302237586),
             *	new Position( 5.0599489280101588, 43.404914999013144),
             *	new Position(5.0144408111937375, 43.555545986597537)
             */
            polygonWithHole = new Polygon(new List <LineString>
            {
                new LineString(new List <Position>
                {
                    new Position(43.179268827576763, 5.6718750056992775),
                    new Position(43.282358019007539, 5.7627938771963274),
                    new Position(43.399165901196014, 5.6827878158334473),
                    new Position(43.420263481346808, 5.7883490332690677),
                    new Position(43.575280226136485, 5.6569195891695419),
                    new Position(43.659928964120652, 5.7992059672926253),
                    new Position(43.722182053435269, 5.772453944482355),
                    new Position(43.659231446664869, 5.5305079449053451),
                    new Position(43.924068511657794, 4.7390611308576647),
                    new Position(43.867477587972004, 4.641909591242106),
                    new Position(43.688132623094383, 4.6268107341244811),
                    new Position(43.698853136943086, 4.4864081749462246),
                    new Position(43.58945970637793, 4.4608683979209367),
                    new Position(43.49708004345662, 4.2379330762447731),
                    new Position(43.446971295015622, 4.55238424144851),
                    new Position(43.346294896388663, 4.6618166942350943),
                    new Position(43.334654947962143, 4.8579247842437638),
                    new Position(43.455412079597927, 4.861467735270022),
                    new Position(43.326670147834825, 5.0545884574514082),
                    new Position(43.359760733800755, 5.3160671845314269),
                    new Position(43.214414007811236, 5.3405286722678431),
                    new Position(43.179268827576763, 5.6718750056992775)
                }),
                new LineString(new List <Position>
                {
                    new Position(43.555545986597537, 5.0144408111937375),
                    new Position(43.453922302237586, 5.2267178460469337),
                    new Position(43.404914999013144, 5.0599489280101588),
                    new Position(43.555545986597537, 5.0144408111937375)
                })
            });
            polygonWithHoleReverseWinding = new Polygon(new List <LineString>
            {
                new LineString(polygonWithHole.Coordinates[0].Coordinates.Select(c => (Position)c).Reverse().ToList()),
                new LineString(polygonWithHole.Coordinates[1].Coordinates.Select(c => (Position)c).Reverse().ToList())
            });
            polygon = new Polygon(new List <LineString>
            {
                new LineString(new List <Position>
                {
                    new Position(52.379790828551016, 5.3173828125),
                    new Position(52.36721467920585, 5.456085205078125),
                    new Position(52.303440474272755, 5.386047363281249, 4.23),
                    new Position(52.379790828551016, 5.3173828125)
                })
            });

            multiPolygon = new MultiPolygon(new List <Polygon>
            {
                new Polygon(new List <LineString>
                {
                    new LineString(new List <IPosition>
                    {
                        new Position(52.959676831105995, -2.6797102391514338),
                        new Position(52.9608756693609, -2.6769029474483279),
                        new Position(52.908449372833715, -2.6079763270327119),
                        new Position(52.891287242948195, -2.5815104708998668),
                        new Position(52.875476700983896, -2.5851645010668989),
                        new Position(52.882954723868622, -2.6050779098387191),
                        new Position(52.875255907042678, -2.6373482332006359),
                        new Position(52.878791122091066, -2.6932445076063951),
                        new Position(52.89564268523565, -2.6931334629377890),
                        new Position(52.930592009390175, -2.6548779332193022),
                        new Position(52.959676831105995, -2.6797102391514338)
                    })
                }),
                new Polygon(new List <LineString>
                {
                    new LineString(new List <IPosition>
                    {
                        new Position(52.89610842810761, -2.69628632041613),
                        new Position(52.8894641454077, -2.75901233808515),
                        new Position(52.89938894657412, -2.7663172788742449),
                        new Position(52.90253773227807, -2.804554822840895),
                        new Position(52.929801009654575, -2.83848602260174),
                        new Position(52.94013913205788, -2.838979264607087),
                        new Position(52.937353122653533, -2.7978187468478741),
                        new Position(52.920394929466184, -2.772273870352612),
                        new Position(52.926572918779222, -2.6996509024137052),
                        new Position(52.89610842810761, -2.69628632041613)
                    })
                })
            });

            geomCollection = new GeometryCollection(new List <IGeometryObject>
            {
                point,
                multiPoint,
                lineString,
                multiLineString,
                polygon,
                multiPolygon
            });

            feature = new Feature.Feature(polygon, new Dictionary <string, object>()
            {
                { "Key", "Value" }
            }, "Id");

            featureCollection = new FeatureCollection(new List <Feature.Feature> {
                feature, new Feature.Feature(multiPolygon, null)
            });
        }
Beispiel #37
0
 /// <summary>
 ///     Converts a MultiLineString to &lt;MultiLineString Text&gt;
 ///     format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiLineString">The MultiLineString to process.</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 private static void AppendMultiLineStringText(MultiLineString multiLineString, StringWriter writer)
 {
     if ((multiLineString == null) || multiLineString.IsEmpty())
         writer.Write("EMPTY");
     else
     {
         writer.Write("(");
         for (var i = 0; i < multiLineString.LineStrings.Count; i++)
         {
             if (i > 0)
                 writer.Write(", ");
             AppendLineStringText(multiLineString[i], writer);
         }
         writer.Write(")");
     }
 }
Beispiel #38
0
        public override void Draw(IScreenDisplay display)
        {
            IScreenDisplayDraw displayDraw = display as IScreenDisplayDraw;

            if (ShapeType == RgEnumShapeType.RgPoint)
            {
                for (int i = 0; i < mGeometries.Count; i++)
                {
                    Feature feat = mGeometries[i];
                    RGeos.Geometries.RgPoint pt = feat.Shape as RGeos.Geometries.RgPoint;
                    if (pt != null)
                    {
                        if (feat.IsSelected == false)
                        {
                            displayDraw.DrawPoint(pt, new Pen(Color.Red), new SolidBrush(Color.Red));
                        }
                        else
                        {
                            displayDraw.DrawPoint(pt, new Pen(Color.LightBlue), new SolidBrush(Color.LightBlue));
                        }
                    }
                }
            }
            if (ShapeType == RgEnumShapeType.RgLineString)
            {
                for (int i = 0; i < mGeometries.Count; i++)
                {
                    Feature    feat = mGeometries[i];
                    LineString pt   = feat.Shape as LineString;
                    if (pt != null)
                    {
                        if (feat.IsSelected == false)
                        {
                            displayDraw.DrawLineString(pt, new Pen(Color.Red));
                        }
                        else
                        {
                            displayDraw.DrawLineString(pt, new Pen(Color.LightBlue));
                        }
                        // display as r
                    }
                }
            }
            if (ShapeType == RgEnumShapeType.RgMultiLineString)
            {
                for (int i = 0; i < mGeometries.Count; i++)
                {
                    Feature         feat = mGeometries[i];
                    MultiLineString pt   = feat.Shape as MultiLineString;
                    if (pt != null)
                    {
                        if (feat.IsSelected == false)
                        {
                            displayDraw.DrawMultiLineString(pt, new Pen(Color.Red));
                        }
                        else
                        {
                            displayDraw.DrawMultiLineString(pt, new Pen(Color.LightBlue));
                        }
                    }
                }
            }
            if (ShapeType == RgEnumShapeType.RgPolygon)
            {
                for (int i = 0; i < mGeometries.Count; i++)
                {
                    Feature feat    = mGeometries[i];
                    Polygon polygon = feat.Shape as Polygon;
                    if (polygon != null)
                    {
                        Pen   mPen  = new Pen(Color.Red);
                        Brush brush = new SolidBrush(Color.Blue);
                        if (feat.IsSelected == false)
                        {
                            displayDraw.DrawPolygon(polygon, brush, mPen, false);
                        }
                        else
                        {
                            displayDraw.DrawPolygon(polygon, brush, new Pen(Color.LightBlue), false);
                        }
                    }
                }
            }
        }
Beispiel #39
0
 static string GeometryToWktString(MultiLineString multiLineString)
 {
     return(string.Format("({0})", string.Join(",", multiLineString.Coordinates.Select(GeometryToWktString))));
 }
Beispiel #40
0
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing existingValue of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>
        /// Deserialized object.
        /// </returns>
        public override object ReadJson(
            JsonReader reader,
            Type objectType,
            object existingValue,
            JsonSerializer serializer)
        {
            JToken token = JToken.Load(reader);

            if (token.Type == JTokenType.Null)
            {
                return(null);
            }

            if (token.Type != JTokenType.Object)
            {
                throw new JsonSerializationException(RMResources.SpatialInvalidGeometryType);
            }

            JToken typeToken = token["type"];

            if (typeToken.Type != JTokenType.String)
            {
                throw new JsonSerializationException(RMResources.SpatialInvalidGeometryType);
            }

            Geometry result;

            switch (typeToken.Value <string>())
            {
            case "Point":
                result = new Point();
                break;

            case "MultiPoint":
                result = new MultiPoint();
                break;

            case "LineString":
                result = new LineString();
                break;

            case "MultiLineString":
                result = new MultiLineString();
                break;

            case "Polygon":
                result = new Polygon();
                break;

            case "MultiPolygon":
                result = new MultiPolygon();
                break;

            case "GeometryCollection":
                result = new GeometryCollection();
                break;

            default:
                throw new JsonSerializationException(RMResources.SpatialInvalidGeometryType);
            }

            serializer.Populate(token.CreateReader(), result);
            return(result);
        }
 public void Write_WritesMultiLineStringsOfAllDimensions(MultiLineString toWrite, string expectedWkt)
 {
     this.TestWriteGeometry(toWrite, expectedWkt);
 }
 public void MultiLsToByteArray()
 {
     Random rnd = new Random();
     LineString[] ls = new LineString[40];
     for (int ii = 0; ii < 40; ii++)
     {
         Coordinate[] coord = new Coordinate[36];
         for (int i = 0; i < 36; i++)
         {
             coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
         }
         ls[ii] = new LineString(coord);
     }
     MultiLineString mls = new MultiLineString(ls);
     Byte[] vals = mls.ToBinary();
     WkbReader wkr = new WkbReader();
     IGeometry g = wkr.Read(vals);
     MultiLineString mlscheck = g as MultiLineString;
     if (mlscheck != null)
     {
         for (int ii = 0; ii < mls.Coordinates.Count; ii++)
         {
             Assert.AreEqual(mls.Coordinates[ii].X, mlscheck.Coordinates[ii].X);
             Assert.AreEqual(mls.Coordinates[ii].Y, mlscheck.Coordinates[ii].Y);
         }
     }
     else
     {
         Assert.Fail("The test failed bc the check multilinestring was null.");
     }
 }
Beispiel #43
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="multiLineString"></param>
 /// <returns></returns>
 protected virtual int SetByteStreamLength(MultiLineString multiLineString)
 {
     int count = INIT_VALUE;
     foreach (LineString ls in multiLineString.Geometries)
         count += SetByteStreamLength(ls);
     return count;
 }
Beispiel #44
0
        async ValueTask <GeoJSONObject> ReadGeometryCore(NpgsqlReadBuffer buf, bool async, BoundingBoxBuilder?boundingBox)
        {
            await buf.Ensure(SizeOfHeader, async);

            var littleEndian = buf.ReadByte() > 0;
            var type         = (EwkbGeometryType)buf.ReadUInt32(littleEndian);

            GeoJSONObject geometry;
            NamedCRS?     crs = null;

            if (HasSrid(type))
            {
                await buf.Ensure(4, async);

                crs = GetCrs(buf.ReadInt32(littleEndian));
            }

            switch (type & EwkbGeometryType.BaseType)
            {
            case EwkbGeometryType.Point:
            {
                await buf.Ensure(SizeOfPoint(type), async);

                var position = ReadPosition(buf, type, littleEndian);
                boundingBox?.Accumulate(position);
                geometry = new Point(position);
                break;
            }

            case EwkbGeometryType.LineString:
            {
                await buf.Ensure(SizeOfLength, async);

                var coordinates = new Position[buf.ReadInt32(littleEndian)];
                for (var i = 0; i < coordinates.Length; ++i)
                {
                    await buf.Ensure(SizeOfPoint(type), async);

                    var position = ReadPosition(buf, type, littleEndian);
                    boundingBox?.Accumulate(position);
                    coordinates[i] = position;
                }
                geometry = new LineString(coordinates);
                break;
            }

            case EwkbGeometryType.Polygon:
            {
                await buf.Ensure(SizeOfLength, async);

                var lines = new LineString[buf.ReadInt32(littleEndian)];
                for (var i = 0; i < lines.Length; ++i)
                {
                    var coordinates = new Position[buf.ReadInt32(littleEndian)];
                    for (var j = 0; j < coordinates.Length; ++j)
                    {
                        await buf.Ensure(SizeOfPoint(type), async);

                        var position = ReadPosition(buf, type, littleEndian);
                        boundingBox?.Accumulate(position);
                        coordinates[j] = position;
                    }
                    lines[i] = new LineString(coordinates);
                }
                geometry = new Polygon(lines);
                break;
            }

            case EwkbGeometryType.MultiPoint:
            {
                await buf.Ensure(SizeOfLength, async);

                var points = new Point[buf.ReadInt32(littleEndian)];
                for (var i = 0; i < points.Length; ++i)
                {
                    await buf.Ensure(SizeOfHeader + SizeOfPoint(type), async);

                    await buf.Skip(SizeOfHeader, async);

                    var position = ReadPosition(buf, type, littleEndian);
                    boundingBox?.Accumulate(position);
                    points[i] = new Point(position);
                }
                geometry = new MultiPoint(points);
                break;
            }

            case EwkbGeometryType.MultiLineString:
            {
                await buf.Ensure(SizeOfLength, async);

                var lines = new LineString[buf.ReadInt32(littleEndian)];
                for (var i = 0; i < lines.Length; ++i)
                {
                    await buf.Ensure(SizeOfHeaderWithLength, async);

                    await buf.Skip(SizeOfHeader, async);

                    var coordinates = new Position[buf.ReadInt32(littleEndian)];
                    for (var j = 0; j < coordinates.Length; ++j)
                    {
                        await buf.Ensure(SizeOfPoint(type), async);

                        var position = ReadPosition(buf, type, littleEndian);
                        boundingBox?.Accumulate(position);
                        coordinates[j] = position;
                    }
                    lines[i] = new LineString(coordinates);
                }
                geometry = new MultiLineString(lines);
                break;
            }

            case EwkbGeometryType.MultiPolygon:
            {
                await buf.Ensure(SizeOfLength, async);

                var polygons = new Polygon[buf.ReadInt32(littleEndian)];
                for (var i = 0; i < polygons.Length; ++i)
                {
                    await buf.Ensure(SizeOfHeaderWithLength, async);

                    await buf.Skip(SizeOfHeader, async);

                    var lines = new LineString[buf.ReadInt32(littleEndian)];
                    for (var j = 0; j < lines.Length; ++j)
                    {
                        var coordinates = new Position[buf.ReadInt32(littleEndian)];
                        for (var k = 0; k < coordinates.Length; ++k)
                        {
                            await buf.Ensure(SizeOfPoint(type), async);

                            var position = ReadPosition(buf, type, littleEndian);
                            boundingBox?.Accumulate(position);
                            coordinates[k] = position;
                        }
                        lines[j] = new LineString(coordinates);
                    }
                    polygons[i] = new Polygon(lines);
                }
                geometry = new MultiPolygon(polygons);
                break;
            }

            case EwkbGeometryType.GeometryCollection:
            {
                await buf.Ensure(SizeOfLength, async);

                var elements = new IGeometryObject[buf.ReadInt32(littleEndian)];
                for (var i = 0; i < elements.Length; ++i)
                {
                    elements[i] = (IGeometryObject) await ReadGeometryCore(buf, async, boundingBox);
                }
                geometry = new GeometryCollection(elements);
                break;
            }

            default:
                throw UnknownPostGisType();
            }

            geometry.CRS = crs;
            return(geometry);
        }
Beispiel #45
0
 /// <summary>
 /// Converts a MultiLineString to &lt;MultiLineString Tagged
 /// Text&gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiLineString">The MultiLineString to process</param>
 /// <param name="level"></param>
 /// <param name="writer">The output stream writer to Append to.</param>
 protected void AppendMultiLineStringTaggedText(MultiLineString multiLineString, int level, StringWriter writer)
 {
     writer.Write("MULTILINESTRING ");
     AppendMultiLineStringText(multiLineString, level, false, writer);
 }
Beispiel #46
0
 public FuzzyPointLocator(Geometry g, double boundaryDistanceTolerance)
 {
     _g = g;
     _boundaryDistanceTolerance = boundaryDistanceTolerance;
     _linework = ExtractLinework(g);
 }
Beispiel #47
0
        private void WriteMultiLineString(MultiLineString mls, WKBByteOrder byteOrder)
        {
            // Write byte order
            _writer.Write((byte)byteOrder);

            // Write type
            this.WriteType(mls, byteOrder);

            //Write the number of linestrings.
            this.Write((uint)mls.getNumGeometries(), byteOrder);

            //Loop on the number of linestrings.
            for (int i = 0; i < mls.getNumGeometries(); i++)
            {
                // Write each linestring.
                this.WriteLineString((LineString)mls.getGeometryN(i), byteOrder, true);
            }
        }
Beispiel #48
0
        public void CanReadWriteMultiPartPolylineXyz()
        {
            // The spatial reference is important to avoid small differences in
            // coordinates (snap to spatial reference!)
            ISpatialReference sr = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95, WellKnownVerticalCS.LHN95);

            var points1 = new WKSPointZ[4];

            points1[0] = new WKSPointZ {
                X = 2600000, Y = 1200000, Z = 456
            };
            points1[1] = new WKSPointZ {
                X = 2600030, Y = 1200020, Z = 457
            };
            points1[2] = new WKSPointZ {
                X = 2600020, Y = 1200030, Z = 459
            };
            points1[3] = new WKSPointZ {
                X = 2600040, Y = 1200040, Z = 416
            };

            IPolyline polyline1 = GeometryFactory.CreatePolyline(points1, sr);

            var points2 = new WKSPointZ[4];

            points2[0] = new WKSPointZ {
                X = 2610000, Y = 1200000, Z = 656
            };
            points2[1] = new WKSPointZ {
                X = 2610030, Y = 1200020, Z = 657
            };
            points2[2] = new WKSPointZ {
                X = 2610020, Y = 1200030, Z = 659
            };
            points2[3] = new WKSPointZ {
                X = 2610040, Y = 1200040, Z = 616
            };

            IPolyline polyline2 = GeometryFactory.CreatePolyline(points2, sr);

            IPolyline polyline = (IPolyline)GeometryUtils.Union(polyline1, polyline2);

            GeometryUtils.Simplify(polyline);

            WkbGeometryWriter writer = new WkbGeometryWriter();

            byte[] wkb = writer.WritePolyline(polyline);

            // Wkx
            var             ordinates       = Ordinates.Xyz;
            MultiLineString multiLineString = new MultiLineString(
                new List <LineString>
            {
                ToWkxLineString(points1, ordinates), ToWkxLineString(points2, ordinates)
            });

            byte[] wkx = ToChristianSchwarzWkb(multiLineString);
            Assert.AreEqual(wkx, wkb);

            // Bonus test: Geom
            WkbGeomWriter  geomWriter    = new WkbGeomWriter();
            MultiPolycurve multiPlycurve = GeometryConversionUtils.CreateMultiPolycurve(polyline);

            byte[] wkbGeom = geomWriter.WriteMultiLinestring(multiPlycurve, ordinates);
            Assert.AreEqual(wkb, wkbGeom);

            WkbGeometryReader reader = new WkbGeometryReader();

            IPolyline restored = reader.ReadPolyline(new MemoryStream(wkb));

            Assert.IsTrue(GeometryUtils.AreEqual(polyline, restored));

            // Geom:
            WkbGeomReader geomReader = new WkbGeomReader();

            Assert.IsTrue(
                multiPlycurve.Equals(geomReader.ReadMultiPolycurve(new MemoryStream(wkbGeom))));
        }
Beispiel #49
0
 private void WriteMultiLineString(MultiLineString multiLineString, WkbBinaryWriter writer)
 {
     WriteGeometryType(multiLineString, WkbGeometryType.MultiLineString, writer);
     writer.Write((uint)multiLineString.Geometries.Count);
     foreach (var linestring in multiLineString.Geometries.Cast<LineString>())
         WriteCoordinates(linestring.Coordinates, writer);
 }
Beispiel #50
0
        /// <summary>
        ///     Creates a <see cref="MultiLineString" /> 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
        ///     MultiLineString Text
        /// </param>
        /// <returns>a <see cref="MultiLineString" /> specified by the next token in the stream</returns>
        private static MultiLineString ReadMultiLineStringText(WktStreamTokenizer tokenizer)
        {
            var lines = new MultiLineString();
            var nextToken = GetNextEmptyOrOpener(tokenizer);
            if (nextToken == "EMPTY")
                return lines;

            lines.LineStrings.Add(ReadLineStringText(tokenizer));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                lines.LineStrings.Add(ReadLineStringText(tokenizer));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return lines;
        }
Beispiel #51
0
 /// <summary>
 /// Converts a MultiLineString to &lt;MultiLineString Tagged
 /// Text&gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiLineString">The MultiLineString to process</param>
 /// <param name="level"></param>
 /// <param name="writer">The output stream writer to Append to.</param>
 protected void AppendMultiLineStringTaggedText( MultiLineString multiLineString, int level, StringWriter writer )
 {
     writer.Write("MULTILINESTRING ");
     AppendMultiLineStringText(multiLineString, level, false, writer);
 }
Beispiel #52
0
        public override Object Clone()
        {
            MultiLineString ml = (MultiLineString)base.Clone();

            return(ml);
        }
Beispiel #53
0
        /// <summary>
        ///     Writes a multilinestring.
        /// </summary>
        /// <param name="mls">The multilinestring to be written.</param>
        /// <param name="bWriter">Stream to write to.</param>
        /// <param name="byteorder">Byte order</param>
        private static void WriteMultiLineString(MultiLineString mls, BinaryWriter bWriter, WkbByteOrder byteorder)
        {
            //Write the number of linestrings.
            WriteUInt32((uint) mls.LineStrings.Count, bWriter, byteorder);

            //Loop on the number of linestrings.
            foreach (var ls in mls.LineStrings)
            {
                //Write LineString Header
                bWriter.Write((byte) byteorder);
                WriteUInt32((uint) WKBGeometryType.WKBLineString, bWriter, byteorder);
                //Write each linestring.
                WriteLineString(ls, bWriter, byteorder);
            }
        }
Beispiel #54
0
 /// <summary>
 /// Converts a MultiLineString to &lt;MultiLineString Tagged
 /// Text&gt; format, then Appends it to the writer.
 /// </summary>
 /// <param name="multiLineString">The MultiLineString to process</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 protected void AppendMultiLineStringTaggedText(MultiLineString multiLineString, TextWriter writer)
 {
     AppendPath(writer);
     AppendMultiLineStringText(multiLineString, writer);
     AppendEndPath(writer);
 }
Beispiel #55
0
        public static void Write(MultiLineString lines, TextWriter writer)
        {
            if (lines == null)
                return;
            if (writer == null)
                throw new ArgumentNullException("writer", "A valid text writer object is required");

            Write(lines, CreateWriter(writer));
        }
Beispiel #56
0
        public void GivenMultiLineStringWhenCreatedThenTypeShouldBeMultiLineString()
        {
            var shape = new MultiLineString();

            Assert.AreEqual(ShapeTypeEnum.MultiLineString, shape.Type);
        }
Beispiel #57
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="geom"></param>
 /// <returns></returns>
 public virtual bool IsSimple(MultiLineString geom)
 {
     return IsSimpleLinearGeometry(geom);
 }
Beispiel #58
0
 public void Write_WritesMultiLineStringsOfAllDimensions(MultiLineString toWrite, string expectedWkt)
 {
     this.TestWriteGeometry(toWrite, expectedWkt);
 }
Beispiel #59
0
 private bool TryParseMultiLineString(JsonObject obj, out object result)
 {
     var coordinates = obj["coordinates"] as JsonArray;
     Coordinate[][] co;
     if (coordinates != null && TryParseCoordinateArrayArray(coordinates, out co))
     {
         result = new MultiLineString(co.Select(x => new LineString(x)));
         return true;
     }
     result = null;
     return false;
 }
Beispiel #60
0
 public void EnveloptMls()
 {
     var rnd = new Random();
     var ls = new LineString[40];
     var lscheck = new GeoAPI.Geometries.ILineString[40];
     var gf = new NetTopologySuite.Geometries.GeometryFactory();
     for (var ii = 0; ii < 40; ii++)
     {
         var coord = new Coordinate[36];
         var coordcheck = new GeoAPI.Geometries.Coordinate[36];
         for (var i = 0; i < 36; i++)
         {
             coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
             var x = coord[i].X;
             var y = coord[i].Y;
             var c = new GeoAPI.Geometries.Coordinate(x, y);
             coordcheck[i] = c;
         }
         ls[ii] = new LineString(coord);
         lscheck[ii] = gf.CreateLineString(coordcheck);
     }
     var mls = new MultiLineString(ls);
     var mlscheck = gf.CreateMultiLineString(lscheck);
     Assert.AreEqual(mls.Envelope.Width, mlscheck.EnvelopeInternal.Width);
     Assert.AreEqual(mls.Envelope.Height, mlscheck.EnvelopeInternal.Height);
 }