예제 #1
0
        private void Init()
        {
            MapBindTrace.Source.TraceInformation("Trace started");

            // Check files
            ShapeFileHelper.CheckFiles(_shapeFile);

            // REVERSE
            SqlServerHelper.REVERSE_GEOMETRIES = null;

            // construct Sql table name
            _tableName = SqlServerModel.CleanSQLName(Path.GetFileNameWithoutExtension(_shapeFile));

            // Init reader
            using (ShapefileDataReader reader = new ShapefileDataReader(_shapeFile, GeometryFactory.Default))
            {
                // Get Shape info
                _bounds      = reader.ShapeHeader.Bounds;
                _shapeType   = reader.ShapeHeader.ShapeType;
                _recordCount = reader.RecordCount;

                _fields = new Dictionary <string, Type>();
                foreach (var field in reader.DbaseHeader.Fields)
                {
                    _fields.Add(field.Name, field.Type);
                }

                _idField   = SqlServerModel.GenerateUniqueColName("ID", ShapeFileHelper.TranslateDbfTypesToSql(reader.DbaseHeader.Fields), _tableName);
                _geomField = SqlServerModel.GenerateUniqueColName("geom", ShapeFileHelper.TranslateDbfTypesToSql(reader.DbaseHeader.Fields), _tableName);
            }
        }
        /// <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="factory">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 factory)
        {
            int totalRead = 0;
            ShapeGeometryType type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead);
            //type = (ShapeGeometryType) EnumUtility.Parse(typeof (ShapeGeometryType), shapeTypeNum.ToString());
            if (type == ShapeGeometryType.NullShape)
                return factory.CreatePoint((Coordinate)null);

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

            CoordinateBuffer buffer = new CoordinateBuffer(1, NoDataBorderValue, true);
            IPrecisionModel precisionModel = factory.PrecisionModel;

            double x = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
            double y = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));

            double? z = null, m = null;
            
            // Trond Benum: Let's read optional Z and M values                                
            if (HasZValue() && totalRead < totalRecordLength)
                z = ReadDouble(file, totalRecordLength, ref totalRead);

            if ((HasMValue() || HasZValue()) &&
                (totalRead < totalRecordLength))
                m = ReadDouble(file, totalRecordLength, ref totalRead);

            buffer.AddCoordinate(x, y, z, m);
            return factory.CreatePoint(buffer.ToSequence(factory.CoordinateSequenceFactory));
        }
예제 #3
0
 /// <summary>
 /// Function to determine whether or not the shape type might supply an z-ordinate value
 /// </summary>
 /// <param name="shapeType">The shape type</param>
 /// <returns><value>true</value> if <paramref name="shapeType"/> is one of
 /// <list type="Bullet">
 /// <item><see cref="ShapeGeometryType.PointZM"/></item>
 /// <item><see cref="ShapeGeometryType.MultiPointZM"/></item>
 /// <item><see cref="ShapeGeometryType.LineStringZM"/></item>
 /// <item><see cref="ShapeGeometryType.PolygonZM"/></item>
 /// </list>
 /// </returns>
 private static bool HasZValue(ShapeGeometryType shapeType)
 {
     return(shapeType == ShapeGeometryType.PointZM ||
            shapeType == ShapeGeometryType.MultiPointZM ||
            shapeType == ShapeGeometryType.LineStringZM ||
            shapeType == ShapeGeometryType.PolygonZM);
 }
예제 #4
0
        private static Ordinates GetOrdinatesFromShapeGeometryType(ShapeGeometryType sgt)
        {
            switch (sgt)
            {
            case ShapeGeometryType.Point:
            case ShapeGeometryType.MultiPoint:
            case ShapeGeometryType.LineString:
            case ShapeGeometryType.Polygon:
                return(Ordinates.XY);

            case ShapeGeometryType.PointZ:
            case ShapeGeometryType.MultiPointZ:
            case ShapeGeometryType.LineStringZ:
            case ShapeGeometryType.PolygonZ:
                return(Ordinates.XYZ);

            case ShapeGeometryType.PointM:
            case ShapeGeometryType.MultiPointM:
            case ShapeGeometryType.LineStringM:
            case ShapeGeometryType.PolygonM:
                return(Ordinates.XYM);

            case ShapeGeometryType.PointZM:
            case ShapeGeometryType.MultiPointZM:
            case ShapeGeometryType.LineStringZM:
            case ShapeGeometryType.PolygonZM:
                return(Ordinates.XYZM);

            case ShapeGeometryType.MultiPatch:
                throw new NotSupportedException("FeatureType " + sgt + " not supported.");

            default:
                throw new ArgumentOutOfRangeException("FeatureType " + sgt + " not recognized by the system");
            }
        }
예제 #5
0
		/// <summary>
		/// Returns the appropriate class to convert a shaperecord to an OGIS geometry given the type of shape.
		/// </summary>
		/// <param name="type">The shapefile type.</param>
		/// <returns>An instance of the appropriate handler to convert the shape record to a Geometry object.</returns>
        public static ShapeHandler GetShapeHandler(ShapeGeometryType type) 
		{
			switch (type) 
			{
				case ShapeGeometryType.Point:
                case ShapeGeometryType.PointM:
                case ShapeGeometryType.PointZ:
                case ShapeGeometryType.PointZM:
					return new PointHandler();

                case ShapeGeometryType.Polygon:
                case ShapeGeometryType.PolygonM:
                case ShapeGeometryType.PolygonZ:
                case ShapeGeometryType.PolygonZM:
					return new PolygonHandler();

                case ShapeGeometryType.LineString:
                case ShapeGeometryType.LineStringM:
                case ShapeGeometryType.LineStringZ:
                case ShapeGeometryType.LineStringZM:
					return new MultiLineHandler();

                case ShapeGeometryType.MultiPoint:
                case ShapeGeometryType.MultiPointM:
                case ShapeGeometryType.MultiPointZ:
                case ShapeGeometryType.MultiPointZM:
                    return new MultiPointHandler();

                default:
                    return null;
			}			
		}
예제 #6
0
        private static Ordinates GetOrdinatesFromShapeGeometryType(ShapeGeometryType sgt)
        {
            switch (sgt)
            {
                case ShapeGeometryType.Point:
                case ShapeGeometryType.MultiPoint:
                case ShapeGeometryType.LineString:
                case ShapeGeometryType.Polygon:
                    return Ordinates.XY;

                case ShapeGeometryType.PointZ:
                case ShapeGeometryType.MultiPointZ:
                case ShapeGeometryType.LineStringZ:
                case ShapeGeometryType.PolygonZ:
                    return Ordinates.XYZ;

                case ShapeGeometryType.PointM:
                case ShapeGeometryType.MultiPointM:
                case ShapeGeometryType.LineStringM:
                case ShapeGeometryType.PolygonM:
                    return Ordinates.XYM;

                case ShapeGeometryType.PointZM:
                case ShapeGeometryType.MultiPointZM:
                case ShapeGeometryType.LineStringZM:
                case ShapeGeometryType.PolygonZM:
                    return Ordinates.XYZM;

                case ShapeGeometryType.MultiPatch:
                    throw new NotSupportedException("FeatureType " + sgt + " not supported.");

                default:
                    throw new ArgumentOutOfRangeException("FeatureType " + sgt + " not recognized by the system");
            }
        }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="shapeType"></param>
 /// <returns></returns>
 public static bool IsPolygon(ShapeGeometryType shapeType)
 {
     return(shapeType == ShapeGeometryType.Polygon ||
            //shapeType == ShapeGeometryType.PolygonZ ||
            shapeType == ShapeGeometryType.PolygonM ||
            shapeType == ShapeGeometryType.PolygonZM);
 }
예제 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="shapeType"></param>
 /// <returns></returns>
 public static bool IsMultiPoint(ShapeGeometryType shapeType)
 {
     return(shapeType == ShapeGeometryType.MultiPoint ||
            //shapeType == ShapeGeometryType.MultiPointZ ||
            shapeType == ShapeGeometryType.MultiPointM ||
            shapeType == ShapeGeometryType.MultiPointZM);
 }
예제 #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="shapeType"></param>
 /// <returns></returns>
 public static bool IsLineString(ShapeGeometryType shapeType)
 {
     return(shapeType == ShapeGeometryType.LineString ||
            //shapeType == ShapeGeometryType.LineStringZ ||
            shapeType == ShapeGeometryType.LineStringM ||
            shapeType == ShapeGeometryType.LineStringZM);
 }
예제 #10
0
		/// <summary>
		/// Initializes a new instance of the ShapefileHeader class with values read in from the stream.
		/// </summary>
		/// <remarks>Reads the header information from the stream.</remarks>
		/// <param name="shpBinaryReader">BigEndianBinaryReader stream to the shapefile.</param>
		public ShapefileHeader(BigEndianBinaryReader shpBinaryReader)
		{
			if (shpBinaryReader == null)
				throw new ArgumentNullException("shpBinaryReader");

			_fileCode = shpBinaryReader.ReadInt32BE();	
			if (_fileCode != Shapefile.ShapefileId)
				throw new ShapefileException("The first four bytes of this file indicate this is not a shape file.");

			// skip 5 unsed bytes
			shpBinaryReader.ReadInt32BE();
			shpBinaryReader.ReadInt32BE();
			shpBinaryReader.ReadInt32BE();
			shpBinaryReader.ReadInt32BE();
			shpBinaryReader.ReadInt32BE();

			_fileLength = shpBinaryReader.ReadInt32BE();

			_version = shpBinaryReader.ReadInt32();
			Debug.Assert(_version == 1000, "Shapefile version", String.Format("Expecting only one version (1000), but got {0}",_version));
			int shapeType = shpBinaryReader.ReadInt32();
            _shapeType = (ShapeGeometryType) Enum.Parse(typeof(ShapeGeometryType), shapeType.ToString());

			//read in and store the bounding box
			double[] coords = new double[4];
			for (int i = 0; i < 4; i++)
				coords[i] = shpBinaryReader.ReadDouble();
			_bounds = new Envelope(coords[0], coords[2], coords[1], coords[3]);
			
			// skip z and m bounding boxes.
			for (int i = 0; i < 4; i++)
				shpBinaryReader.ReadDouble();	
		}
예제 #11
0
        /// <summary>
        /// Returns the appropriate class to convert a shaperecord to an OGIS geometry given the type of shape.
        /// </summary>
        /// <param name="type">The shapefile type.</param>
        /// <returns>An instance of the appropriate handler to convert the shape record to a Geometry object.</returns>
        public static ShapeHandler GetShapeHandler(ShapeGeometryType type)
        {
            switch (type)
            {
            case ShapeGeometryType.Point:
            case ShapeGeometryType.PointM:
            case ShapeGeometryType.PointZM:
                return(new PointHandler(type));

            case ShapeGeometryType.Polygon:
            case ShapeGeometryType.PolygonM:
            case ShapeGeometryType.PolygonZM:
                return(new PolygonHandler(type));

            case ShapeGeometryType.LineString:
            case ShapeGeometryType.LineStringM:
            case ShapeGeometryType.LineStringZM:
                return(new MultiLineHandler(type));

            case ShapeGeometryType.MultiPoint:
            case ShapeGeometryType.MultiPointM:
            case ShapeGeometryType.MultiPointZM:
                return(new MultiPointHandler(type));

            case ShapeGeometryType.NullShape:
                return(new NullShapeHandler());

            default:
                return(null);
            }
        }
예제 #12
0
        // see: https://github.com/NetTopologySuite/NetTopologySuite/issues/111
        public void issue_111_polygonhandler_with_invalid_values()
        {
            IGeometryFactory factory = GeometryFactory.Default;

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

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

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

            ShapeGeometryType shapeType = Shapefile.GetShapeType(geometries);

            Assert.AreEqual(ShapeGeometryType.PolygonZM, shapeType);

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

            Assert.Throws <ArgumentException>(() => sfw.Write(geometries));
        }
예제 #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="shapeType"></param>
 /// <returns></returns>
 public static bool HasZValue(ShapeGeometryType shapeType)
 {
     return(shapeType == ShapeGeometryType.PointZ ||
            shapeType == ShapeGeometryType.PointZM ||
            shapeType == ShapeGeometryType.LineStringZ ||
            shapeType == ShapeGeometryType.LineStringZM ||
            shapeType == ShapeGeometryType.PolygonZ ||
            shapeType == ShapeGeometryType.PolygonZM);
 }
예제 #14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="shapeType"></param>
 /// <returns></returns>
 public static bool HasZValue(ShapeGeometryType shapeType)
 {
     return  shapeType == ShapeGeometryType.PointZ ||
             shapeType == ShapeGeometryType.PointZM ||
             shapeType == ShapeGeometryType.LineStringZ ||
             shapeType == ShapeGeometryType.LineStringZM ||
             shapeType == ShapeGeometryType.PolygonZ ||
             shapeType == ShapeGeometryType.PolygonZM;
 }
예제 #15
0
        public ShapefileWriter(IGeometryFactory geometryFactory, IStreamProviderRegistry streamProviderRegistry,
                               ShapeGeometryType geomType)
            : this(geometryFactory)
        {
            _shpStream = streamProviderRegistry[StreamTypes.Shape].OpenWrite(true);
            _shxStream = streamProviderRegistry[StreamTypes.Index].OpenWrite(true);

            _geometryType = geomType;

            _shpBinaryWriter = new BigEndianBinaryWriter(_shpStream);
            _shxBinaryWriter = new BigEndianBinaryWriter(_shxStream);

            WriteShpHeader(_shpBinaryWriter, 0, new Envelope(0, 0, 0, 0));
            WriteShxHeader(_shxBinaryWriter, 0, new Envelope(0, 0, 0, 0));

            _shapeHandler = Shapefile.GetShapeHandler(geomType);
        }
        public ShapefileWriter(IGeometryFactory geometryFactory, IStreamProviderRegistry streamProviderRegistry, ShapeGeometryType geomType)
    : this(geometryFactory)
        {


            _shpStream = streamProviderRegistry[StreamTypes.Shape].OpenWrite(true);
            _shxStream = streamProviderRegistry[StreamTypes.Index].OpenWrite(true);

            _geometryType = geomType;

            _shpBinaryWriter = new BigEndianBinaryWriter(_shpStream);
            _shxBinaryWriter = new BigEndianBinaryWriter(_shxStream);

            WriteShpHeader(_shpBinaryWriter, 0, new Envelope(0, 0, 0, 0));
            WriteShxHeader(_shxBinaryWriter, 0, new Envelope(0, 0, 0, 0));

            _shapeHandler = Shapefile.GetShapeHandler(geomType);
        }
        // see: https://github.com/NetTopologySuite/NetTopologySuite/issues/111
        public void issue_111_pointhandler_with_invalid_values()
        {
            IGeometryFactory factory = GeometryFactory.Default;

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

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

            ShapeGeometryType shapeType = Shapefile.GetShapeType(geometries);

            Assert.AreEqual(ShapeGeometryType.PointZM, shapeType);

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

            sfw.Write(geometries);
        }
예제 #18
0
        /// <summary>
        /// Initializes a new instance of the ShapefileHeader class with values read in from the stream.
        /// </summary>
        /// <remarks>Reads the header information from the stream.</remarks>
        /// <param name="shpBinaryReader">BigEndianBinaryReader stream to the shapefile.</param>
        public ShapefileHeader(BigEndianBinaryReader shpBinaryReader)
        {
            if (shpBinaryReader == null)
            {
                throw new ArgumentNullException("shpBinaryReader");
            }

            _fileCode = shpBinaryReader.ReadInt32BE();
            if (_fileCode != Shapefile.ShapefileId)
            {
                throw new ShapefileException("The first four bytes of this file indicate this is not a shape file.");
            }

            // skip 5 unsed bytes
            shpBinaryReader.ReadInt32BE();
            shpBinaryReader.ReadInt32BE();
            shpBinaryReader.ReadInt32BE();
            shpBinaryReader.ReadInt32BE();
            shpBinaryReader.ReadInt32BE();

            _fileLength = shpBinaryReader.ReadInt32BE();

            _version = shpBinaryReader.ReadInt32();
            Debug.Assert(_version == 1000, "Shapefile version", String.Format("Expecting only one version (1000), but got {0}", _version));
            int shapeType = shpBinaryReader.ReadInt32();

            _shapeType = (ShapeGeometryType)EnumUtility.Parse(typeof(ShapeGeometryType), shapeType.ToString());

            //read in and store the bounding box
            double[] coords = new double[4];
            for (int i = 0; i < 4; i++)
            {
                coords[i] = shpBinaryReader.ReadDouble();
            }
            _bounds = new Envelope(coords[0], coords[2], coords[1], coords[3]);

            // skip z and m bounding boxes.
            for (int i = 0; i < 4; i++)
            {
                shpBinaryReader.ReadDouble();
            }
        }
            /// <summary>
            /// Initializes a new instance of the <see cref="ShapefileEnumerator"/> class.
            /// </summary>
            /// <param name="shapefile"></param>
            public ShapefileEnumerator(ShapeMemoryStreamReader shapefile)
            {
                _parent = shapefile;

                // create a file stream for each enumerator that is given out. This allows the same file
                // to have one or more enumerator. If we used the parents stream - than only one IEnumerator
                // could be given out.
                //var stream = new FileStream(_parent._inputStream, FileMode.Open, FileAccess.Read, FileShare.Read);
                _shpBinaryReader = new BigEndianBinaryReader(_parent._inputStream);

                // skip header - since parent has already read this.
                _shpBinaryReader.ReadBytes(100);
                ShapeGeometryType type = _parent._mainHeader.ShapeType;

                _handler = Shapefile.GetShapeHandler(type);
                if (_handler == null)
                {
                    throw new NotSupportedException("Unsuported shape type:" + type);
                }
            }
예제 #20
0
        public ShapefileWriter(IGeometryFactory geometryFactory, string filename, ShapeGeometryType geomType)
            : this(geometryFactory)
        {
            var folder = Path.GetDirectoryName(filename) ?? ".";
            var file = Path.GetFileNameWithoutExtension(filename);
            if (string.IsNullOrEmpty(file))
                throw new ArgumentException(string.Format("Filename '{0}' is not valid", filename), "filename");
            filename = Path.Combine(folder, file);

            _shpStream = new FileStream(filename + ".shp", FileMode.Create);
            _shxStream = new FileStream(filename + ".shx", FileMode.Create);

            _geometryType = geomType;

            _shpBinaryWriter = new BigEndianBinaryWriter(_shpStream);
            _shxBinaryWriter = new BigEndianBinaryWriter(_shxStream);

            WriteShpHeader(_shpBinaryWriter, 0, new Envelope(0, 0, 0, 0), geomType);
            WriteShxHeader(_shxBinaryWriter, 0, new Envelope(0, 0, 0, 0), geomType);

            _shapeHandler = Shapefile.GetShapeHandler(geomType);
        }
예제 #21
0
        /// <summary>
        /// Reads the shapefile and returns a GeometryCollection representing all the records in the shapefile.
        /// </summary>
        /// <returns>GeometryCollection representing every record in the shapefile.</returns>
        public IGeometryCollection ReadAll()
        {
            var list = new List <IGeometry>();
            ShapeGeometryType type    = _mainHeader.ShapeType;
            ShapeHandler      handler = Shapefile.GetShapeHandler(type);

            if (handler == null)
            {
                throw new NotSupportedException("Unsupported shape type:" + type);
            }

            int i = 0;

            foreach (IGeometry geometry in this)
            {
                list.Add(geometry);
                i++;
            }

            IGeometry[] geomArray = GeometryFactory.ToGeometryArray(list);
            return(_geometryFactory.CreateGeometryCollection(geomArray));
        }
예제 #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public IGeometry Read(BinaryReader reader)
        {
            ShapeGeometryType shapeType = (ShapeGeometryType)reader.ReadInt32();

            switch (shapeType)
            {
            case ShapeGeometryType.Point:
            case ShapeGeometryType.PointM:
            case ShapeGeometryType.PointZ:
            case ShapeGeometryType.PointZM:
                return(ReadPoint(reader));

            case ShapeGeometryType.LineString:
            case ShapeGeometryType.LineStringM:
            case ShapeGeometryType.LineStringZ:
            case ShapeGeometryType.LineStringZM:
                return(ReadLineString(reader));

            case ShapeGeometryType.Polygon:
            case ShapeGeometryType.PolygonM:
            case ShapeGeometryType.PolygonZ:
            case ShapeGeometryType.PolygonZM:
                return(ReadPolygon(reader));

            case ShapeGeometryType.MultiPoint:
            case ShapeGeometryType.MultiPointM:
            case ShapeGeometryType.MultiPointZ:
            case ShapeGeometryType.MultiPointZM:
                return(ReadMultiPoint(reader));

            case ShapeGeometryType.MultiPatch:
                throw new NotImplementedException("FeatureType " + shapeType + " not supported.");

            default:
                throw new ArgumentOutOfRangeException("FeatureType " + shapeType + " not recognized by the system");
            }
        }
예제 #23
0
        public ShapefileWriter(IGeometryFactory geometryFactory, string filename, ShapeGeometryType geomType)
            : this(geometryFactory)
        {
            var folder = Path.GetDirectoryName(filename) ?? ".";
            var file   = Path.GetFileNameWithoutExtension(filename);
            if (string.IsNullOrEmpty(file))
            {
                throw new ArgumentException(string.Format("Filename '{0}' is not valid", filename), "filename");
            }
            filename = Path.Combine(folder, file);

            _shpStream = new FileStream(filename + ".shp", FileMode.Create);
            _shxStream = new FileStream(filename + ".shx", FileMode.Create);

            _geometryType = geomType;

            _shpBinaryWriter = new BigEndianBinaryWriter(_shpStream);
            _shxBinaryWriter = new BigEndianBinaryWriter(_shxStream);

            WriteShpHeader(_shpBinaryWriter, 0, new Envelope(0, 0, 0, 0), geomType);
            WriteShxHeader(_shxBinaryWriter, 0, new Envelope(0, 0, 0, 0), geomType);

            _shapeHandler = Shapefile.GetShapeHandler(geomType);
        }
        // see: https://github.com/NetTopologySuite/NetTopologySuite/issues/111
        public void issue_111_multilinehandler_with_invalid_values()
        {
            IGeometryFactory factory = GeometryFactory.Default;

            Coordinate[] points = new Coordinate[3];
            points[0] = new Coordinate(0, 0);
            points[1] = new Coordinate(1, 0);
            points[2] = new Coordinate(1, 1);
            ILineString ls = factory.CreateLineString(points);

            IMultiLineString mls = factory.CreateMultiLineString(new[] { ls });

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

            ShapeGeometryType shapeType = Shapefile.GetShapeType(geometries);

            Assert.AreEqual(ShapeGeometryType.LineStringZM, shapeType);

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

            sfw.Write(geometries);
        }
예제 #25
0
        private static void WriteShpHeader(BigEndianBinaryWriter shpBinaryWriter, int shpLength, Envelope bounds, ShapeGeometryType shapeType)
        {
            var shpHeader = new ShapefileHeader {
                FileLength = shpLength, Bounds = bounds, ShapeType = shapeType
            };

            // assumes Geometry type of the first item will the same for all other items
            // in the collection.
            shpHeader.Write(shpBinaryWriter);
        }
예제 #26
0
 public ShapefileWriter(IGeometryFactory geometryFactory, string filename, ShapeGeometryType geomType)
     : this(geometryFactory, new ShapefileStreamProviderRegistry(filename, false, false, false), geomType)
 {
 }
예제 #27
0
 /// <summary>
 /// Initializes a buffered writer where you can write shapes individually to the file.
 /// </summary>
 /// <param name="filename">The filename</param>
 /// <param name="geomType">The geometry type</param>
 public ShapefileWriter(string filename, ShapeGeometryType geomType)
     : this(GeometryFactory.Default, filename, geomType)
 {
 }
예제 #28
0
        /// <summary>
        /// Write the enumeration of features to shapefile (shp, shx and dbf)
        /// </summary>
        /// <param name="filename">Filename to create</param>
        /// <param name="features">Enumeration of features to write, features will be enumerated once</param>
        /// <param name="fields">Fields that should be written, only those attributes specified here will be mapped from the feature attributetable while writing</param>
        /// <param name="shapeGeometryType">Type of geometries shapefile</param>
        /// <param name="dbfEncoding">Optional Encoding to be used when writing the DBF-file (default Windows-1252)</param>
        public static void WriteFeatures(string filename, IEnumerable <IFeature> features, DbaseFieldDescriptor[] fields, ShapeGeometryType shapeGeometryType,
                                         Encoding dbfEncoding = null)
        {
            // Set default encoding if not specified
            if (dbfEncoding == null)
            {
                dbfEncoding = Encoding.GetEncoding(1252);
            }

            // Open shapefile and dbase stream writers
            using (var shpWriter = new ShapefileWriter(Path.ChangeExtension(filename, ".shp"), shapeGeometryType))
            {
                using (var dbfWriter = new DbaseFileWriter(Path.ChangeExtension(filename, ".dbf"), dbfEncoding))
                {
                    var dbfHeader = new DbaseFileHeader(dbfEncoding);
                    foreach (var field in fields)
                    {
                        dbfHeader.AddColumn(field.Name, field.DbaseType, field.Length, field.DecimalCount);
                    }
                    dbfWriter.Write(dbfHeader);

                    var numFeatures = 0;
                    foreach (var feature in features)
                    {
                        shpWriter.Write(feature.Geometry);
                        var values = new object[fields.Length];
                        for (var i = 0; i < fields.Length; i++)
                        {
                            values[i] = feature.Attributes[fields[i].Name];
                        }
                        dbfWriter.Write(values);
                        numFeatures++;
                    }

                    // set the number of records
                    dbfHeader.NumRecords = numFeatures;
                    // Update the header
                    dbfWriter.Write(dbfHeader);
                    // write the end of dbase file marker
                    dbfWriter.WriteEndOfDbf();
                    // close the dbase stream
                    dbfWriter.Close();
                }
            }
        }
예제 #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="shapeType"></param>
 /// <returns></returns>
 public static bool IsLineString(ShapeGeometryType shapeType)
 {
     return shapeType == ShapeGeometryType.LineString ||
            //shapeType == ShapeGeometryType.LineStringZ ||
            shapeType == ShapeGeometryType.LineStringM ||
            shapeType == ShapeGeometryType.LineStringZM;
 }
예제 #30
0
 public MultiPointHandler(ShapeGeometryType type) : base(type)
 {                    
 }
 public MultiPointHandler(ShapeGeometryType type) : base(type)
 {
 }
예제 #32
0
        /// <summary>
        /// Write the enumeration of features to shapefile (shp, shx and dbf)
        /// </summary>
        /// <param name="filename">Filename to create</param>
        /// <param name="features">Enumeration of features to write, features will be enumerated once</param>
        /// <param name="fields">Fields that should be written, only those attributes specified here will be mapped from the feature attributetable while writing</param>
        /// <param name="shapeGeometryType">Type of geometries shapefile</param>
        /// <param name="dbfEncoding">Optional Encoding to be used when writing the DBF-file (default Windows-1252)</param>
        public static void WriteFeatures(string filename, IEnumerable<IFeature> features, DbaseFieldDescriptor[] fields, ShapeGeometryType shapeGeometryType,
            Encoding dbfEncoding = null)
        {

            // Set default encoding if not specified
            if (dbfEncoding == null)
                dbfEncoding = Encoding.GetEncoding(1252);

            // Open shapefile and dbase stream writers
            using (var shpWriter = new ShapefileWriter(Path.ChangeExtension(filename, ".shp"), shapeGeometryType))
            {
                using (var dbfWriter = new DbaseFileWriter(Path.ChangeExtension(filename, ".dbf"), dbfEncoding))
                {
                    var dbfHeader = new DbaseFileHeader(dbfEncoding);
                    foreach (var field in fields)
                    {
                        dbfHeader.AddColumn(field.Name, field.DbaseType, field.Length, field.DecimalCount);
                    }
                    dbfWriter.Write(dbfHeader);

                    var numFeatures = 0;
                    foreach (var feature in features)
                    {
                        shpWriter.Write(feature.Geometry);
                        var values = new object[fields.Length];
                        for (var i = 0; i < fields.Length; i++)
                        {
                            values[i] = feature.Attributes[fields[i].Name];
                        }
                        dbfWriter.Write(values);
                        numFeatures++;
                    }

                    // set the number of records
                    dbfHeader.NumRecords = numFeatures;
                    // Update the header
                    dbfWriter.Write(dbfHeader);
                    // write the end of dbase file marker
                    dbfWriter.WriteEndOfDbf();
                    // close the dbase stream
                    dbfWriter.Close();
                }
            }
        }
예제 #33
0
 public PolygonHandler(ShapeGeometryType type)
     : base(type)
 {
 }
예제 #34
0
        public ShapefileWriter(IGeometryFactory geometryFactory, string filename, ShapeGeometryType geomType)
            : this(geometryFactory, new ShapefileStreamProviderRegistry(filename, false, false, false), geomType)
        {

        }
예제 #35
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="shapeType"></param>
 /// <returns></returns>
 public static bool IsPolygon(ShapeGeometryType shapeType)
 {
     return shapeType == ShapeGeometryType.Polygon ||
            //shapeType == ShapeGeometryType.PolygonZ ||
            shapeType == ShapeGeometryType.PolygonM ||
            shapeType == ShapeGeometryType.PolygonZM;
 }
예제 #36
0
 protected ShapeHandler(ShapeGeometryType type)
 {
     _type = type;
 }
 public MultiLineHandler(ShapeGeometryType type) : base(type)
 {
 }
예제 #38
0
 /// <summary>
 /// Initializes a buffered writer where you can write shapes individually to the file.
 /// </summary>
 /// <param name="filename">The filename</param>
 /// <param name="geomType">The geometry type</param>
 public ShapefileWriter(string filename, ShapeGeometryType geomType)
     : this(GeometryFactory.Default, filename, geomType)
 {}
예제 #39
0
 public PolygonHandler(ShapeGeometryType type)
     : base(type)
 {
 }
예제 #40
0
 protected ShapeHandler(ShapeGeometryType type)
 {
     _type = type;
 }
예제 #41
0
        private static void WriteShpHeader(BigEndianBinaryWriter shpBinaryWriter, int shpLength, Envelope bounds, ShapeGeometryType shapeType)
        {
            var shpHeader = new ShapefileHeader {FileLength = shpLength, Bounds = bounds, ShapeType = shapeType};

            // assumes Geometry type of the first item will the same for all other items
            // in the collection.
            shpHeader.Write(shpBinaryWriter);
        }       
예제 #42
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="shapeType"></param>
 /// <returns></returns>
 public static bool IsMultiPoint(ShapeGeometryType shapeType)
 {
     return shapeType == ShapeGeometryType.MultiPoint ||
            //shapeType == ShapeGeometryType.MultiPointZ ||
            shapeType == ShapeGeometryType.MultiPointM ||
            shapeType == ShapeGeometryType.MultiPointZM;
 }
예제 #43
0
 /// <summary>
 /// Function to determine whether or not the shape type might supply an m-ordinate value
 /// </summary>
 /// <param name="shapeType">The shape type</param>
 /// <returns><value>true</value> if <paramref name="shapeType"/> is one of 
 /// <list type="Bullet">
 /// <item><see cref="ShapeGeometryType.PointM"/>, <see cref="ShapeGeometryType.PointZM"/></item>
 /// <item><see cref="ShapeGeometryType.MultiPointM"/>,<see cref="ShapeGeometryType.MultiPointZM"/></item>
 /// <item><see cref="ShapeGeometryType.LineStringM"/>, <see cref="ShapeGeometryType.LineStringZM"/></item>
 /// <item><see cref="ShapeGeometryType.PolygonM"/>, <see cref="ShapeGeometryType.PolygonZM"/></item>
 /// </list>
 /// </returns>
 private static bool HasMValue(ShapeGeometryType shapeType)
 {
     return shapeType == ShapeGeometryType.PointM ||
            shapeType == ShapeGeometryType.PointZM ||
            shapeType == ShapeGeometryType.MultiPointM ||
            shapeType == ShapeGeometryType.MultiPointZM ||
            shapeType == ShapeGeometryType.LineStringM ||
            shapeType == ShapeGeometryType.LineStringZM ||
            shapeType == ShapeGeometryType.PolygonM ||
            shapeType == ShapeGeometryType.PolygonZM;
 }
예제 #44
0
 public MultiLineHandler(ShapeGeometryType type) : base(type)
 {
 }