gis - How to read geographical raster in c# -
i looking "clean" way load rasters c# code. raster mean (or @ least some) xyz file qgis or arcgis able load: .tif, .rrd ...
i using nettopologysuite
. library works shapefiles, makes me think there raster reader. have been trying focus research under nettopologysuite.io
namespace, contains quite few readers.
i have tagged post nettopologysuite
hoping c#-savvy knows bit more me particular library.
i used libtiff.net .tif, had no requirement other format. upperleft , bottomright properties used position image on world map. don't deal model transform case because it's complicated , - again - no requirement @ moment.
var imagestreamsource = new filestream(filename, filemode.open, fileaccess.read, fileshare.read); var decoder = new tiffbitmapdecoder(imagestreamsource, bitmapcreateoptions.preservepixelformat, bitmapcacheoption.default); var bitmapsource = decoder.frames[0]; // draw image image = bitmapsource.tobitmap(); using (var tiff = tiff.open(filename, "r")) { height = tiff.getfield(tifftag.imagelength)[0].toint(); width = tiff.getfield(tifftag.imagewidth)[0].toint(); // see http://www.remotesensing.org/geotiff/spec/geotiff2.6.html#2.6.1 var modelpixelscaletag = tiff.getfield(tifftag.geotiff_modelpixelscaletag); var modeltiepointtag = tiff.getfield(tifftag.geotiff_modeltiepointtag); //var modeltransformtag = tiff.getfield(tifftag.geotiff_modeltransformationtag); var modelpixelscale = modelpixelscaletag[1].getbytes(); var scalex = bitconverter.todouble(modelpixelscale, 0); var scaley = bitconverter.todouble(modelpixelscale, 8) * -1; if (modeltiepointtag != null) { var modeltransformation = modeltiepointtag[1].getbytes(); var originlon = bitconverter.todouble(modeltransformation, 24); var originlat = bitconverter.todouble(modeltransformation, 32); // origin center of pixel, offset var startlat = originlat + (scaley / 2.0); var startlon = originlon + (scalex / 2.0); upperleft = new position(startlat, startlon); bottomright = new position(startlat + scaley * height, startlon + scalex * width); } //else if (modeltransformtag != null) //{ // complicated //} else { throw new exception("couldn't understand tiff format"); } }
Comments
Post a Comment