Skip to content

Commit 1c3289e

Browse files
committed
applied patch NetTopologySuite#181
Issue: 181 git-svn-id: http://nettopologysuite.googlecode.com/svn/trunk@1224 53ca42c3-9f19-0410-8ccb-b990a9bb5db6
1 parent 08e3c0b commit 1c3289e

22 files changed

+880
-326
lines changed

NetTopologySuite.IO.ShapeFile.Extended/NetTopologySuite.IO.ShapeFile.Extended.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@
1616
<DebugSymbols>true</DebugSymbols>
1717
<DebugType>full</DebugType>
1818
<Optimize>false</Optimize>
19-
<OutputPath>bin\Debug\</OutputPath>
19+
<OutputPath>..\Debug\v4.0\AnyCPU\</OutputPath>
2020
<DefineConstants>DEBUG;TRACE</DefineConstants>
2121
<ErrorReport>prompt</ErrorReport>
2222
<WarningLevel>4</WarningLevel>
2323
</PropertyGroup>
2424
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2525
<DebugType>pdbonly</DebugType>
2626
<Optimize>true</Optimize>
27-
<OutputPath>bin\Release\</OutputPath>
27+
<OutputPath>..\Release\v4.0\AnyCPU\</OutputPath>
2828
<DefineConstants>TRACE</DefineConstants>
2929
<ErrorReport>prompt</ErrorReport>
3030
<WarningLevel>4</WarningLevel>
31+
<DocumentationFile>..\Release\v4.0\AnyCPU\NetTopologySuite.IO.ShapeFile.Extended.XML</DocumentationFile>
3132
</PropertyGroup>
3233
<ItemGroup>
3334
<Reference Include="System" />

NetTopologySuite.IO.ShapeFile.Extended/ShapeDataReader.cs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77
using GeoAPI.Geometries;
8-
using NetTopologySuite.Features;
98
using NetTopologySuite.Geometries;
109
using NetTopologySuite.Index;
1110
using NetTopologySuite.Index.Strtree;

NetTopologySuite.IO/NetTopologySuite.IO.GeoTools/Dbase/DbaseFileHeader.cs

+154-144
Large diffs are not rendered by default.

NetTopologySuite.IO/NetTopologySuite.IO.GeoTools/Handlers/MultiLineHandler.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public MultiLineHandler(ShapeGeometryType type) : base(type)
2323
/// </summary>
2424
/// <param name="file">The stream to read.</param>
2525
/// <param name="totalRecordLength">Total length of the record we are about to read</param>
26-
/// <param name="geometryFactory">The geometry factory to use when making the object.</param>
26+
/// <param name="factory">The geometry factory to use when making the object.</param>
2727
/// <returns>The Geometry object that represents the shape file record.</returns>
28-
public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory geometryFactory)
28+
public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory)
2929
{
3030
int totalRead = 0;
3131
var type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead);
3232
if (type == ShapeGeometryType.NullShape)
33-
return geometryFactory.CreateMultiLineString(null);
33+
return factory.CreateMultiLineString(null);
3434

3535
if (type != ShapeType)
3636
throw new ShapefileException(string.Format("Encountered a '{0}' instead of a '{1}'", type, ShapeType));
@@ -52,7 +52,7 @@ public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength
5252

5353
var lines = new List<ILineString>(numParts);
5454
var buffer = new CoordinateBuffer(numPoints, NoDataBorderValue, true);
55-
var pm = geometryFactory.PrecisionModel;
55+
var pm = factory.PrecisionModel;
5656

5757
for (var part = 0; part < numParts; part++)
5858
{
@@ -77,7 +77,7 @@ public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength
7777
// Geometries via ICoordinateSequence further down.
7878
GetZMValues(file, totalRecordLength, ref totalRead, buffer);
7979

80-
var sequences = new List<ICoordinateSequence>(buffer.ToSequences(geometryFactory.CoordinateSequenceFactory));
80+
var sequences = new List<ICoordinateSequence>(buffer.ToSequences(factory.CoordinateSequenceFactory));
8181

8282
for (var s = 0; s < sequences.Count; s++)
8383
{
@@ -94,10 +94,10 @@ public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength
9494
case GeometryInstantiationErrorHandlingOption.ThrowException:
9595
break;
9696
case GeometryInstantiationErrorHandlingOption.Empty:
97-
sequences[s] = geometryFactory.CoordinateSequenceFactory.Create(0, points.Ordinates);
97+
sequences[s] = factory.CoordinateSequenceFactory.Create(0, points.Ordinates);
9898
break;
9999
case GeometryInstantiationErrorHandlingOption.TryFix:
100-
sequences[s] = AddCoordinateToSequence(points, geometryFactory.CoordinateSequenceFactory,
100+
sequences[s] = AddCoordinateToSequence(points, factory.CoordinateSequenceFactory,
101101
points.GetOrdinate(0, Ordinate.X), points.GetOrdinate(0, Ordinate.Y),
102102
points.GetOrdinate(0, Ordinate.Z), points.GetOrdinate(0, Ordinate.M));
103103
break;
@@ -110,13 +110,13 @@ public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength
110110
if (createLineString)
111111
{
112112
// Grabs m values if we have them
113-
var line = geometryFactory.CreateLineString(points);
113+
var line = factory.CreateLineString(points);
114114
lines.Add(line);
115115
}
116116
}
117117

118118
geom = (lines.Count != 1)
119-
? (IGeometry)geometryFactory.CreateMultiLineString(lines.ToArray())
119+
? (IGeometry)factory.CreateMultiLineString(lines.ToArray())
120120
: lines[0];
121121
return geom;
122122
}
@@ -126,15 +126,15 @@ public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength
126126
/// </summary>
127127
/// <param name="geometry">The geometry object to write.</param>
128128
/// <param name="writer">The stream to write to.</param>
129-
/// <param name="geometryFactory">The geometry factory to use.</param>
130-
public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory geometryFactory)
129+
/// <param name="factory">The geometry factory to use.</param>
130+
public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory factory)
131131
{
132132
// Force to use a MultiGeometry
133133
IMultiLineString multi;
134134
if (geometry is IGeometryCollection)
135135
multi = (IMultiLineString)geometry;
136136
else
137-
multi = geometryFactory.CreateMultiLineString(new[] { (ILineString)geometry });
137+
multi = factory.CreateMultiLineString(new[] { (ILineString)geometry });
138138

139139
writer.Write((int)ShapeType);
140140

NetTopologySuite.IO/NetTopologySuite.IO.GeoTools/Handlers/MultiPointHandler.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ public MultiPointHandler(ShapeGeometryType type) : base(type)
2525
/// </summary>
2626
/// <param name="file">The stream to read.</param>
2727
/// <param name="totalRecordLength">Total length of the record we are about to read</param>
28-
/// <param name="geometryFactory">The geometry factory to use when making the object.</param>
28+
/// <param name="factory">The geometry factory to use when making the object.</param>
2929
/// <returns>The Geometry object that represents the shape file record.</returns>
30-
public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory geometryFactory)
30+
public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory)
3131
{
3232
int totalRead = 0;
3333
int shapeTypeNum = ReadInt32(file, totalRecordLength, ref totalRead);
3434

3535
var type = (ShapeGeometryType) EnumUtility.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString());
3636
if (type == ShapeGeometryType.NullShape)
37-
return geometryFactory.CreateMultiPoint(new IPoint[] { });
37+
return factory.CreateMultiPoint(new IPoint[] { });
3838

3939
if (type != ShapeType)
4040
throw new ShapefileException(string.Format("Encountered a '{0}' instead of a '{1}'", type, ShapeType));
@@ -52,7 +52,7 @@ public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength
5252
var numPoints = ReadInt32(file, totalRecordLength, ref totalRead);
5353
var buffer = new CoordinateBuffer(numPoints, NoDataBorderValue, true);
5454
var points = new IPoint[numPoints];
55-
var pm = geometryFactory.PrecisionModel;
55+
var pm = factory.PrecisionModel;
5656

5757
for (var i = 0; i < numPoints; i++)
5858
{
@@ -65,11 +65,11 @@ public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength
6565
// Trond Benum: We have now read all the points, let's read optional Z and M values
6666
GetZMValues(file, totalRecordLength, ref totalRead, buffer);
6767

68-
var sequences = buffer.ToSequences(geometryFactory.CoordinateSequenceFactory);
68+
var sequences = buffer.ToSequences(factory.CoordinateSequenceFactory);
6969
for (var i = 0; i < numPoints; i++)
70-
points[i] = geometryFactory.CreatePoint(sequences[i]);
70+
points[i] = factory.CreatePoint(sequences[i]);
7171

72-
geom = geometryFactory.CreateMultiPoint(points);
72+
geom = factory.CreateMultiPoint(points);
7373

7474
return geom;
7575
}
@@ -79,8 +79,8 @@ public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength
7979
/// </summary>
8080
/// <param name="geometry">The geometry to write.</param>
8181
/// <param name="writer">The writer to use.</param>
82-
/// <param name="geometryFactory">The geometry factory to use.</param>
83-
public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory geometryFactory)
82+
/// <param name="factory">The geometry factory to use.</param>
83+
public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory factory)
8484
{
8585
var mpoint = geometry as IMultiPoint;
8686
if (mpoint == null)
@@ -91,7 +91,7 @@ public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFac
9191
// Trace.WriteLine("Invalid multipoint being written.");
9292

9393
writer.Write((int)ShapeType);
94-
WriteEnvelope(writer, geometryFactory.PrecisionModel, geometry.EnvelopeInternal);
94+
WriteEnvelope(writer, factory.PrecisionModel, geometry.EnvelopeInternal);
9595

9696
var numPoints = mpoint.NumPoints;
9797
writer.Write(numPoints);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using GeoAPI.Geometries;
4+
5+
namespace NetTopologySuite.IO.Handlers
6+
{
7+
public class NullShapeHandler : ShapeHandler
8+
{
9+
public NullShapeHandler()
10+
: base(ShapeGeometryType.NullShape)
11+
{
12+
}
13+
14+
public override IGeometry Read(BigEndianBinaryReader file,
15+
int totalRecordLength, IGeometryFactory factory)
16+
{
17+
return null;
18+
}
19+
20+
public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory factory)
21+
{ }
22+
23+
public override int ComputeRequiredLengthInWords(IGeometry geometry)
24+
{
25+
return -1;
26+
}
27+
28+
public override IEnumerable<MBRInfo> ReadMBRs(BigEndianBinaryReader reader)
29+
{
30+
reader.Close();
31+
return new MBRInfo[0];
32+
}
33+
}
34+
}

NetTopologySuite.IO/NetTopologySuite.IO.GeoTools/Handlers/PointHandler.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ public PointHandler(ShapeGeometryType type)
2424
/// </summary>
2525
/// <param name="file">The stream to read.</param>
2626
/// <param name="totalRecordLength">Total length of the record we are about to read</param>
27-
/// <param name="geometryFactory">The geometry factory to use when making the object.</param>
27+
/// <param name="factory">The geometry factory to use when making the object.</param>
2828
/// <returns>The Geometry object that represents the shape file record.</returns>
29-
public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory geometryFactory)
29+
public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory factory)
3030
{
3131
int totalRead = 0;
3232
ShapeGeometryType type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead);
3333
//type = (ShapeGeometryType) EnumUtility.Parse(typeof (ShapeGeometryType), shapeTypeNum.ToString());
3434
if (type == ShapeGeometryType.NullShape)
35-
return geometryFactory.CreatePoint((Coordinate)null);
35+
return factory.CreatePoint((Coordinate)null);
3636

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

4040
CoordinateBuffer buffer = new CoordinateBuffer(1, NoDataBorderValue, true);
41-
IPrecisionModel precisionModel = geometryFactory.PrecisionModel;
41+
IPrecisionModel precisionModel = factory.PrecisionModel;
4242

4343
double x = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
4444
double y = precisionModel.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead));
@@ -54,16 +54,16 @@ public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength
5454
m = ReadDouble(file, totalRecordLength, ref totalRead);
5555

5656
buffer.AddCoordinate(x, y, z, m);
57-
return geometryFactory.CreatePoint(buffer.ToSequence(geometryFactory.CoordinateSequenceFactory));
57+
return factory.CreatePoint(buffer.ToSequence(factory.CoordinateSequenceFactory));
5858
}
5959

6060
/// <summary>
6161
/// Writes to the given stream the equilivent shape file record given a Geometry object.
6262
/// </summary>
6363
/// <param name="geometry">The geometry object to write.</param>
6464
/// <param name="writer">The stream to write to.</param>
65-
/// <param name="geometryFactory">The geometry factory to use.</param>
66-
public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory geometryFactory)
65+
/// <param name="factory">The geometry factory to use.</param>
66+
public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory factory)
6767
{
6868
writer.Write((int)ShapeType);
6969

NetTopologySuite.IO/NetTopologySuite.IO.GeoTools/Handlers/PointMBRIterator.cs

+8-63
Original file line numberDiff line numberDiff line change
@@ -6,75 +6,20 @@
66

77
namespace NetTopologySuite.IO.Handlers
88
{
9-
internal class PointMBRIterator : IEnumerator<MBRInfo>
9+
internal class PointMBRIterator : ShapeMBREnumeratorBase
1010
{
11-
private readonly BigEndianBinaryReader m_Reader;
12-
1311
public PointMBRIterator(BigEndianBinaryReader reader)
14-
{
15-
m_Reader = reader;
16-
Reset();
17-
}
12+
: base(reader)
13+
{ }
1814

19-
~PointMBRIterator()
15+
protected override Envelope ReadCurrentEnvelope(out int numOfBytesRead)
2016
{
21-
m_Reader.Close();
22-
}
17+
double x = Reader.ReadDouble();
18+
double y = Reader.ReadDouble();
2319

24-
public MBRInfo Current
25-
{
26-
get;
27-
set;
28-
}
20+
numOfBytesRead = 16;
2921

30-
public void Dispose()
31-
{
32-
m_Reader.Close();
33-
GC.SuppressFinalize(this);
34-
}
35-
36-
object IEnumerator.Current
37-
{
38-
get { return ((IEnumerator<Envelope>)this).Current; }
39-
}
40-
41-
public bool MoveNext()
42-
{
43-
if (m_Reader.BaseStream.Position >= m_Reader.BaseStream.Length)
44-
{
45-
return false;
46-
}
47-
48-
// Save location of shape metadata.
49-
long currShapeOffset = m_Reader.BaseStream.Position;
50-
51-
// Read shape index - substract 1 for a 0-based index.
52-
int currShapeIndex = m_Reader.ReadInt32BE() - 1;
53-
54-
int currPointLengthInWords = m_Reader.ReadInt32BE();
55-
56-
// Skip shape type.
57-
m_Reader.BaseStream.Seek(4, SeekOrigin.Current);
58-
59-
double x = m_Reader.ReadDouble();
60-
double y = m_Reader.ReadDouble();
61-
62-
// Calculate whether or not there is any data to skip, take the total shape size and substract already read data sizes.
63-
int numOfBytesToSkip = (currPointLengthInWords * 2) - (8 + 8 + 4);
64-
65-
if (numOfBytesToSkip != 0)
66-
{
67-
m_Reader.BaseStream.Seek(numOfBytesToSkip, SeekOrigin.Current);
68-
}
69-
70-
Current = new MBRInfo(new Envelope(new Coordinate(x, y)), currShapeOffset, currShapeIndex);
71-
72-
return true;
73-
}
74-
75-
public void Reset()
76-
{
77-
m_Reader.BaseStream.Seek(100, SeekOrigin.Begin);
22+
return new Envelope(new Coordinate(x, y));
7823
}
7924
}
8025
}

0 commit comments

Comments
 (0)