翻譯|使用教程|編輯:李顯亮|2021-05-07 10:05:28.807|閱讀 435 次
概述:我們可以將地圖渲染為不同的圖像格式,例如PNG,SVG,JPG等。在本文中講使用C#將渲染映射到SVG,JPG或PNG圖像。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
KML是Keyhole標(biāo)記語(yǔ)言的縮寫,它是XML表示法的擴(kuò)展。它是GIS文件格式,用于顯示地理信息。可以以編程方式創(chuàng)建KML文件,也可以使用C#語(yǔ)言從其中讀取信息。
讓我們探索以下與KML文件格式有關(guān)的部分:
Aspose.GIS for .NET API可讓您使用不同的地理和地理空間文件格式。您可以根據(jù)需要將地圖從受支持的文件格式渲染為SVG,PNG和其他文件格式。
>>你可以點(diǎn)擊這里下載Aspose.GIS最新版測(cè)試體驗(yàn)。
可以按照以下步驟將地圖從shapefile渲染到SVG文件:
下面的代碼詳細(xì)說(shuō)明了如何使用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圖像的過(guò)程:
// 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); }
可以使用高級(jí)功能樣式自定義地圖的外觀。請(qǐng)按照以下步驟進(jìn)行自定義地圖渲染:
以下代碼說(shuō)明了如何使用C#使用高級(jí)樣式進(jìn)行自定義地圖渲染:
// 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格式呈現(xiàn)為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的全部完整功能,可聯(lián)系在線客服獲取30天臨時(shí)授權(quán)體驗(yàn)。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn