Example #1
0
        private List <ShapefileRecord> GetAllMainRecords(Stream stream)
        {
            List <ShapefileRecord> records = new List <ShapefileRecord>();

            byte[] streamBuffer;
            try
            {
                stream.Position = 100;
                do
                {
                    streamBuffer = ReadBytesFromStream(stream, 8);
                    if (streamBuffer.Length < 8)
                    {
                        break;
                    }
                    else
                    {
                        ShapefileRecord myRecord = new ShapefileRecord(streamBuffer);
                        myRecord.RecordContents = ReadBytesFromStream(stream, myRecord.ContentLength * 2);
                        records.Add(myRecord);
                    }
                } while (streamBuffer.Length > 0);
            }
            catch
            {
                //Clear the list so it is returned empty.
                records.Clear();
            }
            return(records);
        }
Example #2
0
    public static ShapefileConverter Create <T>(IEnumerable <T> items,
                                                Func <T, DbGeometry> geoFunc,
                                                Func <T, string> nameFunc)
        where T : class
    {
        var converter = new ShapefileConverter();

        foreach (var item in items)
        {
            var rec      = new ShapefileRecord();
            var points   = new List <Point>();
            var geometry = geoFunc(item);
            Debug.Assert(geometry.PointCount != null, "geometry.PointCount != null");
            // Points are 1 based in DbGeometry
            var pointCount = geometry.PointCount;
            for (var pointIndex = 1; pointIndex <= pointCount; pointIndex++)
            {
                var point = geometry.PointAt(pointIndex);
                Debug.Assert(point.XCoordinate != null, "point.XCoordinate != null");
                Debug.Assert(point.YCoordinate != null, "point.YCoordinate != null");
                points.Add(new Point(point.XCoordinate.Value, point.YCoordinate.Value));
            }
            rec.Fields = new ShapefileRecordFields {
                { "Name", nameFunc(item) }
            };
            rec.Points = new List <List <Point> > {
                points
            };
            converter.Add(rec);
        }
        return(converter);
    }
Example #3
0
 /// <summary>
 /// Checks if <see cref="ShapefileRecord"/> contains a key in its field keys loaded from database (.dbf) file
 /// </summary>
 public static bool ContainsKey(this ShapefileRecord record, string fieldKey)
 {
     foreach (ShapefileRecordFields field in record.Fields)
     {
         if (field.ContainsKey(fieldKey))
         {
             return(true);
         }
     }
     return(false);
 }
Example #4
0
 /// <summary>
 /// Gets value that corresponds to specified key in <see cref="ShapefileRecord"/>
 /// </summary>
 /// <remarks>
 /// <para>Warning: Throws InvalidCastException if type of field value is incompatible with provided type</para>
 /// <code>Usage: ShapefileRecord.GetValue<DATA_TYPE>("DATA_COLUMN");</code>
 /// </remarks>
 public static T GetValue <T>(this ShapefileRecord record, string fieldKey)
 {
     return(record.Fields.GetValue <T>(fieldKey));
 }