Created
June 14, 2017 14:53
-
-
Save smourier/3d7739c0c719ee0c81fccbd2131fe62c to your computer and use it in GitHub Desktop.
SharpMap sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<configuration> | |
<startup> | |
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | |
</startup> | |
<runtime> | |
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | |
<dependentAssembly> | |
<assemblyIdentity name="GeoAPI" publicKeyToken="a1a0da7def465678" culture="neutral" /> | |
<bindingRedirect oldVersion="0.0.0.0-1.7.5.0" newVersion="1.7.5.0" /> | |
</dependentAssembly> | |
</assemblyBinding> | |
</runtime> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Drawing; | |
using System.Windows.Forms; | |
using GeoAPI.CoordinateSystems; | |
using GeoAPI.CoordinateSystems.Transformations; | |
using ProjNet.CoordinateSystems; | |
using ProjNet.CoordinateSystems.Transformations; | |
using SharpMap; | |
using SharpMap.Converters.WellKnownText; | |
using SharpMap.CoordinateSystems; | |
using SharpMap.Data.Providers; | |
using SharpMap.Layers; | |
namespace WindowsFormsApplication2 | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
DrawMap(); | |
} | |
private void DrawMap() | |
{ | |
Session.Instance.SetCoordinateSystemServices( | |
new CoordinateSystemServices( | |
new CoordinateSystemFactory(), | |
new CoordinateTransformationFactory(), | |
SpatialReference.GetAllReferenceSystems())); | |
var map = new Map(pictureBox1.Size); | |
map.BackColor = Color.White; | |
var file = new ShapeFile(@"D:\Downloads\FRA_adm\FRA_adm1.shp", true); | |
var layer = new VectorLayer("France", file); | |
layer.CoordinateTransformation = Wgs84ToGoogle; | |
map.Layers.Add(layer); | |
map.ZoomToExtents(); | |
pictureBox1.Image = map.GetMap(); | |
} | |
// Wgs84 to Google Mercator Coordinate Transformation | |
// this code comes from SharpMap\Examples\WinFormSamples\LayerTools.cs | |
private ICoordinateTransformation _wgs84ToGoogle; | |
public ICoordinateTransformation Wgs84ToGoogle | |
{ | |
get | |
{ | |
if (_wgs84ToGoogle == null) | |
{ | |
var csFac = new CoordinateSystemFactory(); | |
var ctFac = new CoordinateTransformationFactory(); | |
var wgs84 = csFac.CreateGeographicCoordinateSystem( | |
"WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, | |
new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East)); | |
var parameters = new List<ProjectionParameter>(); | |
parameters.Add(new ProjectionParameter("semi_major", 6378137.0)); | |
parameters.Add(new ProjectionParameter("semi_minor", 6378137.0)); | |
parameters.Add(new ProjectionParameter("latitude_of_origin", 0.0)); | |
parameters.Add(new ProjectionParameter("central_meridian", 0.0)); | |
parameters.Add(new ProjectionParameter("scale_factor", 1.0)); | |
parameters.Add(new ProjectionParameter("false_easting", 0.0)); | |
parameters.Add(new ProjectionParameter("false_northing", 0.0)); | |
var projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters); | |
var epsg900913 = csFac.CreateProjectedCoordinateSystem( | |
"Google Mercator", wgs84, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), | |
new AxisInfo("North", AxisOrientationEnum.North)); | |
((CoordinateSystem)epsg900913).DefaultEnvelope = new[] { -20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789 }; | |
_wgs84ToGoogle = ctFac.CreateFromCoordinateSystems(wgs84, epsg900913); | |
} | |
return _wgs84ToGoogle; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<packages> | |
<package id="GeoAPI" version="1.7.5-pre2" targetFramework="net452" /> | |
<package id="ProjNET4GeoAPI" version="1.3.2-pre1" targetFramework="net452" /> | |
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | |
<PropertyGroup> | |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |
<ProjectGuid>{34A45E09-4AC1-4CA8-852A-BD86A24D96D7}</ProjectGuid> | |
<OutputType>WinExe</OutputType> | |
<AppDesignerFolder>Properties</AppDesignerFolder> | |
<RootNamespace>WindowsFormsApplication2</RootNamespace> | |
<AssemblyName>WindowsFormsApplication2</AssemblyName> | |
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | |
<FileAlignment>512</FileAlignment> | |
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
<PlatformTarget>AnyCPU</PlatformTarget> | |
<DebugSymbols>true</DebugSymbols> | |
<DebugType>full</DebugType> | |
<Optimize>false</Optimize> | |
<OutputPath>bin\Debug\</OutputPath> | |
<DefineConstants>DEBUG;TRACE</DefineConstants> | |
<ErrorReport>prompt</ErrorReport> | |
<WarningLevel>4</WarningLevel> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |
<PlatformTarget>AnyCPU</PlatformTarget> | |
<DebugType>pdbonly</DebugType> | |
<Optimize>true</Optimize> | |
<OutputPath>bin\Release\</OutputPath> | |
<DefineConstants>TRACE</DefineConstants> | |
<ErrorReport>prompt</ErrorReport> | |
<WarningLevel>4</WarningLevel> | |
</PropertyGroup> | |
<ItemGroup> | |
<Reference Include="GeoAPI, Version=1.7.5.0, Culture=neutral, PublicKeyToken=a1a0da7def465678, processorArchitecture=MSIL"> | |
<HintPath>..\packages\GeoAPI.1.7.5-pre2\lib\net45\GeoAPI.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="ProjNet, Version=1.3.2.0, Culture=neutral, PublicKeyToken=a1f5bdcd9c6f5740, processorArchitecture=MSIL"> | |
<HintPath>..\packages\ProjNET4GeoAPI.1.3.2-pre1\lib\net45-client\ProjNet.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="SharpMap, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL"> | |
<SpecificVersion>False</SpecificVersion> | |
<HintPath>D:\github\SharpMap\SharpMap\bin\Debug\SharpMap.dll</HintPath> | |
</Reference> | |
<Reference Include="System" /> | |
<Reference Include="System.Core" /> | |
<Reference Include="Microsoft.CSharp" /> | |
<Reference Include="System.Drawing" /> | |
<Reference Include="System.Windows.Forms" /> | |
<Reference Include="System.Xml" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Compile Include="Form1.cs"> | |
<SubType>Form</SubType> | |
</Compile> | |
<Compile Include="Form1.Designer.cs"> | |
<DependentUpon>Form1.cs</DependentUpon> | |
</Compile> | |
<Compile Include="Program.cs" /> | |
<Compile Include="Properties\AssemblyInfo.cs" /> | |
<EmbeddedResource Include="Form1.resx"> | |
<DependentUpon>Form1.cs</DependentUpon> | |
</EmbeddedResource> | |
<None Include="packages.config" /> | |
</ItemGroup> | |
<ItemGroup> | |
<None Include="App.config" /> | |
</ItemGroup> | |
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |
Other similar extension points exist, see Microsoft.Common.targets. | |
<Target Name="BeforeBuild"> | |
</Target> | |
<Target Name="AfterBuild"> | |
</Target> | |
--> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment