Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read a polygon with a hole from a ShapeFile #80

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NetTopologySuite.IO.ShapeFile.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
# Visual Studio Version 16
VisualStudioVersion = 16.0.31321.278
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B0923F22-AF00-46DA-B5CE-73F4D398DE37}"
ProjectSection(SolutionItems) = preProject
Expand Down
46 changes: 46 additions & 0 deletions PerfApp/Perf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using BenchmarkDotNet.Attributes;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
using System.Linq;

namespace PerfApp
{
public class Perf
{
private const int Count = 50000;
private const int Step = 10;

private static readonly GeometryFactory Fac = GeometryFactory.Default;

private readonly string fname;

public Perf()
{
var features = Utils.CreateFeatures(Fac, Count, Step).ToList();
fname = Utils.WriteFeatures(features);
}

private int InternalRead()
{
int i = 0;
var reader = Shapefile.CreateDataReader(fname, Fac);
while (reader.Read())
i++;
return i;
}

[Benchmark]
public int ReadWithFlagDisabled()
{
Shapefile.ExperimentalPolygonBuilderEnabled = false;
return InternalRead();
}

[Benchmark]
public int ReadWithFlagEnabled()
{
Shapefile.ExperimentalPolygonBuilderEnabled = true;
return InternalRead();
}
}
}
36 changes: 36 additions & 0 deletions PerfApp/PerfApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="nts_develop\**" />
<Compile Remove="nts_features\**" />
<Compile Remove="nts_patch_595\**" />
<EmbeddedResource Remove="nts_develop\**" />
<EmbeddedResource Remove="nts_features\**" />
<EmbeddedResource Remove="nts_patch_595\**" />
<None Remove="nts_develop\**" />
<None Remove="nts_features\**" />
<None Remove="nts_patch_595\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
</ItemGroup>

<ItemGroup>
<Reference Include="NetTopologySuite">
<HintPath>nts_patch_595\NetTopologySuite.dll</HintPath>
</Reference>
<Reference Include="NetTopologySuite.Features">
<HintPath>nts_features\NetTopologySuite.Features.dll</HintPath>
</Reference>
<Reference Include="NetTopologySuite.IO.ShapeFile">
<HintPath>nts_shapefile\NetTopologySuite.IO.ShapeFile.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions PerfApp/PerfApp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31321.278
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerfApp", "PerfApp.csproj", "{64DBD7B8-EE86-40F3-81BF-4D1E0049662F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{64DBD7B8-EE86-40F3-81BF-4D1E0049662F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64DBD7B8-EE86-40F3-81BF-4D1E0049662F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64DBD7B8-EE86-40F3-81BF-4D1E0049662F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64DBD7B8-EE86-40F3-81BF-4D1E0049662F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4FC81A8C-F367-4B21-9955-39FFAE513605}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions PerfApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BenchmarkDotNet.Running;

namespace PerfApp
{
class Program
{
static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<Perf>();
}
}
}
71 changes: 71 additions & 0 deletions PerfApp/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
using System.Collections.Generic;
using System.IO;

namespace PerfApp
{
internal static class Utils
{
internal static IEnumerable<IFeature> CreateFeatures(GeometryFactory fac, uint count, uint step)
{
var list = new List<Polygon>();
int counter = 0;
int indexer = 0;
for (uint i = 1; i < count * 10; i += step)
{
var shell = fac.CreateLinearRing(new Coordinate[]
{
new Coordinate(1 * i, 1 * i),
new Coordinate(9 * i, 1 * i),
new Coordinate(9 * i, 9* i),
new Coordinate(1 * i, 9* i),
new Coordinate(1 * i, 1* i),
});
var hole1 = fac.CreateLinearRing(new Coordinate[]
{
new Coordinate(2* i, 2* i),
new Coordinate(3* i, 3* i),
new Coordinate(4* i, 2* i),
new Coordinate(2* i, 2* i),
});
var hole2 = fac.CreateLinearRing(new Coordinate[]
{
new Coordinate(6* i, 6* i),
new Coordinate(8* i, 8* i),
new Coordinate(7* i, 6* i),
new Coordinate(6* i, 6* i),
});
var poly = fac.CreatePolygon(shell, new[] { hole1, hole2 });
list.Add(poly);
if (++counter >= 100)
{
var mpoly = fac.CreateMultiPolygon(list.ToArray());
var attrs = new AttributesTable { { "id", ++indexer } };
yield return new Feature(mpoly, attrs);

list.Clear();
counter = 0;
}
}
if (list.Count != 0)
{
var mpoly1 = fac.CreateMultiPolygon(list.ToArray());
var attrs1 = new AttributesTable { { "id", ++indexer } };
yield return new Feature(mpoly1, attrs1);
}
}

internal static string WriteFeatures(IList<IFeature> features)
{
string fname = Path.ChangeExtension(Path.GetTempFileName(), ".shp");
var header = ShapefileDataWriter.GetHeader(features[0], features.Count);
var writer = new ShapefileDataWriter(fname) { Header = header };
writer.Write(features);
return Path.Combine(
Path.GetDirectoryName(fname),
Path.GetFileNameWithoutExtension(fname));
}
}
}
152 changes: 152 additions & 0 deletions PerfApp/nts_develop/NetTopologySuite.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"runtimeTarget": {
"name": ".NETStandard,Version=v2.0/",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETStandard,Version=v2.0": {},
".NETStandard,Version=v2.0/": {
"NetTopologySuite/2.5.0-pre.190390493+local": {
"dependencies": {
"Microsoft.DotNet.ApiCompat": "6.0.0-beta.21159.11",
"Microsoft.SourceLink.GitHub": "1.1.1",
"NETStandard.Library": "2.0.3",
"System.Memory": "4.5.4"
},
"runtime": {
"NetTopologySuite.dll": {}
}
},
"Microsoft.Build.Tasks.Git/1.1.1": {},
"Microsoft.DotNet.ApiCompat/6.0.0-beta.21159.11": {},
"Microsoft.NETCore.Platforms/1.1.0": {},
"Microsoft.SourceLink.Common/1.1.1": {},
"Microsoft.SourceLink.GitHub/1.1.1": {
"dependencies": {
"Microsoft.Build.Tasks.Git": "1.1.1",
"Microsoft.SourceLink.Common": "1.1.1"
}
},
"NETStandard.Library/2.0.3": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.0"
}
},
"System.Buffers/4.5.1": {
"runtime": {
"lib/netstandard2.0/System.Buffers.dll": {
"assemblyVersion": "4.0.3.0",
"fileVersion": "4.6.28619.1"
}
}
},
"System.Memory/4.5.4": {
"dependencies": {
"System.Buffers": "4.5.1",
"System.Numerics.Vectors": "4.4.0",
"System.Runtime.CompilerServices.Unsafe": "4.5.3"
},
"runtime": {
"lib/netstandard2.0/System.Memory.dll": {
"assemblyVersion": "4.0.1.1",
"fileVersion": "4.6.28619.1"
}
}
},
"System.Numerics.Vectors/4.4.0": {
"runtime": {
"lib/netstandard2.0/System.Numerics.Vectors.dll": {
"assemblyVersion": "4.1.3.0",
"fileVersion": "4.6.25519.3"
}
}
},
"System.Runtime.CompilerServices.Unsafe/4.5.3": {
"runtime": {
"lib/netstandard2.0/System.Runtime.CompilerServices.Unsafe.dll": {
"assemblyVersion": "4.0.4.1",
"fileVersion": "4.6.28619.1"
}
}
}
}
},
"libraries": {
"NetTopologySuite/2.5.0-pre.190390493+local": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.Build.Tasks.Git/1.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-AT3HlgTjsqHnWpBHSNeR0KxbLZD7bztlZVj7I8vgeYG9SYqbeFGh0TM/KVtC6fg53nrWHl3VfZFvb5BiQFcY6Q==",
"path": "microsoft.build.tasks.git/1.1.1",
"hashPath": "microsoft.build.tasks.git.1.1.1.nupkg.sha512"
},
"Microsoft.DotNet.ApiCompat/6.0.0-beta.21159.11": {
"type": "package",
"serviceable": true,
"sha512": "sha512-SVX3OOq+Jx+DbPETmOjZO4OlHtrJBkAK7+O99crSJYFndveqTLiIIPMI6v5E2xOBEnWQQPwtiFxaVhEtuqHwtA==",
"path": "microsoft.dotnet.apicompat/6.0.0-beta.21159.11",
"hashPath": "microsoft.dotnet.apicompat.6.0.0-beta.21159.11.nupkg.sha512"
},
"Microsoft.NETCore.Platforms/1.1.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A==",
"path": "microsoft.netcore.platforms/1.1.0",
"hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
},
"Microsoft.SourceLink.Common/1.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-WMcGpWKrmJmzrNeuaEb23bEMnbtR/vLmvZtkAP5qWu7vQsY59GqfRJd65sFpBszbd2k/bQ8cs8eWawQKAabkVg==",
"path": "microsoft.sourcelink.common/1.1.1",
"hashPath": "microsoft.sourcelink.common.1.1.1.nupkg.sha512"
},
"Microsoft.SourceLink.GitHub/1.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-IaJGnOv/M7UQjRJks7B6p7pbPnOwisYGOIzqCz5ilGFTApZ3ktOR+6zJ12ZRPInulBmdAf1SrGdDG2MU8g6XTw==",
"path": "microsoft.sourcelink.github/1.1.1",
"hashPath": "microsoft.sourcelink.github.1.1.1.nupkg.sha512"
},
"NETStandard.Library/2.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
"path": "netstandard.library/2.0.3",
"hashPath": "netstandard.library.2.0.3.nupkg.sha512"
},
"System.Buffers/4.5.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg==",
"path": "system.buffers/4.5.1",
"hashPath": "system.buffers.4.5.1.nupkg.sha512"
},
"System.Memory/4.5.4": {
"type": "package",
"serviceable": true,
"sha512": "sha512-1MbJTHS1lZ4bS4FmsJjnuGJOu88ZzTT2rLvrhW7Ygic+pC0NWA+3hgAen0HRdsocuQXCkUTdFn9yHJJhsijDXw==",
"path": "system.memory/4.5.4",
"hashPath": "system.memory.4.5.4.nupkg.sha512"
},
"System.Numerics.Vectors/4.4.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-UiLzLW+Lw6HLed1Hcg+8jSRttrbuXv7DANVj0DkL9g6EnnzbL75EB7EWsw5uRbhxd/4YdG8li5XizGWepmG3PQ==",
"path": "system.numerics.vectors/4.4.0",
"hashPath": "system.numerics.vectors.4.4.0.nupkg.sha512"
},
"System.Runtime.CompilerServices.Unsafe/4.5.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-3TIsJhD1EiiT0w2CcDMN/iSSwnNnsrnbzeVHSKkaEgV85txMprmuO+Yq2AdSbeVGcg28pdNDTPK87tJhX7VFHw==",
"path": "system.runtime.compilerservices.unsafe/4.5.3",
"hashPath": "system.runtime.compilerservices.unsafe.4.5.3.nupkg.sha512"
}
}
}
Binary file added PerfApp/nts_develop/NetTopologySuite.dll
Binary file not shown.
Loading