地図を画像 SVG、PNG、JPG にレンダリングする GIS C# ライブラリ
地図のレンダリング概要
Aspose.GIS for .NET C# API を使用すると、Shapefile、FileGDB、GeoJSON、KML またはその他の サポートされているファイル形式 から地図を SVG、PNG、JPEG、または BMP にレンダリングできます。
以下は、デフォルト設定を使用して Shapefile から SVG に地図をレンダリングする方法を示す C# コードです。
| // For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
| using (var map = new Map(800, 400)) | |
| { | |
| map.Add(VectorLayer.Open(dataDir + "land.shp", Drivers.Shapefile)); | |
| map.Render(dataDir + "land_out.svg", Renderers.Svg); | |
| } |
ここに結果を示します。

コードを詳しく見てみましょう。
まず、Map オブジェクトをインスタンス化します。これは、さまざまなソースからのレイヤーのコレクションを表し、レンダリングできます。 Map には、表示するサイズがあります。ここでは、地図の幅を 800 ピクセル、高さを 400 ピクセルに設定します。
Map は using ステートメントで囲まれていることに注意してください。これは、Map が追加されたすべてのリソースを追跡し、レンダリングが完了して Map オブジェクトが破棄されるときにそれらを破棄する必要があるためです。
次に、ファイルからレイヤーを地図に追加します。各レイヤーは、追加された順序で前のレイヤーの上にレンダリングされます。ベクターレイヤーを開く方法の詳細については、こちらを参照してください。
最後に、Map.Render を呼び出して地図をファイルにレンダリングします。結果ファイルを保存するパスと使用するレンダラーを指定します。クラス Renderers には、Aspose.GIS に含まれるすべてのレンダラーへの参照が含まれています。たとえば、上記の例で Renderers.Png ではなく Renderers.Svg を指定して地図を PNG ファイルにレンダリングできます。
高度なスタイル設定
Aspose.GIS API を使用すると、レンダリングとフィーチャースタイルをカスタマイズして、必要な外観を実現できます。

| // For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
| using (var map = new Map(800, 476)) | |
| { | |
| var baseMapSymbolizer = new SimpleFill { FillColor = Color.Salmon, StrokeWidth = 0.75 }; | |
| map.Add(VectorLayer.Open(dataDir + "basemap.shp", Drivers.Shapefile), baseMapSymbolizer); | |
| var citiesSymbolizer = new SimpleMarker() { FillColor = Color.LightBlue }; | |
| citiesSymbolizer.FeatureBasedConfiguration = (feature, symbolizer) => | |
| { | |
| var population = feature.GetValue<int>("population"); | |
| symbolizer.Size = 10 * population / 1000; | |
| if (population < 2500) | |
| { | |
| symbolizer.FillColor = Color.GreenYellow; | |
| } | |
| }; | |
| map.Add(VectorLayer.Open(dataDir + "points.geojson", Drivers.GeoJson), citiesSymbolizer); | |
| map.Render(dataDir + "cities_out.svg", Renderers.Svg); | |
| } |
地図にラスターを描画
Aspose.GIS for .NET を使用すると、ラスター形式から地図をレンダリングできます。
デフォルト設定でレンダリング
以下は、デフォルト設定を使用して GeoTIFF から SVG に地図をレンダリングする方法です。
| // For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
| string filesPath = RunExamples.GetDataDir(); | |
| using (var map = new Map(500, 500)) | |
| { | |
| var layer = Drivers.GeoTiff.OpenLayer(Path.Combine(filesPath, "raster_float32.tif")); | |
| // Conversion to colors is detected automatically. | |
| // The maximum and minimum values are calculated and linear interpolation is used. | |
| map.Add(layer); | |
| map.Render(filesPath + "raster_float32_out.svg", Renderers.Svg); | |
| } |

歪んだラスターをレンダリング
Aspose.GIS を使用すると、歪んだラスターセルを持つラスターをレンダリングできます。
| // For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
| string filesPath = RunExamples.GetDataDir(); | |
| using (var map = new Map(500, 500)) | |
| { | |
| // use background color | |
| map.BackgroundColor = Color.Azure; | |
| var layer = Drivers.GeoTiff.OpenLayer(Path.Combine(filesPath, "raster_skew.tif")); | |
| // Conversion to colors is detected automatically. | |
| // The maximum and minimum values are calculated and linear interpolation is used. | |
| map.Add(layer); | |
| map.Render(filesPath + "raster_skew_out.svg", Renderers.Svg); | |
| } |

極座標空間参照でレンダリング
Aspose.GIS を使用すると、地図のレンダリングプロセスで極座標空間参照を使用できます。
| // For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET | |
| string filesPath = RunExamples.GetDataDir(); | |
| // make own multi colorizer it works faster than auto-detection | |
| var colorizer = new MultiBandColor() | |
| { | |
| RedBand = new BandColor() { BandIndex = 0, Min = 0, Max = 255 }, | |
| GreenBand = new BandColor() { BandIndex = 1, Min = 0, Max = 255 }, | |
| BlueBand = new BandColor() { BandIndex = 2, Min = 0, Max = 255 } | |
| }; | |
| using (var map = new Map(500, 500)) | |
| { | |
| // setup the polar extent and coordinate system (gnomonic spatial reference) | |
| map.SpatialReferenceSystem = SpatialReferenceSystem.CreateFromEpsg(102034); | |
| map.Extent = new Extent(-180, 60, 180, 90) { SpatialReferenceSystem = SpatialReferenceSystem.Wgs84 }; | |
| map.BackgroundColor = Color.Azure; | |
| // open geo-tiff | |
| var layer = Drivers.GeoTiff.OpenLayer(Path.Combine(filesPath, "raster_countries.tif")); | |
| // draw | |
| map.Add(layer, colorizer); | |
| map.Render(filesPath + "raster_countries_gnomonic_out.png", Renderers.Png); | |
| } |
