지도 렌더링을 이미지 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.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); | |
} |