Beispiel #1
0
 public void Multils()
 {
     Random rnd = new Random();
     LineString[] ls = new LineString[40];
     GeoAPI.Geometries.ILineString[] lscheck = new GeoAPI.Geometries.ILineString[40];
     GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory gf = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
     for (int ii = 0; ii < 40; ii++)
     {
         Coordinate[] coord = new Coordinate[36];
         GeoAPI.Geometries.ICoordinate[] coordcheck = new GeoAPI.Geometries.ICoordinate[36];
         for (int i = 0; i < 36; i++)
         {
             coord[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
             double x = coord[i].X;
             double y = coord[i].Y;
             GisSharpBlog.NetTopologySuite.Geometries.Coordinate c = new GisSharpBlog.NetTopologySuite.Geometries.Coordinate(x, y);
             coordcheck[i] = c;
         }
         ls[ii] = new LineString(coord);
         lscheck[ii] = gf.CreateLineString(coordcheck);
     }
     MultiLineString mls = new MultiLineString(ls);
     GeoAPI.Geometries.IMultiLineString mlscheck = gf.CreateMultiLineString(lscheck);
     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);
     }
     Assert.AreEqual(mls.NumGeometries, mlscheck.NumGeometries);
 }
Beispiel #2
0
        private void VisualizeEnvelope()
        {
            if (!Config.Settings.Map.StoreBoundingBoxes)
            {
                return;
            }
            var coordinates = new[]
            {
                new Coordinate(BoundingBox.Left, BoundingBox.Bottom),
                new Coordinate(BoundingBox.Left, BoundingBox.Top),
                new Coordinate(BoundingBox.Right, BoundingBox.Top),
                new Coordinate(BoundingBox.Right, BoundingBox.Top),
                new Coordinate(BoundingBox.Right, BoundingBox.Bottom),
                new Coordinate(BoundingBox.Left, BoundingBox.Bottom)
            };
            var geom = new LineString(coordinates);

            var bbox = new Geometri.Område(-2, AreaType.BoundingBox)
            {
                Number = -2,
                Name   = "envelope",
                kind   = "envelope"
            };

            UpdateGeometry(bbox, geom);
        }
        public RuleSymbolizerPreview()
        {
            InitializeComponent();
            mapPreview.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            featureSetPoint.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            featureSetLine.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            featureSetPolygon.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            DotSpatial.Topology.LineString ls = new DotSpatial.Topology.LineString(new Coordinate[] { new Coordinate(-45D, 0D), new Coordinate(45D, 0D) });
            featureSetLine.AddFeature(ls);
            DotSpatial.Topology.Polygon polygon = new DotSpatial.Topology.Polygon(new LinearRing(new Coordinate[] {
                new Coordinate(90, -25), new Coordinate(135, -25), new Coordinate(135,25),new Coordinate(90, 25),new Coordinate(90, -25)
            }));
            featureSetPolygon.AddFeature(polygon);

            DotSpatial.Topology.Point point = new DotSpatial.Topology.Point(new Coordinate(-90D, 0D));
            featureSetPoint.AddFeature(point);

            layerPoint = new MapPointLayer(featureSetPoint);
            layerLine = new MapLineLayer(featureSetLine);
            layerPolygon = new MapPolygonLayer(featureSetPolygon);
               // layerPoint.Symbolizer = new DotSpatial.Symbology.PointSymbolizer(System.Drawing.Color.DarkBlue, DotSpatial.Symbology.PointShape.Triangle, 20);

            mapPreview.Layers.Add(layerLine);
            mapPreview.Layers.Add(layerPolygon);
            mapPreview.Layers.Add(layerPoint);
            this.SizeChanged += RuleSymbolizerPreview_SizeChanged;
            mapPreview.ViewExtents = new Extent(-180, -180, 180, 180);
            mapPreview.ViewExtents.SetCenter(new Coordinate(0, 0));
        }
        private static Geometry From(geoJson.MultiLineString geometry)
        {
            var lineStrings = geometry.Coordinates;
            var p           = new LineString[lineStrings.Count];

            for (var i = 0; i < lineStrings.Count; i++)
            {
                p[i] = From(lineStrings[i]);
            }
            return(new MultiLineString(p));
        }
 public Polygon TwoPieces(Polygon polygon1, Polygon polygon2, LineString line1, LineString line2)
 {
     if (polygon1.Intersects(polygon2) || polygon1.Touches(polygon2))
     {
         return polygon1.Union(polygon2) as Polygon;
     }
     else
     {
         var pg = GetConvexHull(line1, line2);
         return pg.Union(polygon1).Union(polygon2) as Polygon;
     }
 }
Beispiel #6
0
 /// <summary>
 /// The Voronoi Graph calculation creates a delaunay tesselation where
 /// each point is effectively converted into triangles.
 /// </summary>
 /// <param name="points">The points to use for creating the tesselation.</param>
 /// <returns>The generated line featureset.</returns>
 public static IFeatureSet DelaunayLines(IFeatureSet points)
 {
     double[] vertices = points.Vertex;
     VoronoiGraph gp = Fortune.ComputeVoronoiGraph(vertices);
     FeatureSet result = new FeatureSet();
     foreach (VoronoiEdge edge in gp.Edges)
     {
         Coordinate c1 = edge.RightData.ToCoordinate();
         Coordinate c2 = edge.LeftData.ToCoordinate();
         LineString ls = new LineString(new List<Coordinate> { c1, c2 });
         Feature f = new Feature(ls);
         result.AddFeature(f);
     }
     return result;
 }
Beispiel #7
0
        static string GetLineStringPath(LineString lineString)
        {
            var points = new List<string>();

            foreach (var coordinate in lineString.Coordinates)
            {
                var x = (0 + (coordinate.X)) / 10000;
                var y = (0 + (coordinate.Y * -1)) / 10000;
                var point = x.ToString(CultureInfo.InvariantCulture) + "," + y.ToString(CultureInfo.InvariantCulture);

                points.Add(point);
            }

            var @join = string.Join(" ", points);
            return @join;
        }
Beispiel #8
0
        /// <summary>
        /// The Voronoi Graph calculation creates the lines that form a voronoi diagram.
        /// </summary>
        /// <param name="points">The points to use for creating the tesselation.</param>
        /// <returns>An IFeatureSet that is the resulting set of lines in the diagram.</returns>
        public static IFeatureSet VoronoiLines(IFeatureSet points)
        {
            double[] vertices = points.Vertex;
            VoronoiGraph gp = Fortune.ComputeVoronoiGraph(vertices);

            HandleBoundaries(gp, points.Extent.ToEnvelope());

            FeatureSet result = new FeatureSet();
            foreach (VoronoiEdge edge in gp.Edges)
            {
                Coordinate c1 = edge.VVertexA.ToCoordinate();
                Coordinate c2 = edge.VVertexB.ToCoordinate();
                LineString ls = new LineString(new List<Coordinate> { c1, c2 });
                Feature f = new Feature(ls);
                result.AddFeature(f);
            }
            return result;
        }
        public void ConvexHull_由兩條線段產生多邊形()
        {
            var coords1 = new List<Coordinate>
            {
                new Coordinate(1, 1),
                new Coordinate(1, 2)
            };
            var line1 = new LineString(coords1);
            var coords2 = new List<Coordinate>
            {
                new Coordinate(2, 1),
                new Coordinate(2, 2)
            };
            var line2 = new LineString(coords2);

            var merger = new MergerCustom();
            var result = merger.GetConvexHull(line1, line2);

            Assert.NotNull(result);
            Assert.AreEqual(1.0, result.Area, 0.00000001);

        }
Beispiel #10
0
 internal FeatureSet CreateFeatureSet()
 {
     FeatureSet featureSet = new FeatureSet(FeatureType.Line);
     featureSet.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;
     foreach (ReferentielMultiLineString mls in this.MultiLineStrings)
     {
         List<LineString> lineStrings = new List<LineString>();
         foreach (ReferentielLineString ls in mls.LineStrings)
         {
             List<Coordinate> coordinates = new List<Coordinate>();
             for (int i = 0; i < (ls.Segements.Count - 1); i++)
             {
                 coordinates.Add(ls.Segements[i].CoordDeb);
             }
             coordinates.Add(ls.Segements.Last().CoordDeb);
             coordinates.Add(ls.Segements.Last().CoordFin);
             LineString fsLs = new LineString(coordinates);
             lineStrings.Add(fsLs);
         }
         MultiLineString fsMls = new MultiLineString(lineStrings);
         featureSet.AddFeature(fsMls);
     }
     return featureSet;
 }
        public Polygon GetConvexHull(LineString line1, LineString line2)
        {
            var coords1 = new List<Coordinate>
            {
                line1.StartPoint.Coordinate,
                line1.EndPoint.Coordinate,
                line2.StartPoint.Coordinate,
                line2.EndPoint.Coordinate,
                line1.StartPoint.Coordinate
            };
            var pg1 = new Polygon(coords1);

            var coords2 = new List<Coordinate>
            {
                line1.StartPoint.Coordinate,
                line1.EndPoint.Coordinate,
                line2.EndPoint.Coordinate,
                line2.StartPoint.Coordinate,
                line1.StartPoint.Coordinate
            };
            var pg2 = new Polygon(coords2);
            return pg1.Area > pg2.Area ? pg1 : pg2;
            //return line1.Union(line2).ConvexHull() as Polygon;
        }
Beispiel #12
0
        private void DrawLine(object sender, EventArgs e)
        {
            double xmin = App.Map.Extent.MinX;
            double xmax = App.Map.Extent.MaxX;
            double ymin = App.Map.Extent.MinY;
            double ymax = App.Map.Extent.MaxY;

            Feature f = new Feature();
            FeatureSet fs = new FeatureSet(f.FeatureType);

            // TODO change to List<Coordinate>... 
            Coordinate[] coord = new Coordinate[2];
            coord[0] = new Coordinate(xmin, ymin);
            coord[1] = new Coordinate(xmin, ymax);
            LineString ls = new LineString(coord);
            f = new Feature(ls);
            fs.Features.Add(f);

            coord[0] = new Coordinate(xmin / 2, ymin);
            coord[1] = new Coordinate(xmin / 2, ymax);
            ls = new LineString(coord);
            f = new Feature(ls);
            fs.Features.Add(f);

            coord[0] = new Coordinate(xmin, ymax);
            coord[1] = new Coordinate(xmax, ymax);
            ls = new LineString(coord);
            f = new Feature(ls);
            fs.Features.Add(f);

            coord[0] = new Coordinate(xmin, ymax / 2);
            coord[1] = new Coordinate(xmax, ymax / 2);
            ls = new LineString(coord);
            f = new Feature(ls);
            fs.Features.Add(f);

            //App.Map.AddFeatureLayer 


            fs.SaveAs("C:\\Temp\\LineTest.shp", true);
        }
Beispiel #13
0
 private void linestringCS(object sender, EventArgs e)
 {
     //creates a new coordinate array
     Coordinate[] coords = new Coordinate[36];
     //creates a random point variable
     Random rnd = new Random();
     //a for loop that generates a new random X and Y value and feeds those values into the coordinate array
     for (int i = 0; i < 36; i++)
     {
         coords[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);
     }
     //creates a new linstring from the array of coordinates
     LineString ls = new LineString(coords);
     //new variable for the length of the linstring
     Double length;
     length = ls.Length;
     //Displays the length of the linstring
     MessageBox.Show("The length of the linstring is: " + length);
 }
Beispiel #14
0
        private void MlsCS(object sender, EventArgs e)
        {
            Random rnd = new Random();
            MultiLineString Mls = new MultiLineString();
            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);
            }
            Mls = new MultiLineString(ls);

            FeatureSet fs = new FeatureSet(Mls.FeatureType);
            fs.Features.Add(Mls);
            fs.SaveAs("C:\\Temp\\Mls.shp", true);
        }
Beispiel #15
0
 /// <summary>
 /// Creates a <c>MultiLineString</c> using the given <c>LineStrings</c>; a null or empty
 /// array will create an empty MultiLineString.
 /// </summary>
 /// <param name="lineStrings">LineStrings, each of which may be empty but not null-</param>
 public virtual IMultiLineString CreateMultiLineString(IBasicLineString[] lineStrings)
 {
     if (lineStrings == null)
     {
         return new MultiLineString();
     }
     int count = lineStrings.Length;
     LineString[] ls = new LineString[count];
     for (int i = 0; i < count; i++)
     {
         ls[i] = new LineString(lineStrings[i]);
     }
     MultiLineString temp = new MultiLineString(ls);
     return temp;
 }
        /// <summary>
        /// If the input geometry is a singular basic geometry, this will become a collection of 1 geometry.
        /// If the input geometry is a multi- basic geometry, this will simply ensure that each member
        /// is upgraded to a full geometry.
        /// </summary>
        /// <param name="inGeometry"></param>
        /// <param name="inFactory"></param>
        public GeometryCollection(IBasicGeometry inGeometry, IGeometryFactory inFactory)
            : base(inFactory)
        {
            if (inGeometry == null)
            {
                _geometries = new IGeometry[] { };
                return;
            }

            IBasicPolygon pg = inGeometry.GetBasicGeometryN(0) as IBasicPolygon;
            if (pg != null)
            {
                _geometries = new IGeometry[inGeometry.NumGeometries];
                for (int iGeom = 0; iGeom < inGeometry.NumGeometries; iGeom++)
                {
                    pg = inGeometry.GetBasicGeometryN(iGeom) as IBasicPolygon;
                    _geometries[iGeom] = new Polygon(pg);
                }
                return;
            }
            IBasicPoint pt = inGeometry.GetBasicGeometryN(0) as IBasicPoint;
            if (pt != null)
            {
                _geometries = new IGeometry[inGeometry.NumGeometries];
                for (int iGeom = 0; iGeom < inGeometry.NumGeometries; iGeom++)
                {
                    pt = inGeometry.GetBasicGeometryN(iGeom) as IBasicPoint;
                    _geometries[iGeom] = new Point(pt);
                }
                return;
            }
            IBasicLineString ls = inGeometry.GetBasicGeometryN(0) as IBasicLineString;
            if (ls != null)
            {
                _geometries = new IGeometry[inGeometry.NumGeometries];
                for (int iGeom = 0; iGeom < inGeometry.NumGeometries; iGeom++)
                {
                    ls = inGeometry.GetBasicGeometryN(iGeom) as IBasicLineString;
                    _geometries[iGeom] = new LineString(ls);
                }
                return;
            }
        }
Beispiel #17
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // First, we need to retrieve all data from the input parameters.
            List <string>           fields            = new List <string>();
            GH_Structure <IGH_Goo>  attributes        = new GH_Structure <IGH_Goo>();
            GH_Structure <GH_Curve> inputPolylineTree = new GH_Structure <GH_Curve>();

            bool   writeFile = false;
            string filePath  = "";
            string prj       = null;

            // access the input parameter by index.
            if (!DA.GetData(5, ref writeFile))
            {
                return;
            }
            if (!DA.GetData(4, ref filePath))
            {
                return;
            }
            if (!DA.GetDataTree(0, out inputPolylineTree))
            {
                return;
            }
            if (!DA.GetDataList(1, fields))
            {
                return;
            }
            if (!DA.GetDataTree(2, out attributes))
            {
                return;
            }
            if (!DA.GetData(3, ref prj))
            {
                return;
            }


            //create new feature set to add data to
            //FeatureSet fs = new FeatureSet(FeatureType.Polygon);
            //FeatureSet fs = new FeatureSet(FeatureType.Point);
            //FeatureSet fs = new FeatureSet(FeatureType.MultiPoint);
            FeatureSet fs = new FeatureSet(FeatureType.Line);

            if (prj != null)
            {
                //load projection file
                string cur_proj = System.IO.File.ReadAllText(@prj);

                ///create Projection system
                ProjectionInfo targetProjection = new ProjectionInfo();
                targetProjection.ParseEsriString(cur_proj);
                fs.Projection = targetProjection;
            }



            if (writeFile)
            {
                // Add fields to the feature sets attribute table
                foreach (string field in fields)
                {
                    //check for type
                    string[] splitField = field.Split(';');
                    //if field type provided, specify it
                    if (splitField.Length == 2)
                    {
                        fs.DataTable.Columns.Add(new DataColumn(splitField[0], Type.GetType(splitField[1])));
                    }
                    else
                    {
                        //otherwise jsut use a string
                        fs.DataTable.Columns.Add(new DataColumn(field, typeof(string)));
                    }
                }


                // for every branch  (ie feature)
                foreach (GH_Path path in inputPolylineTree.Paths)
                {
                    //set branch
                    IList branch = inputPolylineTree.get_Branch(path);
                    List <DotSpatial.Topology.LineString> theseLines = new List <DotSpatial.Topology.LineString>();

                    foreach (GH_Curve curve in branch)
                    {
                        // create vertex list for this curve
                        List <Coordinate> vertices = new List <Coordinate>();

                        //convert to rhino curve
                        Curve rhinoCurve = null;
                        GH_Convert.ToCurve(curve, ref rhinoCurve, 0);
                        //curve to nurbes
                        NurbsCurve thisNurbsCurve = rhinoCurve.ToNurbsCurve();
                        //Get list of control points
                        Rhino.Geometry.Collections.NurbsCurvePointList theseControlPoints = thisNurbsCurve.Points;
                        //for each control point
                        foreach (ControlPoint thisPoint in theseControlPoints)
                        {
                            vertices.Add(new Coordinate(thisPoint.Location.X, thisPoint.Location.Y));
                        }//end each control point

                        //create lineString Geometry from coordinates
                        DotSpatial.Topology.LineString thisLine = new DotSpatial.Topology.LineString(vertices);
                        // add linestring to linestring list
                        theseLines.Add(thisLine);
                    }//end curve itteration

                    //Convert Coordinates to dot spatial point or multipoint geometry
                    //DotSpatial.Topology.Point geom = new DotSpatial.Topology.Point(vertices);
                    //DotSpatial.Topology.MultiPoint geom = new DotSpatial.Topology.MultiPoint(vertices);

                    //convert list of line strings into single multilinestring feature
                    MultiLineString geom = new MultiLineString(theseLines);

                    //convert geom to a feature
                    IFeature feature = fs.AddFeature(geom);

                    //begin editing to add feature attributes
                    feature.DataRow.BeginEdit();
                    //get this features attributes by its path
                    IList <string> featrueAttributes = attributes.get_Branch(path) as IList <string>;
                    int            thisIndex         = 0;
                    //add each attribute for the pt's path
                    foreach (var thisAttribute in attributes.get_Branch(path))
                    {
                        string thisField = fields[thisIndex].Split(';')[0];
                        feature.DataRow[thisField] = thisAttribute.ToString(); //currently everything is a string....
                        thisIndex++;
                    }

                    //finish attribute additions
                    feature.DataRow.EndEdit();
                }//end of itterating through branches of pt tree
                fs.SaveAs(filePath, true);
            }
        }
        /// <summary>
        /// Executes the DP line simplefy tool programaticaly
        /// </summary>
        /// <param name="input">The input polygon feature set</param>
        /// <param name="tolerance">The tolerance to use when simplefiying</param>
        /// <param name="output">The output polygon feature set</param>
        /// <param name="cancelProgressHandler">The progress handler</param>
        /// <returns></returns>
        public bool Execute(
            IFeatureSet input, double tolerance, IFeatureSet output, ICancelProgressHandler cancelProgressHandler)
        {
            // Validates the input and output data
            if (input == null || output == null)
            {
                return false;
            }

            // We copy all the fields
            foreach (DataColumn inputColumn in input.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            int numTotalOldPoints = 0;
            int numTotalNewPoints = 0;

            for (int j = 0; j < input.Features.Count; j++)
            {
                int numOldPoints = 0;
                int numNewPoints = 0;

                Geometry geom = input.Features[j].BasicGeometry as Geometry;
                if (geom != null)
                {
                    numOldPoints = geom.NumPoints;
                }

                numTotalOldPoints += numOldPoints;
                if (geom != null)
                {
                    for (int part = 0; part < geom.NumGeometries; part++)
                    {
                        Geometry geomPart = (Geometry)geom.GetGeometryN(part);

                        // do the simplification
                        IList<Coordinate> oldCoords = geomPart.Coordinates;
                        IList<Coordinate> newCoords = DouglasPeuckerLineSimplifier.Simplify(
                            oldCoords, tolerance);

                        // convert the coordinates back to a geometry
                        Geometry newGeom = new LineString(newCoords);
                        numNewPoints += newGeom.NumPoints;
                        numTotalNewPoints += numNewPoints;
                        Feature newFeature = new Feature(newGeom, output);
                        foreach (DataColumn colSource in input.DataTable.Columns)
                        {
                            newFeature.DataRow[colSource.ColumnName] = input.Features[j].DataRow[colSource.ColumnName];
                        }
                    }
                }

                // Status updates is done here, shows number of old / new points
                cancelProgressHandler.Progress(
                    string.Empty,
                    Convert.ToInt32((Convert.ToDouble(j) / Convert.ToDouble(input.Features.Count)) * 100),
                    numOldPoints + "-->" + numNewPoints);
                if (cancelProgressHandler.Cancel)
                {
                    return false;
                }
            }

            cancelProgressHandler.Progress(
                string.Empty,
                100,
                TextStrings.Originalnumberofpoints + numTotalOldPoints + " " + TextStrings.Newnumberofpoints
                + numTotalNewPoints);

            output.Save();
            return true;
        }
Beispiel #19
0
        /// <summary>
        /// Returns true if the element intersect the rectangle from the parent class
        /// </summary>
        /// <param name="rect">The rectangle to test must be in the virtual modeling coordinant plane</param>
        /// <returns></returns>
        public override bool ElementInRectangle(Rectangle rect)
        {
            IGeometry rectanglePoly;
            if ((rect.Height == 0) && (rect.Width == 0))
            {
                rectanglePoly = new Topology.Point(rect.X, rect.Y);
            }
            else if (rect.Width == 0)
            {
                Topology.Point[] rectanglePoints = new Topology.Point[2];
                rectanglePoints[0] = new Topology.Point(rect.X, rect.Y);
                rectanglePoints[1] = new Topology.Point(rect.X, rect.Y + rect.Height);
                rectanglePoly = new LineString(rectanglePoints);
            }
            else if (rect.Height == 0)
            {
                Topology.Point[] rectanglePoints = new Topology.Point[2];
                rectanglePoints[0] = new Topology.Point(rect.X, rect.Y);
                rectanglePoints[1] = new Topology.Point(rect.X + rect.Width, rect.Y);
                rectanglePoly = new LineString(rectanglePoints);
            }
            else
            {
                Topology.Point[] rectanglePoints = new Topology.Point[5];
                rectanglePoints[0] = new Topology.Point(rect.X, rect.Y);
                rectanglePoints[1] = new Topology.Point(rect.X, rect.Y + rect.Height);
                rectanglePoints[2] = new Topology.Point(rect.X + rect.Width, rect.Y + rect.Height);
                rectanglePoints[3] = new Topology.Point(rect.X + rect.Width, rect.Y);
                rectanglePoints[4] = new Topology.Point(rect.X, rect.Y);
                rectanglePoly = new Polygon(new LinearRing(rectanglePoints));
            }

            if (Shape == ModelShape.Arrow)
            {
                Topology.Point[] arrowPoints = new Topology.Point[_arrowPath.PointCount];
                for (int i = 0; i < _arrowPath.PointCount; i++)
                {
                    arrowPoints[i] = new Topology.Point(_arrowPath.PathPoints[i].X + Location.X, _arrowPath.PathPoints[i].Y + Location.Y);
                }
                LineString arrowLine = new LineString(arrowPoints);
                return (arrowLine.Intersects(rectanglePoly));
            }
            return false;
        }
        public static IEnumerable<OCM.API.Common.LatLon> SearchPolygonFromPolyLine(List<OCM.API.Common.LatLon> points, double distanceKM)
        {
            //http://dotspatial.codeplex.com/wikipage?title=CycleThroughVerticesCS&referringTitle=Desktop_SampleCode

            //create feature set from points
            Feature f = new Feature();
            FeatureSet fs = new FeatureSet(f.FeatureType);

            Coordinate[] coord = new Coordinate[points.Count];
            for (int i = 0; i < points.Count; i++)
            {
                coord[i] = new Coordinate((double)points[i].Latitude, (double)points[i].Longitude);
            }
            LineString ls = new LineString(coord);
            f = new Feature(ls);
            fs.Features.Add(f);
            fs.Buffer(distanceKM, false); //TODO: approx km to lat/long coord value
            IFeatureSet iF = fs.Buffer(10, true);

            //export polygon points
            List<OCM.API.Common.LatLon> polyPoints = new List<OCM.API.Common.LatLon>();
            Extent extent = new Extent(-180, -90, 180, 90);
            foreach (ShapeRange shape in fs.ShapeIndices)
            {
                if (shape.Intersects(extent))
                    foreach (PartRange part in shape.Parts)
                    {
                        foreach (Vertex vertex in part)
                        {
                            if (vertex.X > 0 && vertex.Y > 0)
                            {
                                // prepare export of polygon points
                                Console.WriteLine(vertex.X);
                                polyPoints.Add(new OCM.API.Common.LatLon { Latitude = vertex.X, Longitude = vertex.Y });
                            }
                        }
                    }
            }

            return polyPoints;
        }
        /// <summary>
        /// Find the intersection points of lines that cross a polygon
        /// </summary>
        /// <param name="lineFeatureSet">The line features</param>
        /// <param name="polygon">The polygon feature</param>
        /// <param name="intersectsPerLineSeg">Output array of intersection counts</param>
        /// <param name="intersectionPts">Output array of intersection points</param>
        /// <param name="polyIntersectLocs">Output array of intersection locations in reference to polygon vertex indices</param>
        /// <returns></returns>
        public static int FindIntersections(
            IFeatureSet lineFeatureSet,
            IFeature polygon,
            out int[] intersectsPerLineSeg,
            out Point[][] intersectionPts,
            out int[][] polyIntersectLocs)
        {
            int numSignChanges = 0; // tracks number of determinant sign changes
            int numLines = lineFeatureSet.Features.Count;
            int numVerticies = polygon.NumPoints;
            int[][] detSigns = new int[numLines][];
            bool[][] signChanges = new bool[numLines][]; // keeps track of where sign changes occur
            int[][] changeLocations = new int[numLines][];
            int[] intersectsPerLine = new int[numLines];
            Point[][] intersectPts = new Point[numLines][];

            IList<Coordinate> coorPoly = polygon.Coordinates;

            // ICoordinate[] secCoor = new ICoordinate[2];
            for (int lineNo = 0; lineNo <= numLines - 1; lineNo++)
            {
                IFeature line = lineFeatureSet.Features[lineNo];
                IList<Coordinate> coorLine = line.Coordinates;
                int numChangesPerLine = 0;
                detSigns[lineNo] = new int[numVerticies];
                signChanges[lineNo] = new bool[numVerticies];
                intersectPts[lineNo] = new Point[numVerticies];
                changeLocations[lineNo] = new int[numVerticies];

                for (int vertNo = 0; vertNo <= numVerticies - 1; vertNo++)
                {
                    intersectPts[lineNo][vertNo] = new Point();
                    Point intersectPt = new Point();

                    // Calculate the determinant (3x3 square matrix)
                    double si = TurboDeterm(
                        coorPoly[vertNo].X,
                        coorLine[0].X,
                        coorLine[1].X,
                        coorPoly[vertNo].Y,
                        coorLine[0].Y,
                        coorLine[1].Y);

                    // Check the determinant result
                    switch (vertNo)
                    {
                        case 0:
                            if (Math.Abs(si) <= FindIntersectionTolerance)
                            {
                                detSigns[lineNo][vertNo] = 0; // we have hit a vertex
                            }
                            else if (si > 0)
                            {
                                detSigns[lineNo][vertNo] = 1; // +'ve
                            }
                            else if (si < 0)
                            {
                                detSigns[lineNo][vertNo] = -1; // -'ve
                            }

                            signChanges[lineNo][0] = false; // First element will NEVER be a sign change
                            break;
                        default:
                            if (Math.Abs(si) <= FindIntersectionTolerance)
                            {
                                detSigns[lineNo][vertNo] = 0;
                            }
                            else if (si > 0)
                            {
                                detSigns[lineNo][vertNo] = 1;
                            }
                            else if (si < 0)
                            {
                                detSigns[lineNo][vertNo] = -1;
                            }

                            // Check for sign change
                            if (detSigns[lineNo][vertNo - 1] != detSigns[lineNo][vertNo])
                            {
                                IList<Coordinate> secCoor = new List<Coordinate>
                                                                {
                                                                    coorPoly[vertNo - 1], coorPoly[vertNo]
                                                                };

                                // calculate the actual intercept point
                                LineString polyTestLine1 = new LineString(secCoor);
                                secCoor = new List<Coordinate> { coorLine[0], coorLine[1] };
                                LineString polyTestLine2 = new LineString(secCoor);
                                bool validIntersect = polyTestLine1.Intersects(polyTestLine2);
                                IGeometry inPt = polyTestLine1.Intersection(polyTestLine2);
                                if (inPt.Coordinates.Count == 1)
                                {
                                    intersectPt = new Point(inPt.Coordinate);
                                }

                                if (validIntersect)
                                {
                                    signChanges[lineNo][vertNo] = true;
                                    numSignChanges += 1;
                                    numChangesPerLine += 1;
                                    intersectsPerLine[lineNo] = numChangesPerLine;

                                    // we want to store the valid intersect pts at the
                                    // beginning of the array so we don't have to search for them
                                    intersectPts[lineNo][numChangesPerLine - 1] = intersectPt;

                                    // keep track of where the intersect occurs in reference to polygon
                                    changeLocations[lineNo][numChangesPerLine - 1] = vertNo;

                                    // intersect pt occurs between vertNo-1 and vertNo
                                }
                                else
                                {
                                    signChanges[lineNo][vertNo] = false;
                                }
                            }
                            else
                            {
                                signChanges[lineNo][vertNo] = false;
                            }

                            break;
                    }
                    // end of switch
                }
            }

            polyIntersectLocs = changeLocations;
            intersectionPts = intersectPts;
            intersectsPerLineSeg = intersectsPerLine;
            return numSignChanges;
        }
Beispiel #22
0
        public ReferentielLineString(InfChaussee chaussee, double absDeb, double absFin, LineString ls)
        {
            // TODO: Complete member initialization
            this.Segements = new List<ReferentielSegment>();
            this.Chaussee = chaussee;
            this.AbsDeb = absDeb;
            this.AbsFin = absFin;
            double deltaAbs = this.AbsFin - this.AbsDeb;
            double coeff = deltaAbs / ls.Length;
            double absCurrent = this.AbsDeb;
            for (int i = 0; i < ls.Coordinates.Count - 1; i++)
            {
                Coordinate coordDeb = ls.Coordinates[i];
                Coordinate coordFin = ls.Coordinates[i+1];
                double segmentLength = new LineString(new Coordinate[] { coordDeb,coordFin  }).Length;
                if (segmentLength > 0)
                {
                    double lengthInAbs = segmentLength * coeff;
                    ReferentielSegment segment = new ReferentielSegment(coordDeb, coordFin, absCurrent, absCurrent + lengthInAbs);
                    this.Segements.Add(segment);
                    absCurrent += lengthInAbs;
                }
            }
            this.Segements.First().AbsDeb = absDeb;

            this.Segements.Last().AbsFin = absFin;
        }
Beispiel #23
0
        /// <summary>
        /// Returns true if the element intersect the rectangle from the parent class
        /// </summary>
        /// <param name="rect">The rectangle to test must be in the virtual modeling coordinant plane</param>
        /// <returns></returns>
        public virtual bool ElementInRectangle(Rectangle rect)
        {
            IGeometry rectanglePoly;
            if ((rect.Height == 0) && (rect.Width == 0))
            {
                rectanglePoly = new Topology.Point(rect.X, rect.Y);
            }
            else if (rect.Width == 0)
            {
                Topology.Point[] rectanglePoints = new Topology.Point[2];
                rectanglePoints[0] = new Topology.Point(rect.X, rect.Y);
                rectanglePoints[1] = new Topology.Point(rect.X, rect.Y + rect.Height);
                rectanglePoly = new LineString(rectanglePoints);
            }
            else if (rect.Height == 0)
            {
                Topology.Point[] rectanglePoints = new Topology.Point[2];
                rectanglePoints[0] = new Topology.Point(rect.X, rect.Y);
                rectanglePoints[1] = new Topology.Point(rect.X + rect.Width, rect.Y);
                rectanglePoly = new LineString(rectanglePoints);
            }
            else
            {
                Topology.Point[] rectanglePoints = new Topology.Point[5];
                rectanglePoints[0] = new Topology.Point(rect.X, rect.Y);
                rectanglePoints[1] = new Topology.Point(rect.X, rect.Y + rect.Height);
                rectanglePoints[2] = new Topology.Point(rect.X + rect.Width, rect.Y + rect.Height);
                rectanglePoints[3] = new Topology.Point(rect.X + rect.Width, rect.Y);
                rectanglePoints[4] = new Topology.Point(rect.X, rect.Y);
                rectanglePoly = new Polygon(new LinearRing(rectanglePoints));
            }

            switch (Shape)
            {
                case ModelShape.Rectangle:
                    return (rect.IntersectsWith(Rectangle));

                case ModelShape.Ellipse:
                    int b = Height / 2;
                    int a = Width / 2;
                    Topology.Point[] ellipsePoints = new Topology.Point[(4 * a) + 1];
                    for (int x = -a; x <= a; x++)
                    {
                        if (x == 0)
                        {
                            ellipsePoints[x + a] = new Topology.Point(Location.X + x + a, Location.Y);
                            ellipsePoints[3 * a - x] = new Topology.Point(Location.X + x + a, Location.Y + Height);
                        }
                        else
                        {
                            ellipsePoints[x + a] = new Topology.Point(Location.X + x + a, Location.Y + b - Math.Sqrt(Math.Abs(((b * b * x * x) / (a * a)) - (b * b))));
                            ellipsePoints[3 * a - x] = new Topology.Point(Location.X + x + a, Location.Y + b + Math.Sqrt(Math.Abs(((b * b * x * x) / (a * a)) - (b * b))));
                        }
                    }

                    Polygon ellipsePoly = new Polygon(new LinearRing(ellipsePoints));
                    return (ellipsePoly.Intersects(rectanglePoly));

                case ModelShape.Triangle:
                    Topology.Point[] trianglePoints = new Topology.Point[4];
                    trianglePoints[0] = new Topology.Point(Location.X, Location.Y);
                    trianglePoints[1] = new Topology.Point(Location.X, Location.Y + Height);
                    trianglePoints[2] = new Topology.Point(Location.X + Width - 5, Location.Y + ((Height - 5) / 2));
                    trianglePoints[3] = new Topology.Point(Location.X, Location.Y);
                    Polygon trianglePoly = new Polygon(new LinearRing(trianglePoints));
                    return (trianglePoly.Intersects(rectanglePoly));

                default:
                    return false;
            }
        }
Beispiel #24
0
 private void MultilsFSCS(object sender, EventArgs e)
 {
     Random rnd = new Random();
     Feature f = new Feature();
     FeatureSet fs = new FeatureSet(f.FeatureType);
     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);
         }
         LineString ls = new LineString(coord);
         f = new Feature(ls);
         fs.Features.Add(f);
     }
     fs.SaveAs("C:\\Temp\\test.shp", true);
 }
        /// <summary>
        /// Executes the DP line simplefy tool programaticaly
        /// Ping Yang Added it for external Testing
        /// </summary>
        /// <param name="input">The input polygon feature set</param>
        /// <param name="tolerance">The tolerance to use when simplefiying</param>
        /// <param name="output">The output polygon feature set</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet input, double tolerance, IFeatureSet output)
        {
            // Validates the input and output data
            if (input == null || output == null)
            {
                return false;
            }

            // We copy all the fields
            foreach (DataColumn inputColumn in input.DataTable.Columns)
            {
                output.DataTable.Columns.Add(new DataColumn(inputColumn.ColumnName, inputColumn.DataType));
            }

            foreach (IFeature t in input.Features)
            {
                Geometry geom = t.BasicGeometry as Geometry;
                if (geom != null)
                {
                    for (int part = 0; part < geom.NumGeometries; part++)
                    {
                        Geometry geomPart = (Geometry)geom.GetGeometryN(part);

                        // do the simplification
                        IList<Coordinate> oldCoords = geomPart.Coordinates;
                        IList<Coordinate> newCoords = DouglasPeuckerLineSimplifier.Simplify(
                            oldCoords, tolerance);

                        // convert the coordinates back to a geometry
                        Geometry newGeom = new LineString(newCoords);
                        Feature newFeature = new Feature(newGeom, output);
                        foreach (DataColumn colSource in input.DataTable.Columns)
                        {
                            newFeature.DataRow[colSource.ColumnName] = t.DataRow[colSource.ColumnName];
                        }
                    }
                }
            }

            output.Save();
            return true;
        }
Beispiel #26
0
        private void CreatesLineFeature(object sender, EventArgs e)
        {
            //http://dotspatial.codeplex.com/wikipage?title=LFCS&referringTitle=Desktop_SampleCode
            //Creates a random number generator
            Random rnd = new Random();
            //creates a new coordiante array
            Coordinate[] c = new Coordinate[36];
            //for loop that will generate 36 random numbers
            for (int i = 0; i < 36; i++)
            {
                c[i] = new Coordinate((rnd.NextDouble() * 360) - 180, (rnd.NextDouble() * 180) - 90);

            }
            //creates a linestring from the coordinate array
            LineString ls = new LineString(c);
            //creates a feature from the linestring
            Feature f = new Feature(ls);
            FeatureSet fs = new FeatureSet(f.FeatureType);
            fs.Features.Add(f);

            fs.SaveAs("C:\\Temp\\Lines.shp", true);
        }
Beispiel #27
0
        public DotSpatial.Topology.Geometry Geocode(long chausseeId, long absDeb, long absFin)
        {
            ReferentielMultiLineString mls = this.GetChausseeMultiLineString(chausseeId);
            if (mls != null)
            {
                ReferentielLineString lsDeb = (from l in mls.LineStrings where absDeb >= l.AbsDeb && absDeb < l.AbsFin select l).FirstOrDefault();
                ReferentielLineString lsFin = (from l in mls.LineStrings where absFin >= l.AbsDeb && absFin < l.AbsFin select l).FirstOrDefault();
                if (lsDeb != null && lsFin != null)
                {
                    if (mls.LineStrings.IndexOf(lsDeb) == mls.LineStrings.IndexOf(lsFin))
                    {
                        ReferentielSegment segDeb = (from s in lsDeb.Segements where absDeb >= s.AbsDeb && absDeb < s.AbsFin select s).FirstOrDefault();
                        ReferentielSegment segFin = (from s in lsDeb.Segements where absFin >= s.AbsDeb && absFin < s.AbsFin select s).FirstOrDefault();
                        if (segDeb != null && segFin != null)
                        {
                            if (lsDeb.Segements.IndexOf(segDeb) == lsDeb.Segements.IndexOf(segFin))
                            {
                                // sur le meme segment de la linestring
                                List<Coordinate> coordinates = new List<Coordinate>();
                                double fractionSegDeb = (absDeb - segDeb.AbsDeb) / (segDeb.AbsFin - segDeb.AbsDeb);
                                double fractionSegFin = (absFin - segFin.AbsDeb) / (segFin.AbsFin - segFin.AbsDeb);
                                double xDeb = segDeb.CoordDeb.X + ((segDeb.CoordFin.X - segDeb.CoordDeb.X) * fractionSegDeb);
                                double yDeb = segDeb.CoordDeb.Y + ((segDeb.CoordFin.Y - segDeb.CoordDeb.Y) * fractionSegDeb);
                                double xFin = segFin.CoordDeb.X + ((segFin.CoordFin.X - segFin.CoordDeb.X) * fractionSegFin);
                                double yFin = segFin.CoordDeb.Y + ((segFin.CoordFin.Y - segFin.CoordDeb.Y) * fractionSegFin);
                                coordinates.Add(new Coordinate(xDeb, yDeb));
                                coordinates.Add(new Coordinate(xFin, yFin));
                                LineString ls = new LineString(coordinates);
                                return ls;
                                //Console.WriteLine("sur le meme segment de la linestring");
                            }
                            else
                            {
                                List<Coordinate> coordinates = new List<Coordinate>();
                                double fractionSegDeb = (absDeb - segDeb.AbsDeb) / (segDeb.AbsFin - segDeb.AbsDeb);
                                double fractionSegFin = (absFin - segFin.AbsDeb) / (segFin.AbsFin - segFin.AbsDeb);
                                double xDeb = segDeb.CoordDeb.X + ((segDeb.CoordFin.X - segDeb.CoordDeb.X) * fractionSegDeb);
                                double yDeb = segDeb.CoordDeb.Y + ((segDeb.CoordFin.Y - segDeb.CoordDeb.Y) * fractionSegDeb);
                                double xFin = segFin.CoordDeb.X + ((segFin.CoordFin.X - segFin.CoordDeb.X) * fractionSegFin);
                                double yFin = segFin.CoordDeb.Y + ((segFin.CoordFin.Y - segFin.CoordDeb.Y) * fractionSegFin);
                                coordinates.Add(new Coordinate(xDeb, yDeb));
                                int indexSegDeb = lsDeb.Segements.IndexOf(segDeb);
                                int indexSegFin = lsDeb.Segements.IndexOf(segFin);
                                for (int i = indexSegDeb; i < indexSegFin; i++)
                                {
                                    ReferentielSegment s = lsDeb.Segements[i];
                                    coordinates.Add(s.CoordFin);
                                }
                                coordinates.Add(new Coordinate(xFin, yFin));
                                LineString ls = new LineString(coordinates);
                                return ls;
                                // sur plusieur segment de la linestring
                               // Console.WriteLine("sur plusieur segment de la linestring");
                            }
                        }

                    }
                    else
                    {
                        // sur plusieur lignes de la multilinestring
                        //Console.WriteLine("sur plusieur lignes de la multilinestring");
                    }
                }

            }
            return null;
        }
        /// <summary>
        /// This uses extent checking (rather than full polygon intersection checking).  It will add
        /// any members that are either contained by or intersect with the specified region
        /// depending on the SelectionMode property.  The order of operation is the region
        /// acting on the feature, so Contains, for instance, would work with points.
        /// </summary>
        /// <param name="region"></param>
        /// <param name="affectedArea">The affected area of this addition</param>
        /// <returns>True if any item was actually added to the collection</returns>
        public bool AddRegion(IEnvelope region, out IEnvelope affectedArea)
        {
            bool added = false;
            SuspendChanges();
            affectedArea = new Envelope();
            Stopwatch sw = new Stopwatch();
            Stopwatch total = new Stopwatch();
            total.Start();
            foreach (IFeature f in FeatureList)
            {
                bool doAdd = false;
                if (_selectionMode == SelectionMode.IntersectsExtent)
                {
                    if (region.Intersects(f.Envelope))
                    {
                        Add(f);
                        affectedArea.ExpandToInclude(f.Envelope);
                        added = true;
                    }
                }
                else if (_selectionMode == SelectionMode.ContainsExtent)
                {
                    if (region.Contains(f.Envelope))
                    {
                        Add(f);
                        affectedArea.ExpandToInclude(f.Envelope);
                        added = true;
                    }
                }

                IGeometry reg;
                if (region.Width == 0 && region.Height == 0)
                {
                    reg = new Point(region.X, region.Y);
                }
                else if (region.Height == 0 || region.Width == 0)
                {
                    Coordinate[] coords = new Coordinate[2];
                    coords[0] = new Coordinate(region.X, region.Y);
                    coords[1] = new Coordinate(region.Bottom(), region.Right());
                    reg = new LineString(coords);
                }
                else
                {
                    reg = region.ToPolygon();
                }
                IGeometry geom = Geometry.FromBasicGeometry(f.BasicGeometry);
                switch (_selectionMode)
                {
                    case SelectionMode.Contains:
                        if (region.Contains(f.Envelope))
                        {
                            doAdd = true;
                        }
                        else if (region.Intersects(f.Envelope))
                        {
                            if (reg.Contains(geom)) doAdd = true;
                        }
                        break;
                    case SelectionMode.CoveredBy:
                        if (reg.CoveredBy(geom)) doAdd = true;
                        break;
                    case SelectionMode.Covers:
                        if (reg.Covers(geom)) doAdd = true;
                        break;
                    case SelectionMode.Disjoint:
                        if (reg.Disjoint(geom)) doAdd = true;
                        break;
                    case SelectionMode.Intersects:

                        if (region.Contains(f.Envelope))
                        {
                            doAdd = true;
                        }
                        else if (region.Intersects(f.Envelope))
                        {
                            if (reg.Intersects(geom)) doAdd = true;
                        }

                        break;
                    case SelectionMode.Overlaps:
                        if (reg.Overlaps(geom)) doAdd = true;
                        break;
                    case SelectionMode.Touches:
                        if (reg.Touches(geom)) doAdd = true;
                        break;
                    case SelectionMode.Within:
                        if (reg.Within(geom)) doAdd = true;
                        break;
                }

                if (doAdd)
                {
                    Add(f);
                    affectedArea.ExpandToInclude(f.Envelope);
                    added = true;
                }
            }
            sw.Start();
            ResumeChanges();
            sw.Stop();
            total.Stop();
            Debug.WriteLine("Geometry Intersection Time: " + sw.ElapsedMilliseconds);
            Debug.WriteLine("Total Intersection Time: " + total.ElapsedMilliseconds);
            return added;
        }
Beispiel #29
0
        public static Geometry CreateGeometryFromWkt(string strData)
        {
            if (strData.StartsWith("LINESTRING"))
            {
                strData = strData.Substring(10);
                strData = strData.TrimStart().TrimEnd();
                if (strData.StartsWith("("))
                { strData = strData.Substring(1); }
                if (strData.EndsWith(")"))
                { strData = strData.Substring(0, strData.Length - 1); }
                strData = strData.TrimStart().TrimEnd();
                String[] items = strData.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                List<Coordinate> coordinates = new List<Coordinate>();
                foreach (String item in items)
                {
                    String[] strCoord = item.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    double x = 0;
                    double y = 0;
                    if (double.TryParse(strCoord[0], System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out x) &&
                        double.TryParse(strCoord[1], System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out y))
                    {
                        Coordinate coordinate = new Coordinate(x, y);
                        coordinates.Add(coordinate);
                    }
                }
                LineString lineString = new LineString(coordinates);
                return lineString;
            }
            else if (strData.StartsWith("MULTILINESTRING"))
            {
                strData = strData.Substring(15);
                strData = strData.TrimStart().TrimEnd();
                if (strData.StartsWith("("))
                { strData = strData.Substring(1); }
                if (strData.EndsWith(")"))
                { strData = strData.Substring(0, strData.Length - 1); }
                strData = strData.TrimStart().TrimEnd();

                bool parse = true;
                List<LineString> lineStrings = new List<LineString>();
                while (parse)
                {
                    int indexStart = strData.IndexOf("(") + 1;
                    int indexEnd = strData.IndexOf(")");
                    if (indexStart != -1 && indexEnd != -1 && indexEnd > indexStart)
                    {
                        String strLine = strData.Substring(indexStart, indexEnd - indexStart);

                        strLine = strLine.TrimStart().TrimEnd();
                        String[] items = strLine.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                        List<Coordinate> coordinates = new List<Coordinate>();
                        foreach (String item in items)
                        {
                            String[] strCoord = item.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                            double x = 0;
                            double y = 0;
                            if (double.TryParse(strCoord[0], System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out x) &&
                                double.TryParse(strCoord[1], System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out y))
                            {
                                Coordinate coordinate = new Coordinate(x, y);
                                coordinates.Add(coordinate);
                            }
                        }
                        LineString lineString = new LineString(coordinates);
                        lineStrings.Add(lineString);

                        strData = strData.Substring(0, indexEnd);

                    }
                    else parse = false;

                }
                MultiLineString multiLineString = new MultiLineString(lineStrings);
                return multiLineString;

            }
            return null;
        }
Beispiel #30
0
 /// <summary>
 /// 兩個未相交多邊形合併時,依照邊界線先產出中間空白的多邊形
 /// </summary>
 /// <param name="line1"></param>
 /// <param name="line2"></param>
 /// <returns></returns>
 public Polygon GetConvexHull(LineString line1, LineString line2)
 {
     return line1.Union(line2).ConvexHull() as Polygon;
 }
 /// <summary>
 /// Creates a <see cref="MultiLineString" /> in the reverse order to this object.
 /// Both the order of the component LineStrings
 /// and the order of their coordinate sequences are reversed.
 /// </summary>
 /// <returns>a <see cref="MultiLineString" /> in the reverse order.</returns>
 public virtual IMultiLineString Reverse()
 {
     int nLines = Geometries.Length;
     ILineString[] revLines = new LineString[nLines];
     for (int i = 0; i < Geometries.Length; i++)
         revLines[nLines - 1 - i] = new LineString(((ILineString)Geometries[i]).Reverse());
     return Factory.CreateMultiLineString(revLines);
 }
        /// <summary>
        /// Allows for new behavior during deactivation.
        /// </summary>
        protected override void OnDeactivate()
        {
            if (_standBy) { return; }

            // Don't completely deactivate, but rather go into standby mode
            // where we draw only the content that we have actually locked in.
            _standBy = true;
            if (_coordinateDialog != null) { _coordinateDialog.Hide(); }
            if (_coordinates != null && _coordinates.Count > 1)
            {
                LineString ls = new LineString(_coordinates);
                FeatureSet fs = new FeatureSet(FeatureType.Line);
                fs.Features.Add(new Feature(ls));
                MapLineLayer gll = new MapLineLayer(fs)
                                       {
                                           Symbolizer =
                                               {
                                                   ScaleMode = ScaleMode.Symbolic,
                                                   Smoothing = true
                                               },
                                           MapFrame = Map.MapFrame
                                       };
                _tempLayer = gll;
                Map.MapFrame.DrawingLayers.Add(gll);
                Map.MapFrame.Invalidate();
                Map.Invalidate();
            }

            base.Deactivate();
        }
Beispiel #33
0
 /// <summary>
 /// 檢驗線段是否與圖幅框接觸,起點、終點、中間點都要比對
 /// </summary>
 /// <param name="line">要被檢驗的線段</param>
 /// <param name="extent">圖幅框</param>
 /// <returns></returns>
 public bool IsLineTouchesBoundary(ILineString line, LineString extent)
 {
     return line.Centroid.Distance(extent) < _tolerance &&
            line.StartPoint.Distance(extent) < _tolerance &&
            line.EndPoint.Distance(extent) < _tolerance;
 }