コード例 #1
0
        private ILineString ReadLine(int dim, int lrsDim, SdoGeometry sdoGeom)
        {
            bool lrs = sdoGeom.LRS > 0;

            decimal[]           info = sdoGeom.ElemArray;
            ICoordinateSequence cs   = null;

            int i = 0;

            while (i < info.Length)
            {
                if (info.getElementType(i).isCompound())
                {
                    int numCompounds = info.getNumCompounds(i);
                    cs = Add(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom));
                    i += 1 + numCompounds;
                }
                else
                {
                    cs = Add(cs, GetElementCSeq(i, sdoGeom, false));
                    i++;
                }
            }

            LineString ls =
                lrs
                                        ? factory.CreateMultiLineString(cs)
                                        : factory.CreateLineString(cs);

            ls.SRID = (int)sdoGeom.Sdo_Srid;
            return(ls);
        }
コード例 #2
0
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivent geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="geometryFactory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory)
        {
            int shapeTypeNum = file.ReadInt32();
            type = (ShapeGeometryType) Enum.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString());
            if (type == ShapeGeometryType.NullShape)
                return geometryFactory.CreateMultiLineString(null);

            if (!(type == ShapeGeometryType.LineString  || type == ShapeGeometryType.LineStringM ||
                  type == ShapeGeometryType.LineStringZ || type == ShapeGeometryType.LineStringZM))
                throw new ShapefileException("Attempting to load a non-arc as arc.");

            // Read and for now ignore bounds.            
            int bblength = GetBoundingBoxLength();
            bbox = new double[bblength];
            for (; bbindex < 4; bbindex++)
            {
                double d = file.ReadDouble();
                bbox[bbindex] = d;
            }
        
            int numParts = file.ReadInt32();
            int numPoints = file.ReadInt32();
            int[] partOffsets = new int[numParts];
            for (int i = 0; i < numParts; i++)
                partOffsets[i] = file.ReadInt32();
			
            ILineString[] lines = new ILineString[numParts];			
            for (int part = 0; part < numParts; part++)
            {
                int start, finish, length;
                start = partOffsets[part];
                if (part == numParts - 1)
                     finish = numPoints;
                else finish = partOffsets[part + 1];
                length = finish - start;
                CoordinateList points = new CoordinateList();                
                points.Capacity = length;
                for (int i = 0; i < length; i++)
                {
                    double x = file.ReadDouble();
                    double y = file.ReadDouble();
                    ICoordinate external = new Coordinate(x, y);
                    geometryFactory.PrecisionModel.MakePrecise(external);
                    points.Add(external);				    
                }
                ILineString line = geometryFactory.CreateLineString(points.ToArray());
                lines[part] = line;
            }
            geom = geometryFactory.CreateMultiLineString(lines);
            GrabZMValues(file);
            return geom;
        }
コード例 #3
0
        /// <summary>
        /// Converts the GML element to multi line string.
        /// </summary>
        /// <param name="element">The GML element of the multi line string.</param>
        /// <param name="factory">The geometry factory.</param>
        /// <returns>The converted multi line string.</returns>
        private static IMultiLineString ToMultiLineString(XElement element, IGeometryFactory factory)
        {
            if (element.Elements() == null)
            {
                return(factory.CreateMultiLineString());
            }

            List <ILineString> lineStrings = new List <ILineString>();

            return(factory.CreateMultiLineString(element.Elements()
                                                 .Where(innerElement => innerElement.Name.LocalName == "LineStringMember")
                                                 .Select(innerElement => ToLineString(innerElement.Elements().FirstOrDefault(), factory))));
        }
        private IGeometry BuildGrid()
        {
            var lines = new ILineString[_numLines * 2];
            int index = 0;

            for (int i = 0; i < _numLines; i++)
            {
                Coordinate  p0   = new Coordinate(GetRandOrdinate(), 0);
                Coordinate  p1   = new Coordinate(GetRandOrdinate(), GridWidth);
                ILineString line = _geomFactory.CreateLineString(new [] { p0, p1 });
                lines[index++] = line;
            }

            for (int i = 0; i < _numLines; i++)
            {
                Coordinate  p0   = new Coordinate(0, GetRandOrdinate());
                Coordinate  p1   = new Coordinate(GridWidth, GetRandOrdinate());
                ILineString line = _geomFactory.CreateLineString(new [] { p0, p1 });
                lines[index++] = line;
            }

            IMultiLineString ml = _geomFactory.CreateMultiLineString(lines);

            _grid = ml.Buffer(_lineWidth);
            var wktWriter = new WKTWriter(2)
            {
                Formatted = true, MaxCoordinatesPerLine = 6
            };

            if (Verbose)
            {
                Console.WriteLine(wktWriter.Write(_grid));
            }
            return(_grid);
        }
コード例 #5
0
        private IGeometry BuildMultiLineString()
        {
            var lineStrings = _ccGeometries
                              .ConvertAll(g => g as ILineString).ToArray();

            return(_factory.CreateMultiLineString(lineStrings));
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private IMultiLineString BuildEdges()
        {
            IGeometry temp = null;

            foreach (ILineString line in strings)
            {
                if (temp == null)
                {
                    temp = line;
                }
                else
                {
                    temp = temp.Union(line);
                }
            }

            IMultiLineString edges;

            if (temp == null || temp.NumGeometries == 0)
            {
                edges = MultiLineString.Empty;
            }
            else if (temp.NumGeometries == 1)
            {
                edges = factory.CreateMultiLineString(new ILineString[] { (ILineString)temp, });
            }
            else
            {
                edges = (IMultiLineString)temp;
            }
            return(edges);
        }
コード例 #7
0
        /// <summary>
        /// Builds a geometry (<see cref="LineString" /> or <see cref="MultiLineString" />)
        /// representing the sequence.
        /// </summary>
        /// <param name="sequences">
        /// A <see cref="IList" /> of <see cref="IList" />s of <see cref="DirectedEdge" />s
        /// with <see cref="LineMergeEdge" />s as their parent edges.
        /// </param>
        /// <returns>
        /// The sequenced geometry, or <c>null</c> if no sequence exists.
        /// </returns>
        private IGeometry BuildSequencedGeometry(IEnumerable sequences)
        {
            IList lines = new ArrayList();

            IEnumerator i1 = sequences.GetEnumerator();

            while (i1.MoveNext())
            {
                IList       seq = (IList)i1.Current;
                IEnumerator i2  = seq.GetEnumerator();
                while (i2.MoveNext())
                {
                    DirectedEdge  de   = (DirectedEdge)i2.Current;
                    LineMergeEdge e    = (LineMergeEdge)de.Edge;
                    ILineString   line = e.Line;

                    ILineString lineToAdd = line;
                    if (!de.EdgeDirection && !line.IsClosed)
                    {
                        lineToAdd = Reverse(line);
                    }

                    lines.Add(lineToAdd);
                }
            }

            if (lines.Count == 0)
            {
                return(factory.CreateMultiLineString(new ILineString[] { }));
            }
            return(factory.BuildGeometry(lines));
        }
コード例 #8
0
        private static IMultiLineString ParseWkbMultiLineString(byte[] blob, ref int offset, IGeometryFactory factory, ReadCoordinatesFunction readCoordinates, GaiaImport gaiaImport)
        {
            int number      = gaiaImport.GetInt32(blob, ref offset);
            var lineStrings = new ILineString[number];

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

                var gt = gaiaImport.GetInt32(blob, ref offset);
                if (ToBaseGeometryType((GaiaGeoGeometry)gt) != GaiaGeoGeometry.GAIA_LINESTRING)
                {
                    throw new Exception();
                }

                //Since Uncompressed MultiGeom can contain compressed we need to set it here also
                readCoordinates = SetReadCoordinatesFunction(gaiaImport, (GaiaGeoGeometry)gt);

                lineStrings[i] = ParseWkbLineString(blob, ref offset, factory, factory.CreateLineString, readCoordinates, gaiaImport);
            }
            return(factory.CreateMultiLineString(lineStrings));
        }
