翻譯|使用教程|編輯:李顯亮|2021-05-07 10:05:28.807|閱讀 455 次
概述:我們可以將地圖渲染為不同的圖像格式,例如PNG,SVG,JPG等。在本文中講使用C#將渲染映射到SVG,JPG或PNG圖像。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
KML是Keyhole標記語言的縮寫,它是XML表示法的擴展。它是GIS文件格式,用于顯示地理信息。可以以編程方式創建KML文件,也可以使用C#語言從其中讀取信息。
讓我們探索以下與KML文件格式有關的部分:
Aspose.GIS for .NET API可讓您使用不同的地理和地理空間文件格式。您可以根據需要將地圖從受支持的文件格式渲染為SVG,PNG和其他文件格式。
>>你可以點擊這里下載Aspose.GIS最新版測試體驗。
可以按照以下步驟將地圖從shapefile渲染到SVG文件:
下面的代碼詳細說明了如何使用C#以編程方式將地圖從Shapefile渲染到SVG。
// Create new instance of Map class.
using (var map = new Rendering.Map(800, 400))
{
// Create vector map layer and add it to map.
map.Add(VectorLayer.Open("land.shp", Drivers.Shapefile));
// Render the map into a file.
map.Render("land_out.svg", Renderers.Svg);
}
可以將地圖文件從shapefile渲染為光柵圖像格式,如PNG,JPG,BMP等。以下是將地圖文件從shapefile渲染為PNG圖像的步驟:
以下代碼顯示了使用C#以編程方式將地圖從Shapefile渲染到PNG圖像的過程:
// Initialize Map class object with dimensions.
using (var map = new Rendering.Map(800, 400))
{
// Create and add vector map layer.
map.Add(VectorLayer.Open("land.shp", Drivers.Shapefile));
// Render the map to a PNG image.
map.Render("land_out.png", Renderers.Png);
}
可以使用高級功能樣式自定義地圖的外觀。請按照以下步驟進行自定義地圖渲染:
以下代碼說明了如何使用C#使用高級樣式進行自定義地圖渲染:
// Initialize Map class object.
using (var map = new Rendering.Map(800, 476))
{
// Initilize SimpleFill for simple polygon symbolizer.
var baseMapSymbolizer = new Rendering.Symbolizers.SimpleFill { FillColor = Color.Salmon, StrokeWidth = 0.75 };
// Open the layer from input shapefile for reading.
map.Add(VectorLayer.Open("basemap.shp", Drivers.Shapefile), baseMapSymbolizer);
// Initialize a new instance of SimpleMarker class.
var citiesSymbolizer = new Rendering.Symbolizers.SimpleMarker() { FillColor = Color.LightBlue };
citiesSymbolizer.FeatureBasedConfiguration = (feature, symbolizer) =>
{
var population = feature.GetValue("population");
symbolizer.Size = 10 * population / 1000;
if (population < 2500) { symbolizer.FillColor = Color.GreenYellow; } }; // Add a VectorMapLayer to the map. map.Add(VectorLayer.Open("points.geojson", Drivers.GeoJson), citiesSymbolizer); // Render map into a file. map.Render("cities_out.svg", Renderers.Svg); }
可以按照以下步驟將地圖從GeoTIFF渲染到SVG文件:
以下代碼段演示了如何使用C#以編程方式將地圖從GeoTIFF格式呈現為SVG:
// Initialize Map class object.
using (var map = new Rendering.Map(500, 500))
{
// Open the layer for reading using driver for the GeoTIFF or TIFF format.
var layer = GeoTiff.OpenLayer("raster_float32.tif");
// Conversion to colors is detected automatically.
// The maximum and minimum values are calculated and linear interpolation is used.
map.Add(layer);
// Render map into a file.
map.Render("raster_float32_out.svg", Renderers.Svg);
}
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn