Beispiel #1
0
        public void CanCreateShapeFromCoordinate(double x, double y, double z, double m)
        {
            var c     = new CoordinateZM(x, y, z, m);
            var shape = new Shape(c);

            Assert.IsNotNull(shape);
        }
Beispiel #2
0
        private bool TryParseCoordinate(JsonArray coordinates, out Coordinate result)
        {
            result = null;
            if (coordinates == null || coordinates.Count < 2)
            {
                return(false);
            }

            var valid = coordinates.All(x => x is double || x is long);

            if (!valid)
            {
                return(false);
            }

            if (coordinates.Count == 2)
            {
                result = new Coordinate(Convert.ToDouble(coordinates[1]), Convert.ToDouble(coordinates[0]));
            }
            else if (coordinates.Count == 3)
            {
                result = new CoordinateZ(Convert.ToDouble(coordinates[1]), Convert.ToDouble(coordinates[0]), Convert.ToDouble(coordinates[2]));
            }
            else
            {
                result = new CoordinateZM(Convert.ToDouble(coordinates[1]), Convert.ToDouble(coordinates[0]), Convert.ToDouble(coordinates[2]), Convert.ToDouble(coordinates[3]));
            }
            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="tokens"></param>
        /// <param name="skipExtraParenthesis"></param>
        /// <returns></returns>
        private Coordinate GetPreciseCoordinate(IList tokens, Boolean skipExtraParenthesis)
        {
            var     coord = new CoordinateZM();
            Boolean extraParenthesisFound = false;

            if (skipExtraParenthesis)
            {
                extraParenthesisFound = IsStringValueNext(tokens, "("); //NOXLATE
                if (extraParenthesisFound)
                {
                    index++;
                }
            }
            coord.X = GetNextNumber(tokens);
            coord.Y = GetNextNumber(tokens);
            if (IsNumberNext(tokens))
            {
                coord.Z = GetNextNumber(tokens);
            }
            if (IsNumberNext(tokens))
            {
                coord.M = GetNextNumber(tokens);
            }

            if (skipExtraParenthesis &&
                extraParenthesisFound &&
                IsStringValueNext(tokens, ")")) //NOXLATE
            {
                index++;
            }

            precisionModel.MakePrecise((Coordinate)coord);
            return(coord);
        }
Beispiel #4
0
        public void CoordinateTypeWriteOnSaveAs()
        {
            var         outfile = FileTools.GetTempFileName(".shp");
            IFeatureSet fs      = new FeatureSet();
            var         c       = new CoordinateZM(10.1, 20.2, 3.3, 4.4);

            fs.CoordinateType = CoordinateType.Z;
            fs.Projection     = KnownCoordinateSystems.Geographic.World.WGS1984;
            fs.DataTable.Columns.Add(new DataColumn("ID", typeof(int)));

            IFeature f = fs.AddFeature(new Point(c));

            f.DataRow.BeginEdit();
            f.DataRow["ID"] = 1;
            f.DataRow.EndEdit();

            fs.SaveAs(outfile, true);

            var actual = FeatureSet.Open(outfile);

            try
            {
                Assert.AreEqual(fs.CoordinateType, actual.CoordinateType);
            }
            finally
            {
                FileTools.DeleteShapeFile(outfile);
            }
        }
Beispiel #5
0
        private List <Coordinate> GetCoordinates(VertexRange part, List <Coordinate> coords = null)
        {
            if (coords == null)
            {
                coords = new List <Coordinate>();
            }

            int i = part.StartIndex;

            foreach (var d in part)
            {
                var c = new CoordinateZM(d.X, d.Y);
                if (M != null && M.Length > 0)
                {
                    c.M = M[i];
                }
                if (Z != null && Z.Length > 0)
                {
                    c.Z = Z[i];
                }
                i++;
                coords.Add(c);
            }

            return(coords);
        }
        /// <inheritdoc cref="CoordinateSequence.ToCoordinateArray"/>>
        public override Coordinate[] ToCoordinateArray()
        {
            var ret = GetCachedCoords();

            if (ret != null)
            {
                return(ret);
            }

            ret = new Coordinate[Count];
            if (_z != null)
            {
                if (_m != null)
                {
                    for (int i = 0; i < ret.Length; i++)
                    {
                        ret[i] = new CoordinateZM(_points[i].X, _points[i].Y, _z[i], _m[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < ret.Length; i++)
                    {
                        ret[i] = new CoordinateZ(_points[i].X, _points[i].Y, _z[i]);
                    }
                }
            }
            else
            {
                if (_m != null)
                {
                    for (int i = 0; i < ret.Length; i++)
                    {
                        ret[i] = new CoordinateM(_points[i].X, _points[i].Y, _m[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < ret.Length; i++)
                    {
                        ret[i] = new Coordinate(_points[i].X, _points[i].Y);
                    }
                }
            }

            _coordinateArrayRef = new WeakReference <Coordinate[]>(ret);
            return(ret);
        }
Beispiel #7
0
        private bool TryParseCoordinate(JsonArray coordinates, out Coordinate result)
        {
            result = null;
            if (coordinates == null || coordinates.Count < 2)
                return false;

            var valid = coordinates.All(x => x is double || x is long);
            if (!valid)
                return false;

            if (coordinates.Count == 2)
                result = new Coordinate(Convert.ToDouble(coordinates[1]), Convert.ToDouble(coordinates[0]));
            else if (coordinates.Count == 3)
                result = new CoordinateZ(Convert.ToDouble(coordinates[1]), Convert.ToDouble(coordinates[0]), Convert.ToDouble(coordinates[2]));
            else
                result = new CoordinateZM(Convert.ToDouble(coordinates[1]), Convert.ToDouble(coordinates[0]), Convert.ToDouble(coordinates[2]), Convert.ToDouble(coordinates[3]));
            return true;
        }
Beispiel #8
0
        public void TestCoordinateXYZM()
        {
            var xyzm = new CoordinateZM();

            xyzm.Z = 1.0;
            Assert.That(xyzm.Z, Is.EqualTo(1.0));
            xyzm.M = 1.0;
            Assert.That(xyzm.M, Is.EqualTo(1.0));

            var coord = new CoordinateZ(xyzm); // copy

            Assert.That(coord, Is.EqualTo(xyzm));
            Assert.That(coord.Z, Is.EqualTo(1.0));
            Assert.That(coord.M, Is.NaN);

            coord = new CoordinateZ(1.0, 1.0, 1.0); // 2.5d
            xyzm  = new CoordinateZM(coord);        // copy
            Assert.That(xyzm, Is.EqualTo(coord));
            Assert.That(xyzm.Z, Is.EqualTo(coord.Z).Within(0.000001));
        }
Beispiel #9
0
 public Circle(double latitiude, double longitude, double elevation, double measure, double radius)
 {
     Center = new CoordinateZM(latitiude, longitude, measure, elevation);
     Radius = radius;
 }
Beispiel #10
0
 public Point(double latitude, double longitude, double elevation, double measure)
 {
     Coordinate = new CoordinateZM(latitude, longitude, elevation, measure);
 }
Beispiel #11
0
 public Circle(double latitiude, double longitude, double elevation, double measure, double radius)
 {
     Center = new CoordinateZM(latitiude, longitude, measure, elevation);
     Radius = radius;
 }
Beispiel #12
0
 public Point(double latitude, double longitude, double elevation, double measure)
 {
     Coordinate = new CoordinateZM(latitude, longitude, elevation, measure);
 }
Beispiel #13
0
        private void ReadPolygonShape(Shape shape)
        {
            List <LinearRing> shells = new List <LinearRing>();
            List <LinearRing> holes  = new List <LinearRing>();

            foreach (PartRange part in shape.Range.Parts)
            {
                List <Coordinate> coords = new List <Coordinate>();
                int i = part.StartIndex;
                foreach (Vertex d in part)
                {
                    Coordinate c = new CoordinateZM(d.X, d.Y);
                    if (shape.M != null && shape.M.Length > 0)
                    {
                        c.M = shape.M[i];
                    }
                    if (shape.Z != null && shape.Z.Length > 0)
                    {
                        c.Z = shape.Z[i];
                    }
                    i++;
                    coords.Add(c);
                }

                LinearRing ring = new LinearRing(coords.ToArray());
                if (shape.Range.Parts.Count == 1)
                {
                    shells.Add(ring);
                }
                else
                {
                    if (Orientation.IsCCW(ring.Coordinates))
                    {
                        holes.Add(ring);
                    }
                    else
                    {
                        shells.Add(ring);
                    }
                }
            }

            if (shells.Count == 0 && holes.Count > 0)
            {
                shells = holes;
                holes  = new List <LinearRing>();
            }

            //// Now we have a list of all shells and all holes
            List <LinearRing>[] holesForShells = new List <LinearRing> [shells.Count];
            for (int i = 0; i < shells.Count; i++)
            {
                holesForShells[i] = new List <LinearRing>();
            }

            // Find holes
            foreach (LinearRing hole in holes)
            {
                LinearRing minShell = null;
                Envelope   minEnv   = null;
                Envelope   testEnv  = hole.EnvelopeInternal;
                Coordinate testPt   = hole.Coordinates[0];
                for (int j = 0; j < shells.Count; j++)
                {
                    LinearRing tryRing = shells[j];
                    Envelope   tryEnv  = tryRing.EnvelopeInternal;
                    if (minShell != null)
                    {
                        minEnv = minShell.EnvelopeInternal;
                    }

                    // Check if this new containing ring is smaller than the current minimum ring
                    if (tryEnv.Contains(testEnv) && (PointLocation.IsInRing(testPt, tryRing.Coordinates) || PointInList(testPt, tryRing.Coordinates)))
                    {
                        if (minShell == null || minEnv.Contains(tryEnv))
                        {
                            minShell = tryRing;
                        }

                        holesForShells[j].Add(hole);
                    }
                }
            }

            var polygons = new Polygon[shells.Count];

            for (int i = 0; i < shells.Count; i++)
            {
                polygons[i] = new Polygon(shells[i], holesForShells[i].ToArray());
            }

            if (polygons.Length == 1)
            {
                _geometry = polygons[0];
            }
            else
            {
                // It's a multi part
                _geometry = new MultiPolygon(polygons);
            }

            _featureType = FeatureType.Polygon;
        }
Beispiel #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Feature"/> class from the specified shape. This will not
        /// handle the attribute content, which should be handles separately, with full knowledge of the desired schema.
        /// </summary>
        /// <param name="shape">The shape to read the vertices from in order to build a proper geometry.</param>
        public Feature(Shape shape)
        {
            if (shape.Range == null)
            {
                return;
            }

            ShapeIndex = shape.Range;
            if (shape.Range.FeatureType == FeatureType.Point)
            {
                Coordinate c = new CoordinateZM(shape.Vertices[0], shape.Vertices[1]);
                if (shape.Z != null)
                {
                    c.Z = shape.Z[0];
                }
                if (shape.M != null)
                {
                    c.M = shape.M[0];
                }

                _geometry    = new Point(c);
                _featureType = FeatureType.Point;
            }

            if (shape.Range.FeatureType == FeatureType.MultiPoint)
            {
                List <Coordinate> coords = new List <Coordinate>();
                foreach (PartRange part in shape.Range.Parts)
                {
                    for (int i = part.StartIndex; i <= part.EndIndex; i++)
                    {
                        Coordinate c = new CoordinateZM(shape.Vertices[i * 2], shape.Vertices[(i * 2) + 1]);
                        if (shape.Z != null)
                        {
                            c.Z = shape.Z[i];
                        }
                        if (shape.M != null)
                        {
                            c.M = shape.M[i];
                        }

                        coords.Add(c);
                    }
                }

                _geometry    = new MultiPoint(coords.CastToPointArray());
                _featureType = FeatureType.MultiPoint;
            }

            if (shape.Range.FeatureType == FeatureType.Line)
            {
                List <LineString> strings = new List <LineString>();
                foreach (PartRange part in shape.Range.Parts)
                {
                    List <Coordinate> coords = new List <Coordinate>();
                    for (int i = part.StartIndex; i <= part.EndIndex; i++)
                    {
                        Coordinate c = new CoordinateZM(shape.Vertices[i * 2], shape.Vertices[(i * 2) + 1]);
                        if (shape.Z != null)
                        {
                            c.Z = shape.Z[i];
                        }
                        if (shape.M != null)
                        {
                            c.M = shape.M[i];
                        }

                        coords.Add(c);
                    }

                    strings.Add(new LineString(coords.ToArray()));
                }

                if (strings.Count > 1)
                {
                    _geometry = new MultiLineString(strings.ToArray());
                }
                else if (strings.Count == 1)
                {
                    _geometry = strings[0];
                }

                _featureType = FeatureType.Line;
            }

            if (shape.Range.FeatureType == FeatureType.Polygon)
            {
                ReadPolygonShape(shape);
            }
        }