コード例 #9
0
        private IMultiLineString ReadMultiLine(SdoGeometry sdoGeom)
        {
            int[]         elements = sdoGeom.ElemArrayOfInts;
            ILineString[] lines    = new ILineString[sdoGeom.ElemArray.Length / ElementTupleSize];
            int           i        = 0;

            while (i < elements.Length / ElementTupleSize)
            {
                ICoordinateSequence cs = null;
                if (GetElementType(elements, i) == (int)SdoGeometryTypes.ETYPE_COMPOUND.FOURDIGIT)
                {
                    int numCompounds = GetNumCompounds(elements, i);
                    cs = AppendCoordinateSequence(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom));
                    ILineString line = _factory.CreateLineString(cs);
                    lines[i] = line;
                    i       += 1 + numCompounds;
                }
                else
                {
                    cs = AppendCoordinateSequence(cs, GetElementCoordinateSequence(i, sdoGeom, false));
                    ILineString line = _factory.CreateLineString(cs);
                    lines[i] = line;
                    i++;
                }
            }

            IMultiLineString mls = _factory.CreateMultiLineString(lines);

            mls.SRID = (int)sdoGeom.Sdo_Srid;
            return(mls);
        }
コード例 #10
0
ファイル: Shape.cs プロジェクト: yangkf1985/DotSpatial
        /// <summary>
        /// Gets the line for the specified index
        /// </summary>
        /// <returns>A LineString or MultiLineString geometry created from this shape.</returns>
        protected IGeometry FromLine(IGeometryFactory factory)
        {
            if (factory == null)
            {
                factory = Geometry.DefaultFactory;
            }
            List <IBasicLineString> lines = new List <IBasicLineString>();

            foreach (PartRange part in _shapeRange.Parts)
            {
                int i = part.StartIndex;
                List <Coordinate> coords = new List <Coordinate>();
                foreach (Vertex d in part)
                {
                    Coordinate c = new Coordinate(d.X, d.Y);
                    coords.Add(c);
                    if (M != null && M.Length > 0)
                    {
                        c.M = M[i];
                    }
                    if (Z != null && Z.Length > 0)
                    {
                        c.Z = Z[i];
                    }
                    i++;
                }
                lines.Add(factory.CreateLineString(coords));
            }
            if (lines.Count == 1)
            {
                return((IGeometry)lines[0]);
            }
            return(factory.CreateMultiLineString(lines.ToArray()));
        }
コード例 #11
0
 /// <summary>
 /// Creates a MultiLineString.
 /// </summary>
 /// <returns></returns>
 private IGeometry CreateMultiLineString(ICoordinateSequence[] sequences)
 {
     var ls = new ILineString[sequences.Length];
     for (var i = 0; i < sequences.Length; i++)
         ls[i] = _factory.CreateLineString(sequences[i]);
     return _factory.CreateMultiLineString(ls);
 }
コード例 #12
0
        /// <summary>
        /// Writes to the given stream the equilivent shape file record given a Geometry object.
        /// </summary>
        /// <param name="geometry">The geometry object to write.</param>
        /// <param name="writer">The stream to write to.</param>
        /// <param name="factory">The geometry factory to use.</param>
        public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory factory)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }

            var multi = geometry as IMultiLineString;

            if (multi == null)
            {
                var ls = geometry as ILineString;
                if (ls == null)
                {
                    var err = String.Format("Expected geometry that implements 'IMultiLineString' or 'ILineString', but was '{0}'",
                                            geometry.GetType().Name);
                    throw new ArgumentException(err, "geometry");
                }

                var arr = new[] { ls };
                multi = factory.CreateMultiLineString(arr);
            }

            writer.Write((int)ShapeType);

            var box = multi.EnvelopeInternal;

            writer.Write(box.MinX);
            writer.Write(box.MinY);
            writer.Write(box.MaxX);
            writer.Write(box.MaxY);

            var numParts  = multi.NumGeometries;
            var numPoints = multi.NumPoints;

            writer.Write(numParts);
            writer.Write(numPoints);

            // Write the offsets
            var offset = 0;

            for (var i = 0; i < numParts; i++)
            {
                var g = multi.GetGeometryN(i);
                writer.Write(offset);
                offset = offset + g.NumPoints;
            }

            var zList = HasZValue() ? new List <double>() : null;
            var mList = HasMValue() ? new List <double>() : null;

            for (var part = 0; part < numParts; part++)
            {
                var geometryN = (ILineString)multi.GetGeometryN(part);
                var points    = geometryN.CoordinateSequence;
                WriteCoords(points, writer, zList, mList);
            }

            WriteZM(writer, numPoints, zList, mList);
        }
コード例 #13
0
        /// <summary>
        /// Computes the <see cref="IMultiLineString" /> representation of the WKB.
        /// </summary>
        /// <param name="geometryBytes">The WKB representation of the geometry.</param>
        /// <param name="byteOrder">The byte-order of the conversion.</param>
        /// <param name="geometryModel">The geometry model of the conversion.</param>
        /// <param name="factory">The factory used for geometry production.</param>
        /// <returns>The <see cref="IMultiLineString" /> representation of the geometry.</returns>
        private static IMultiLineString ComputeMultiLineString(Byte[] geometryBytes, ByteOrder byteOrder, GeometryModel geometryModel, IGeometryFactory factory)
        {
            Int32 coordinateSize  = (geometryModel == GeometryModel.Spatial3D) ? 24 : 16;
            Int32 lineStringCount = EndianBitConverter.ToInt32(geometryBytes, 5, byteOrder);

            ILineString[] lineStrings = new ILineString[lineStringCount];

            Int32 lineStringStartIndex = 9;

            for (Int32 i = 0; i < lineStringCount; i++)
            {
                Int32 coordinateCount = EndianBitConverter.ToInt32(geometryBytes, lineStringStartIndex, byteOrder);
                lineStringStartIndex += 4;

                Coordinate[] coordinates = new Coordinate[coordinateCount];

                for (Int32 byteIndex = lineStringStartIndex, coordinateIndex = 0; coordinateIndex < coordinateCount; byteIndex += coordinateSize, coordinateIndex++)
                {
                    coordinates[coordinateIndex] = new Coordinate(EndianBitConverter.ToDouble(geometryBytes, byteIndex, byteOrder),
                                                                  EndianBitConverter.ToDouble(geometryBytes, byteIndex + 8, byteOrder),
                                                                  geometryModel == GeometryModel.Spatial3D ? EndianBitConverter.ToDouble(geometryBytes, byteIndex + 16, byteOrder) : 0);
                }

                lineStrings[i] = factory.CreateLineString(coordinates);
            }

            return(factory.CreateMultiLineString(lineStrings));
        }
コード例 #14
0
 public static IReadOnlyList <MultiLineStringEntity> CreateMultiLineStringEntities(IGeometryFactory factory)
 => new[]
 {
     new MultiLineStringEntity
     {
         Id = 1,
         MultiLineString = factory.CreateMultiLineString(
             new[]
         {
             factory.CreateLineString(
                 new[]
             {
                 new Coordinate(0, 0),
                 new Coordinate(0, 1)
             }),
             factory.CreateLineString(
                 new[]
             {
                 new Coordinate(1, 0),
                 new Coordinate(1, 1)
             })
         })
     },
     new MultiLineStringEntity
     {
         Id = 2,
         MultiLineString = null
     }
 };
コード例 #15
0
        /// <summary>
        /// Converts the Well-known Binary (WKB) to a multi line string.
        /// </summary>
        /// <param name="geometryBytes">The WKB representation of the multi line string.</param>
        /// <param name="byteOrder">The byte-order of the conversion.</param>
        /// <param name="dimension">The dimension of the geometry.</param>
        /// <param name="factory">The geometry factory.</param>
        /// <returns>The converted multi line string.</returns>
        private static IMultiLineString ToMultiLineString(Byte[] geometryBytes, ByteOrder byteOrder, Int32 dimension, IGeometryFactory factory)
        {
            Int32 coordinateSize  = (dimension == 3) ? 24 : 16;
            Int32 lineStringCount = EndianBitConverter.ToInt32(geometryBytes, 5, byteOrder);

            ILineString[] lineStrings = new ILineString[lineStringCount];

            Int32 lineStringStartIndex = 9;

            for (Int32 lineStringIndex = 0; lineStringIndex < lineStringCount; lineStringIndex++)
            {
                Int32 coordinateCount = EndianBitConverter.ToInt32(geometryBytes, lineStringStartIndex, byteOrder);
                lineStringStartIndex += 4;

                Coordinate[] coordinates = new Coordinate[coordinateCount];

                for (Int32 byteIndex = lineStringStartIndex, coordinateIndex = 0; coordinateIndex < coordinateCount; byteIndex += coordinateSize, coordinateIndex++)
                {
                    coordinates[coordinateIndex] = new Coordinate(EndianBitConverter.ToDouble(geometryBytes, byteIndex, byteOrder),
                                                                  EndianBitConverter.ToDouble(geometryBytes, byteIndex + 8, byteOrder),
                                                                  dimension == 3 ? EndianBitConverter.ToDouble(geometryBytes, byteIndex + 16, byteOrder) : 0);
                }

                lineStrings[lineStringIndex] = factory.CreateLineString(coordinates);

                lineStringStartIndex += coordinates.Length * coordinateSize;
            }

            return(factory.CreateMultiLineString(lineStrings));
        }
コード例 #16
0
        /// <summary>
        /// Reads a <see cref="IMultiLineString"/> from the input stream.
        /// </summary>
        /// <param name="reader">The binary reader.</param>
        /// <param name="factory">The geometry factory to use for geometry creation.</param>
        /// <returns>The MultiLineString</returns>
        protected IMultiLineString ReadMultiLineString(BinaryReader reader, IGeometryFactory factory)
        {
            int numGeometries = reader.ReadInt32();
            var strings       = new ILineString[numGeometries];

            ReadGeometryArray(reader, strings);
            return(factory.CreateMultiLineString(strings));
        }
コード例 #17
0
 public object ToMultiLineString(CoordinateInfo[][] coordinates)
 {
     if (coordinates.Length == 0)
     {
         return(MultiLineString.Empty);
     }
     return(_geometryFactory.CreateMultiLineString(coordinates.Select(ToLineString).Cast <IBasicLineString>().ToArray()));
 }
コード例 #18
0
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
        {
            reader.Read();
            if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "type"))
            {
                throw new ArgumentException("invalid tokentype: " + reader.TokenType);
            }
            reader.Read();
            if (reader.TokenType != JsonToken.String)
            {
                throw new ArgumentException("invalid tokentype: " + reader.TokenType);
            }
            GeoJsonObjectType geometryType = (GeoJsonObjectType)Enum.Parse(typeof(GeoJsonObjectType), (string)reader.Value);

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

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

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

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

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

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

            case GeoJsonObjectType.GeometryCollection:
                List <IGeometry> geoms = _geoJsonSerializer.Deserialize <List <IGeometry> >(reader);
                return(_factory.CreateGeometryCollection(geoms.ToArray()));
            }
            return(null);
        }
コード例 #19
0
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivent geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="geometryFactory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory)
        {
            int shapeTypeNum             = file.ReadInt32();
            ShapeGeometryTypes shapeType = (ShapeGeometryTypes)Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString());

            if (!(shapeType == ShapeGeometryTypes.LineString || shapeType == ShapeGeometryTypes.LineStringM ||
                  shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM))
            {
                throw new ShapefileException("Attempting to load a non-arc as arc.");
            }

            //read and for now ignore bounds.
            double[] box = new double[4];
            for (int i = 0; i < 4; i++)
            {
                double d = file.ReadDouble();
                box[i] = d;
            }

            int numParts  = file.ReadInt32();
            int numPoints = file.ReadInt32();

            int[] partOffsets = new int[numParts];
            for (int i = 0; i < numParts; i++)
            {
                partOffsets[i] = file.ReadInt32();
            }

            ILineString[] lines = new LineString[numParts];
            int           start, finish, length;

            for (int part = 0; part < numParts; part++)
            {
                start = partOffsets[part];
                if (part == numParts - 1)
                {
                    finish = numPoints;
                }
                else
                {
                    finish = partOffsets[part + 1];
                }
                length = finish - start;
                CoordinateList points = new CoordinateList();
                points.Capacity = length;
                Coordinate external;
                for (int i = 0; i < length; i++)
                {
                    external = new Coordinate(file.ReadDouble(), file.ReadDouble());
                    // points.Add(geometryFactory.PrecisionModel.ToInternal(external));
                    new PrecisionModel(geometryFactory.PrecisionModel).MakePrecise(external);
                    points.Add(external);
                }
                lines[part] = geometryFactory.CreateLineString((ICoordinate[])points.ToArray(typeof(ICoordinate)));
            }
            return(geometryFactory.CreateMultiLineString(lines));
        }
コード例 #20
0
 private IMultiLineString CreateMultiLineString(List <Coordinate[]> coordinates)
 {
     ILineString[] strings = new ILineString[coordinates.Count];
     for (int i = 0; i < coordinates.Count; i++)
     {
         strings[i] = _factory.CreateLineString(coordinates[i]);
     }
     return(_factory.CreateMultiLineString(strings));
 }
コード例 #21
0
 private IMultiLineString CreateMultiLineString(int[][] data)
 {
     ILineString[] list = new ILineString[data.Length];
     for (int i = 0; i < data.Length; i++)
     {
         list[i] = CreateLineString(data[i]);
     }
     return(_factory.CreateMultiLineString(list));
 }
コード例 #22
0
        /// <summary>
        /// Converts the geometry from Geography Markup Language (GML) representation.
        /// </summary>
        /// <param name="source">The source collection of XML elements.</param>
        /// <param name="geometryFactory">The geometry factory.</param>
        /// <param name="referenceSystemFactory">The reference system factory.</param>
        /// <returns>The converted geometry.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// The source is null.
        /// or
        /// The geometry factory is null.
        /// or
        /// The reference system factory is null.
        /// </exception>
        /// <exception cref="System.ArgumentException">The specified source is invalid.</exception>
        public static IGeometry ToGeometry(this IEnumerable <XElement> source, IGeometryFactory geometryFactory, IReferenceSystemFactory referenceSystemFactory)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (geometryFactory == null)
            {
                throw new ArgumentNullException(nameof(geometryFactory));
            }
            if (referenceSystemFactory == null)
            {
                throw new ArgumentNullException(nameof(referenceSystemFactory));
            }

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

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

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

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

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

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

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

                return(geometryFactory.CreateGeometryCollection(geometries));
            }
            catch (Exception ex)
            {
                throw new ArgumentException(CoreMessages.SourceIsInvalid, nameof(source), ex);
            }
        }
コード例 #23
0
        private IMultiLineString ReadMultiLine(int dim, int lrsDim,
                                               SdoGeometry sdoGeom)
        {
            bool lrs = sdoGeom.LRS > 0;

            decimal[]     info  = sdoGeom.ElemArray;
            ILineString[] lines =
                lrs
                    ? new MLineString[sdoGeom.ElemArray.Length]
                    : new LineString[sdoGeom.ElemArray.Length];
            int i = 0;

            while (i < info.Length)
            {
                ICoordinateSequence cs = null;
                //if (info.getElementType(i).isCompound())
                //{
                //    int numCompounds = info.getNumCompounds(i);
                //    cs = Add(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom));
                //    LineString line =
                //        lrs
                //            ? factory.CreateMultiLineString(cs)
                //            : factory.CreateLineString(cs);
                //    lines[i] = line;
                //    i += 1 + numCompounds;
                //}
                //else
                //{
                cs = Add(cs, GetElementCSeq(i, sdoGeom, false));
                //LineString line = lrs ? (LineString)factory.CreateMultiLineString(cs) : factory.CreateLineString(cs);
                ILineString line = factory.CreateLineString(cs);
                lines[i] = line;
                i++;
                //}
            }

            IMultiLineString mls = lrs
                                       ? factory.CreateMultiLineString((MLineString[])lines)
                                       : factory.CreateMultiLineString(lines);

            mls.SRID = (int)sdoGeom.Sdo_Srid;
            return(mls);
        }
コード例 #24
0
ファイル: GeometryFromWKT.cs プロジェクト: cugkgq/Project
        /// <summary>
        /// Creates a <see cref="IMultiLineString"/> 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>
        /// <param name="factory">The factory to create the result geometry</param>
        /// <returns>a <see cref="MultiLineString"/> specified by the next token in the stream</returns>
        private static IMultiLineString ReadMultiLineStringText(WktStreamTokenizer tokenizer, IGeometryFactory factory)
        {
            string nextToken = GetNextEmptyOrOpener(tokenizer);

            if (nextToken == "EMPTY")
            {
                return(factory.CreateMultiLineString(null));
            }

            var lineStrings = new List <ILineString>();

            lineStrings.Add(ReadLineStringText(tokenizer, factory));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                lineStrings.Add(ReadLineStringText(tokenizer, factory));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return(factory.CreateMultiLineString(lineStrings.ToArray()));
        }
コード例 #25
0
        private IGeometry ToGeoAPIMultiLineString(SpatialLite.Core.API.IMultiLineString geometry)
        {
            var lst = new List <ILineString>();

            foreach (var line in geometry.Geometries)
            {
                lst.Add((ILineString)ToGeoAPILineString(line));
            }

            return(_factory.CreateMultiLineString(lst.ToArray()));
        }
コード例 #26
0
        /// <summary>
        /// Transforms a <see cref="GeoAPI.Geometries.IMultiLineString"/>.
        /// </summary>
        /// <param name="lines">MultiLineString to transform</param>
        /// <param name="from">Source Projection</param>
        /// <param name="to">Target Projection</param>
        /// <param name="toFactory">The factory to create geometries for <paramref name="to"/></param>
        /// <returns>Transformed MultiLineString</returns>
        public static IMultiLineString TransformMultiLineString(IMultiLineString lines, ProjectionInfo from, ProjectionInfo to, IGeometryFactory toFactory)
        {
            var l = new ILineString[lines.Count];

            for (var i = 0; i < lines.Count; i++)
            {
                l[i] = TransformLineString((ILineString)lines.GetGeometryN(i), from, to, toFactory);
            }

            return(toFactory.CreateMultiLineString(l));
        }
コード例 #27
0
        /// <summary>
        /// Transforms a <see cref="GeoAPI.Geometries.IMultiLineString"/>.
        /// </summary>
        /// <param name="lines">MultiLineString to transform</param>
        /// <param name="transform">MathTransform</param>
        /// <param name="targetFactory">The factory to create the target geometry</param>
        /// <returns>Transformed MultiLineString</returns>
        public static IMultiLineString TransformMultiLineString(IMultiLineString lines, IMathTransform transform, IGeometryFactory targetFactory)
        {
            var lineList = new ILineString[lines.NumGeometries];

            for (var i = 0; i < lines.NumGeometries; i++)
            {
                var line = (ILineString)lines[i];
                lineList[i] = TransformLineString(line, transform, targetFactory);
            }
            return(targetFactory.CreateMultiLineString(lineList));
        }
コード例 #28
0
ファイル: GeometryTransform.cs プロジェクト: Sony-NS/SharpMap
        /// <summary>
        /// Transforms a <see cref="MultiLineString" /> object.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="lines"></param>
        /// <param name="transform"></param>
        /// <returns></returns>
        public static IMultiLineString TransformMultiLineString(IGeometryFactory factory,
                                                                IMultiLineString lines, IMathTransform transform)
        {
            List <ILineString> strings = new List <ILineString>(lines.Geometries.Length);

            foreach (ILineString ls in lines.Geometries)
            {
                ILineString item = TransformLineString(factory, ls, transform);
                strings.Add(item);
            }
            return(factory.CreateMultiLineString(strings.ToArray()));
        }
コード例 #29
0
        internal static NTSMultiLineString ToNTSMultiLineString(Geometries.MultiLineString geom,
                                                                IGeometryFactory factory)
        {
            NTSLineString[] lstrings = new NTSLineString[geom.LineStrings.Count];
            int             index    = 0;

            foreach (Geometries.LineString lstring in geom.LineStrings)
            {
                lstrings[index++] = ToNTSLineString(lstring, factory);
            }
            return(factory.CreateMultiLineString(lstrings) as NTSMultiLineString);
        }
コード例 #30
0
        public void TestIsClosed()
        {
            var l = (LineString)reader.Read("LINESTRING EMPTY");

            Assert.IsTrue(l.IsEmpty);
            Assert.IsTrue(!l.IsClosed);

            var r = geometryFactory.CreateLinearRing((ICoordinateSequence)null);

            Assert.IsTrue(r.IsEmpty);
            Assert.IsTrue(r.IsClosed);

            var m = geometryFactory.CreateMultiLineString(
                new ILineString[] { l, r });

            Assert.IsTrue(!m.IsClosed);

            var m2 = geometryFactory.CreateMultiLineString(
                new ILineString[] { r });

            Assert.IsTrue(!m2.IsClosed);
        }
コード例 #31
0
ファイル: WKTReader.cs プロジェクト: ghq1254544150/_SharpMap
        /// <summary>
        /// Creates a <c>MultiLineString</c> using the next token in the stream.
        /// </summary>
        /// <param name="tokens">
        /// Tokenizer over a stream of text in Well-known Text
        /// format. The next tokens must form a MultiLineString Text.
        /// </param>
        /// <returns>
        /// A <c>MultiLineString</c> specified by the
        /// next token in the stream.</returns>
        private IMultiLineString ReadMultiLineStringText(IList tokens)
        {
            string nextToken = GetNextEmptyOrOpener(tokens);

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

            List <ILineString> lineStrings = new List <ILineString>();
            ILineString        lineString  = ReadLineStringText(tokens);

            lineStrings.Add(lineString);
            nextToken = GetNextCloserOrComma(tokens);
            while (nextToken.Equals(","))
            {
                lineString = ReadLineStringText(tokens);
                lineStrings.Add(lineString);
                nextToken = GetNextCloserOrComma(tokens);
            }
            return(geometryFactory.CreateMultiLineString(lineStrings.ToArray()));
        }
コード例 #32
0
        /// <summary>
        /// Converts a collection of <see cref="ISegmentString"/>s into a <see cref="IGeometry"/>.
        /// The geometry will be either a <see cref="ILineString"/> 
        /// or a <see cref="IMultiLineString"/> (possibly empty).
        /// </summary>
        /// <param name="segStrings">A collection of <see cref="ISegmentString"/>.</param>
        /// <param name="geomFact">A geometry factory</param>
        /// <returns>A <see cref="ILineString"/> or a <see cref="IMultiLineString"/>.</returns>
        public static IGeometry ToGeometry(IList<ISegmentString> segStrings, IGeometryFactory geomFact)
        {
            ILineString[] lines = new ILineString[segStrings.Count];
            int index = 0;

            foreach (ISegmentString ss in segStrings)
            {
                ILineString line = geomFact.CreateLineString(ss.Coordinates);
                lines[index++] = line;
            }
            if (lines.Length == 1)
                return lines[0];
            return geomFact.CreateMultiLineString(lines);
        }
コード例 #33
0
ファイル: MultiLineHandler.cs プロジェクト: lishxi/_SharpMap
		/// <summary>
		/// Reads a stream and converts the shapefile record to an equilivent geometry object.
		/// </summary>
		/// <param name="file">The stream to read.</param>
		/// <param name="geometryFactory">The geometry factory to use when making the object.</param>
		/// <returns>The Geometry object that represents the shape file record.</returns>
		public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory)
		{
			int shapeTypeNum = file.ReadInt32();
            ShapeGeometryTypes shapeType = (ShapeGeometryTypes)Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString());
            if( ! ( shapeType == ShapeGeometryTypes.LineString  || shapeType == ShapeGeometryTypes.LineStringM   ||
                    shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM  ))
				throw new ShapefileException("Attempting to load a non-arc as arc.");

			//read and for now ignore bounds.
			double[] box = new double[4];
			for (int i = 0; i < 4; i++) 
			{
				double d= file.ReadDouble();
				box[i] =d;
			}
        
			int numParts = file.ReadInt32();
			int numPoints = file.ReadInt32();
			int[] partOffsets = new int[numParts];
			for (int i = 0; i < numParts; i++)
				partOffsets[i] = file.ReadInt32();
			
			ILineString[] lines = new ILineString[numParts];
			int start, finish, length;
			for (int part = 0; part < numParts; part++)
			{
				start = partOffsets[part];
				if (part == numParts - 1)
					 finish = numPoints;
				else finish = partOffsets[part + 1];
				length = finish - start;
                CoordinateList points = new CoordinateList();
				points.Capacity=length;
				ICoordinate external;
				for (int i = 0; i < length; i++)
				{
					external = new Coordinate(file.ReadDouble(),file.ReadDouble());
					geometryFactory.PrecisionModel.MakePrecise( external);
                    points.Add(external);
				}
                lines[part] = geometryFactory.CreateLineString(points.ToArray());
			}
			return geometryFactory.CreateMultiLineString(lines);
		}
コード例 #34
0
 /// <summary>
 /// Gets the geometry for the edges in the subdivision as a <see cref="IMultiLineString"/>
 /// containing 2-point lines.
 /// </summary>
 /// <param name="geomFact">the GeometryFactory to use</param>
 /// <returns>a IMultiLineString</returns>
 public IMultiLineString GetEdges(IGeometryFactory geomFact)
 {
     var quadEdges = GetPrimaryEdges(false);
     ILineString[] edges = new LineString[quadEdges.Count];
     int i = 0;
     foreach (var qe in quadEdges)
     {
         edges[i++] = geomFact.CreateLineString(new[] {
                                                 qe.Orig.Coordinate, qe.Dest.Coordinate });
     }
     return geomFact.CreateMultiLineString(edges);
 }
コード例 #35
0
        /// <summary>
        /// Transforms a <see cref="GeoAPI.Geometries.IMultiLineString"/>.
        /// </summary>
        /// <param name="lines">MultiLineString to transform</param>
        /// <param name="from">Source Projection</param>
        /// <param name="to">Target Projection</param>
        /// <param name="toFactory">The factory to create geometries for <paramref name="to"/></param>
        /// <returns>Transformed MultiLineString</returns>
        public static IMultiLineString TransformMultiLineString(IMultiLineString lines, ProjectionInfo from, ProjectionInfo to, IGeometryFactory toFactory)
        {
            var l = new ILineString[lines.Count];
            for (var i = 0; i < lines.Count; i++)
                l[i] = TransformLineString((ILineString)lines.GetGeometryN(i), from, to, toFactory);

            return toFactory.CreateMultiLineString(l);
        }
コード例 #36
0
 private static ILineal RandomLinealZ(IGeometryFactory geometryFactory)
 {
     switch (Random.Next(0, 2))
     {
         case 0:
             return geometryFactory.CreateLineString(RandomCoordinatesZ(geometryFactory, 2, 10));
         case 1:
             var ls = new ILineString[Random.Next(2, 5)];
             for (int i = 0; i < ls.Length; i++)
                 ls[i] = geometryFactory.CreateLineString(RandomCoordinatesZ(geometryFactory, 2, 15));
             return geometryFactory.CreateMultiLineString(ls);
     }
     return geometryFactory.CreateLineString(RandomCoordinatesZ(geometryFactory, 2, 10));
 }
コード例 #37
0
 /// <summary>
 /// Transforms a <see cref="GeoAPI.Geometries.IMultiLineString"/>.
 /// </summary>
 /// <param name="lines">MultiLineString to transform</param>
 /// <param name="transform">MathTransform</param>
 /// <param name="targetFactory">The factory to create the target geometry</param>
 /// <returns>Transformed MultiLineString</returns>
 public static IMultiLineString TransformMultiLineString(IMultiLineString lines, IMathTransform transform, IGeometryFactory targetFactory)
 {
     var lineList = new ILineString[lines.NumGeometries];
     for (var i = 0; i < lines.NumGeometries; i++)
     {
         var line = (ILineString)lines[i];
         lineList[i] = TransformLineString(line, transform, targetFactory);
     }
     return targetFactory.CreateMultiLineString(lineList);
 }
コード例 #38
0
 internal static NTSMultiLineString ToNTSMultiLineString(Geometries.MultiLineString geom,
     IGeometryFactory factory)
 {
     NTSLineString[] lstrings = new NTSLineString[geom.LineStrings.Count];
     int index = 0;
     foreach (Geometries.LineString lstring in geom.LineStrings)
         lstrings[index++] = ToNTSLineString(lstring, factory);
     return factory.CreateMultiLineString(lstrings) as NTSMultiLineString;
 }
コード例 #39
0
        /// <summary>
        /// Creates a <see cref="IMultiLineString"/> 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>
        /// <param name="factory">The factory to create the result geometry</param>
        /// <returns>a <see cref="MultiLineString"/> specified by the next token in the stream</returns>
        private static IMultiLineString ReadMultiLineStringText(WktStreamTokenizer tokenizer, IGeometryFactory factory)
        {
            string nextToken = GetNextEmptyOrOpener(tokenizer);
            if (nextToken == "EMPTY")
                return factory.CreateMultiLineString(null);

            var lineStrings = new List<ILineString>();
            lineStrings.Add(ReadLineStringText(tokenizer, factory));
            nextToken = GetNextCloserOrComma(tokenizer);
            while (nextToken == ",")
            {
                lineStrings.Add(ReadLineStringText(tokenizer, factory));
                nextToken = GetNextCloserOrComma(tokenizer);
            }
            return factory.CreateMultiLineString(lineStrings.ToArray());
        }
コード例 #40
0
        /// <summary>
        /// Writes to the given stream the equilivent shape file record given a Geometry object.
        /// </summary>
        /// <param name="geometry">The geometry object to write.</param>
        /// <param name="file">The stream to write to.</param>
        /// <param name="geometryFactory">The geometry factory to use.</param>
        public override void Write(IGeometry geometry, BinaryWriter file, IGeometryFactory geometryFactory)
        {
            // Force to use a MultiGeometry
            IMultiLineString multi;
            if (geometry is IGeometryCollection)
                 multi = (IMultiLineString) geometry;
            else multi = geometryFactory.CreateMultiLineString(new ILineString[] { (ILineString) geometry });

            file.Write(int.Parse(Enum.Format(typeof(ShapeGeometryType), ShapeType, "d")));
        
            IEnvelope box = multi.EnvelopeInternal;
            file.Write(box.MinX);
            file.Write(box.MinY);
            file.Write(box.MaxX);
            file.Write(box.MaxY);
        
            int numParts = multi.NumGeometries;
            int numPoints = multi.NumPoints;
        
            file.Write(numParts);		
            file.Write(numPoints);      
        
            // Write the offsets
            int offset=0;
            for (int i = 0; i < numParts; i++)
            {
                IGeometry g = multi.GetGeometryN(i);
                file.Write( offset );
                offset = offset + g.NumPoints;
            }
        
            for (int part = 0; part < numParts; part++)
            {
                CoordinateList points = new CoordinateList(multi.GetGeometryN(part).Coordinates);
                for (int i = 0; i < points.Count; i++)
                {
                    ICoordinate external = points[i];
                    file.Write(external.X);
                    file.Write(external.Y);
                }
            }
        }
コード例 #41
0
        /// <summary>
        /// Writes to the given stream the equilivent shape file record given a Geometry object.
        /// </summary>
        /// <param name="geometry">The geometry object to write.</param>
        /// <param name="writer">The stream to write to.</param>
        /// <param name="geometryFactory">The geometry factory to use.</param>
        public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory geometryFactory)
        {
            // Force to use a MultiGeometry
            IMultiLineString multi;
            if (geometry is IGeometryCollection)
                multi = (IMultiLineString)geometry;
            else
                multi = geometryFactory.CreateMultiLineString(new[] { (ILineString)geometry });

            writer.Write((int)ShapeType);

            var box = multi.EnvelopeInternal;
            writer.Write(box.MinX);
            writer.Write(box.MinY);
            writer.Write(box.MaxX);
            writer.Write(box.MaxY);

            var numParts = multi.NumGeometries;
            var numPoints = multi.NumPoints;

            writer.Write(numParts);
            writer.Write(numPoints);

            // Write the offsets
            var offset = 0;
            for (var i = 0; i < numParts; i++)
            {
                var g = multi.GetGeometryN(i);
                writer.Write(offset);
                offset = offset + g.NumPoints;
            }

            var zList = HasZValue() ? new List<double>() : null;
            var mList = HasMValue() ? new List<double>() : null;

            for (var part = 0; part < numParts; part++)
            {
                var geometryN = (ILineString)multi.GetGeometryN(part);
                var points = geometryN.CoordinateSequence;
                WriteCoords(points, writer, zList, mList);
            }

            WriteZM(writer, numPoints, zList, mList);
        }
コード例 #42
0
        private static IMultiLineString CreateWKBMultiLineString(BinaryReader reader, WkbByteOrder byteOrder, IGeometryFactory factory)
        {
            // Get the number of linestrings in this multilinestring.
            var numLineStrings = (int) ReadUInt32(reader, byteOrder);

            // Create a new array for the linestrings .
            var lines = new ILineString[numLineStrings];

            // 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.
                lines[i] = CreateWKBLineString(reader, byteOrder, factory);
            }

            // Create and return the MultiLineString.
            return factory.CreateMultiLineString(lines);
        }
コード例 #43
0
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivent geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="totalRecordLength">Total length of the record we are about to read</param>
        /// <param name="geometryFactory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory geometryFactory)
        {
            int totalRead = 0;
            var type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead);
            if (type == ShapeGeometryType.NullShape)
                return geometryFactory.CreateMultiLineString(null);

            if (type != ShapeType)
                throw new ShapefileException(string.Format("Encountered a '{0}' instead of a  '{1}'", type, ShapeType));

            // Read and for now ignore bounds.
            int bblength = GetBoundingBoxLength();
            boundingBox = new double[bblength];
            for (; boundingBoxIndex < 4; boundingBoxIndex++)
            {
                double d = ReadDouble(file, totalRecordLength, ref totalRead);
                boundingBox[boundingBoxIndex] = d;
            }

            int numParts = ReadInt32(file, totalRecordLength, ref totalRead);
            int numPoints = ReadInt32(file, totalRecordLength, ref totalRead);
            int[] partOffsets = new int[numParts];
            for (int i = 0; i < numParts; i++)
                partOffsets[i] = ReadInt32(file, totalRecordLength, ref totalRead);

            var lines = new List<ILineString>(numParts);
            var buffer = new CoordinateBuffer(numPoints, NoDataBorderValue, true);
            var pm = geometryFactory.PrecisionModel;

            for (var part = 0; part < numParts; part++)
            {
                var start = partOffsets[part];
                var finish = part == numParts - 1
                                 ? numPoints
                                 : partOffsets[part + 1];
                var length = finish - start;
                
                for (var i = 0; i < length; i++)
                {
                    var x = pm.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
                    var y = pm.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
                    buffer.AddCoordinate(x, y);
                }
                buffer.AddMarker();
            }

            // Trond Benum: We have now read all the parts, let's read optional Z and M values
            // and populate Z in the coordinate before we start manipulating the segments
            // We have to track corresponding optional M values and set them up in the 
            // Geometries via ICoordinateSequence further down.
            GetZMValues(file, totalRecordLength, ref totalRead, buffer);

            var sequences = new List<ICoordinateSequence>(buffer.ToSequences(geometryFactory.CoordinateSequenceFactory));

            for (var s = 0; s < sequences.Count; s++)
            {
                var points = sequences[s];

                //Skip garbage input data with 0 points
                if (points.Count < 1) continue;

                var createLineString = true;
                if (points.Count == 1)
                {
                    switch (GeometryInstantiationErrorHandling)
                    {
                        case GeometryInstantiationErrorHandlingOption.ThrowException:
                            break;
                        case GeometryInstantiationErrorHandlingOption.Empty:
                            sequences[s] = geometryFactory.CoordinateSequenceFactory.Create(0, points.Ordinates);
                            break;
                        case GeometryInstantiationErrorHandlingOption.TryFix:
                            sequences[s] = AddCoordinateToSequence(points, geometryFactory.CoordinateSequenceFactory,
                                points.GetOrdinate(0, Ordinate.X), points.GetOrdinate(0, Ordinate.Y),
                                points.GetOrdinate(0, Ordinate.Z), points.GetOrdinate(0, Ordinate.M));
                            break;
                        case GeometryInstantiationErrorHandlingOption.Null:
                            createLineString = false;
                            break;
                    }
                }

                if (createLineString)
                {
                    // Grabs m values if we have them
                    var line = geometryFactory.CreateLineString(points);
                    lines.Add(line);
                }
            }

            geom = (lines.Count != 1)
                ? (IGeometry)geometryFactory.CreateMultiLineString(lines.ToArray())
                : lines[0];          
            return geom;
        }
コード例 #44
0
ファイル: Shape.cs プロジェクト: hanchao/DotSpatial
 /// <summary>
 /// Gets the line for the specified index
 /// </summary>
 /// <returns>A LineString or MultiLineString geometry created from this shape.</returns>
 protected IGeometry FromLine(IGeometryFactory factory)
 {
     if (factory == null) factory = Geometry.DefaultFactory;
     var lines = new List<IBasicLineString>();
     foreach (var part in _shapeRange.Parts)
     {
         var coords = GetCoordinates(part);
         lines.Add(factory.CreateLineString(coords));
     }
     if (lines.Count == 1) return (IGeometry)lines[0];
     return factory.CreateMultiLineString(lines.ToArray());
 }
コード例 #45
0
ファイル: MultiLineHandler.cs プロジェクト: izambakci/tf-net
        /// <summary>
        /// Reads a stream and converts the shapefile record to an equilivent geometry object.
        /// </summary>
        /// <param name="file">The stream to read.</param>
        /// <param name="geometryFactory">The geometry factory to use when making the object.</param>
        /// <returns>The Geometry object that represents the shape file record.</returns>
        public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory)
        {
            int shapeTypeNum = file.ReadInt32();
            ShapeGeometryTypes shapeType = (ShapeGeometryTypes)Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString());

            if (shapeType == ShapeGeometryTypes.NullShape)
                return null;

            if( ! ( shapeType == ShapeGeometryTypes.LineString  || shapeType == ShapeGeometryTypes.LineStringM   ||
                    shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM  ))
                throw new ShapefileException("Attempting to load a non-arc as arc.");

            //read and for now ignore bounds.
            double[] box = new double[4];
            for (int i = 0; i < 4; i++)
            {
                double d= file.ReadDouble();
                box[i] =d;
            }

            int numParts = file.ReadInt32();
            int numPoints = file.ReadInt32();
            int[] partOffsets = new int[numParts];
            for (int i = 0; i < numParts; i++)
                partOffsets[i] = file.ReadInt32();

            ILineString[] lines = new ILineString[numParts];
            int start, finish, length;
            for (int part = 0; part < numParts; part++)
            {
                start = partOffsets[part];
                if (part == numParts - 1)
                     finish = numPoints;
                else finish = partOffsets[part + 1];
                length = finish - start;
                CoordinateList points = new CoordinateList();
                points.Capacity=length;
                ICoordinate external;
                for (int i = 0; i < length; i++)
                {
                    external = new Coordinate(file.ReadDouble(),file.ReadDouble());
                    geometryFactory.PrecisionModel.MakePrecise( external);
                    points.Add(external);
                }
                if (numPoints < 2)
                    lines[part] = geometryFactory.CreateLineString(null as Topology.Geometries.ICoordinate[]);
                else
                    lines[part] = geometryFactory.CreateLineString(points.ToArray());
            }

            //If we have Z-coordinates, read them..
            if (shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM)
            {
                //z-Bounds
                double zMin = file.ReadDouble();
                double zMax = file.ReadDouble();
                for (int part = 0; part < numParts; part++)
                {
                    start = partOffsets[part];
                    if (part == numParts - 1)
                        finish = numPoints;
                    else finish = partOffsets[part + 1];
                    length = finish - start;
                    for (int i = 0; i < length; i++)
                    {
                        double val = file.ReadDouble();
                        if (numPoints > 1)
                        {

                            lines[part].Coordinates[i].Z = val;
                        }
                    }

                }
            }

            //If we have M-coordinates, read them..
            if (shapeType == ShapeGeometryTypes.LineStringM || shapeType == ShapeGeometryTypes.LineStringZM)
            {
                //m-Bounds
                double mMin = file.ReadDouble();
                double mMax = file.ReadDouble();
                for (int part = 0; part < numParts; part++)
                {
                    start = partOffsets[part];
                    if (part == numParts - 1)
                        finish = numPoints;
                    else finish = partOffsets[part + 1];
                    length = finish - start;
                    for (int i = 0; i < length; i++)
                    {
                        double val = file.ReadDouble();
                        //dont store..
                    }

                }
            }

            return geometryFactory.CreateMultiLineString(lines);
        }
コード例 #46
0
        /// <summary>
        /// See http://www.gaia-gis.it/gaia-sins/BLOB-Geometry.html
        /// for the specification of the spatialite BLOB geometry format
        /// Derived from WKB, but unfortunately it is not practical to reuse existing
        /// WKB encoding/decoding code
        /// </summary>
        /// <param name="spatialliteGeom">The geometry blob</param>
        /// <param name="factory">The factory to create the result geometry</param>
        /// <returns>A geometry</returns>
        public static IGeometry Parse(byte[] spatialliteGeom, IGeometryFactory factory)
        {
            var nBytes = spatialliteGeom.Length;
            if (spatialliteGeom.Length < 44
            || spatialliteGeom[0] != 0
            || spatialliteGeom[38] != 0x7C
            || spatialliteGeom[nBytes - 1] != 0xFE)
                throw new ApplicationException("Corrupt SpatialLite geom");

            bool isLittleEndian = spatialliteGeom[1] == 0x01;
            if (spatialliteGeom[1] != 0x00 && spatialliteGeom[1] != 0x01)
                throw new ApplicationException("Corrupt SpatialLite geom");

            int idx = 39;
            int nGType = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);

            if (nGType < 1 || nGType > 7)
                throw new ApplicationException("Unsupported geom type!");

            /* -------------------------------------------------------------------- */
            /*      Point                                                           */
            /* -------------------------------------------------------------------- */
            if (nGType == 1)
            {
                return factory.CreatePoint(ReadPoint(spatialliteGeom, ref idx, isLittleEndian));
            }
            /* -------------------------------------------------------------------- */
            /*      LineString                                                      */
            /* -------------------------------------------------------------------- */
            else if (nGType == 2)
            {
                return ReadLineString(spatialliteGeom, ref idx, isLittleEndian, factory);
            }
            /* -------------------------------------------------------------------- */
            /*      Polygon                                                      */
            /* -------------------------------------------------------------------- */
            else if (nGType == 3)
            {
                return ReadPolygon(spatialliteGeom, ref idx, isLittleEndian, factory);
            }
            /* -------------------------------------------------------------------- */
            /*      MultiPoint                          */
            /* -------------------------------------------------------------------- */
            else if (nGType == 4)
            {
                List<GeoAPI.Geometries.IPoint> pts = new List<GeoAPI.Geometries.IPoint>();
                int numGeoms = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                for (int i = 0; i < numGeoms; i++)
                {
                    if (spatialliteGeom[idx] != 0x69)
                        throw new ApplicationException("FormatError in SpatiaLIteGeom");
                    idx++;
                    int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                    if (gt != 1)
                        throw new ApplicationException("MultiPoint must Contain Point entities");

                    pts.Add(factory.CreatePoint(ReadPoint(spatialliteGeom, ref idx, isLittleEndian)));
                }
                return factory.CreateMultiPoint(pts.ToArray());
            }
            /* -------------------------------------------------------------------- */
            /*      MultiLineString                          */
            /* -------------------------------------------------------------------- */
            else if (nGType == 5)
            {
                List<GeoAPI.Geometries.ILineString> lss = new List<GeoAPI.Geometries.ILineString>();
                int numGeoms = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                for (int i = 0; i < numGeoms; i++)
                {
                    if (spatialliteGeom[idx] != 0x69)
                        throw new ApplicationException("FormatError in SpatiaLIteGeom");
                    idx++;
                    int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                    if (gt != 2)
                        throw new ApplicationException("MultiLineString must contain LineString Entities");
                    lss.Add(ReadLineString(spatialliteGeom, ref idx, isLittleEndian, factory));
                }
                return factory.CreateMultiLineString(lss.ToArray());
            }
            /* -------------------------------------------------------------------- */
            /*      MultiPolygon                                                      */
            /* -------------------------------------------------------------------- */
            else if (nGType == 6)
            {
                List<GeoAPI.Geometries.IPolygon> polys = new List<GeoAPI.Geometries.IPolygon>();
                int numPolys = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                for (int i = 0; i < numPolys; i++)
                {
                    if (spatialliteGeom[idx] != 0x69)
                        throw new ApplicationException("FormatError in SpatiaLIteGeom");
                    idx++;
                    int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
                    if (gt != 3)
                        throw new ApplicationException("Multipolygon must contain Polygon Entities");

                    polys.Add(ReadPolygon(spatialliteGeom, ref idx, isLittleEndian, factory));
                }
                return factory.CreateMultiPolygon(polys.ToArray());
            }

            return null;
        }
コード例 #47
0
        private static IMultiLineString ParseWkbMultiLineString(byte[] blob, ref int offset, IGeometryFactory factory, ReadCoordinatesFunction readCoordinates, GaiaImport gaiaImport)
        {
            int number = gaiaImport.GetInt32(blob, ref offset);
            var lineStrings = new ILineString[number];
            for (var i = 0; i < number; i++)
            {
                if (blob[offset++] != (byte)GaiaGeoBlobMark.GAIA_MARK_ENTITY)
                    throw new Exception();

                var gt = gaiaImport.GetInt32(blob, ref offset);
                if (ToBaseGeometryType((GaiaGeoGeometry)gt) != GaiaGeoGeometry.GAIA_LINESTRING)
                    throw new Exception();

                //Since Uncompressed MultiGeom can contain compressed we need to set it here also
                readCoordinates = SetReadCoordinatesFunction(gaiaImport, (GaiaGeoGeometry)gt);

                lineStrings[i] = ParseWkbLineString(blob, ref offset, factory, factory.CreateLineString, readCoordinates, gaiaImport);
            }
            return factory.CreateMultiLineString(lineStrings);
        }
コード例 #48
0
ファイル: Shape.cs プロジェクト: ExRam/DotSpatial-PCL
 /// <summary>
 /// Gets the line for the specified index
 /// </summary>
 /// <returns>A LineString or MultiLineString geometry created from this shape.</returns>
 protected IGeometry FromLine(IGeometryFactory factory)
 {
     if (factory == null) factory = Geometry.DefaultFactory;
     List<IBasicLineString> lines = new List<IBasicLineString>();
     foreach (PartRange part in _shapeRange.Parts)
     {
         int i = part.StartIndex;
         List<Coordinate> coords = new List<Coordinate>();
         foreach (Vertex d in part)
         {
             Coordinate c = new Coordinate(d.X, d.Y);
             coords.Add(c);
             if (M != null && M.Length > 0) c.M = M[i];
             if (Z != null && Z.Length > 0) c.Z = Z[i];
             i++;
         }
         lines.Add(factory.CreateLineString(coords));
     }
     if (lines.Count == 1) return (IGeometry)lines[0];
     return factory.CreateMultiLineString(lines.ToArray());
 }
コード例 #49
0
        /// <summary>
        /// Creates a <c>MultiLineString</c> using the next token in the stream.
        /// </summary>
        /// <param name="tokens">
        ///   Tokenizer over a stream of text in Well-known Text
        ///   format. The next tokens must form a MultiLineString Text.
        /// </param>
        /// <param name="factory"> </param>
        /// <returns>
        /// A <c>MultiLineString</c> specified by the
        /// next token in the stream.</returns>
        private IMultiLineString ReadMultiLineStringText(IEnumerator<Token> tokens, IGeometryFactory factory)
        {
            string nextToken = GetNextEmptyOrOpener(tokens);
            if (nextToken.Equals("EMPTY"))
                return factory.CreateMultiLineString( new ILineString[] { } );

            var lineStrings = new List<ILineString>();
            var lineString = ReadLineStringText(tokens, factory);
            lineStrings.Add(lineString);
            nextToken = GetNextCloserOrComma(tokens);
            while (nextToken.Equals(",")) {

                lineString = ReadLineStringText(tokens, factory);
                lineStrings.Add(lineString);
                nextToken = GetNextCloserOrComma(tokens);
            }
            return factory.CreateMultiLineString(lineStrings.ToArray());
        }
コード例 #50
0
		/// <summary>
		/// Transforms a <see cref="MultiLineString" /> object.
		/// </summary>
		/// <param name="factory"></param>
		/// <param name="lines"></param>
		/// <param name="transform"></param>
		/// <returns></returns>
        public static IMultiLineString TransformMultiLineString(IGeometryFactory factory,
            IMultiLineString lines, IMathTransform transform)
		{
			List<ILineString> strings = new List<ILineString>(lines.Geometries.Length);
			foreach (ILineString ls in lines.Geometries)
			{
			    ILineString item = TransformLineString(factory, ls, transform);
			    strings.Add(item);
			}
		    return factory.CreateMultiLineString(strings.ToArray());
		}