How can I load direct Image Object in GeoTiffRasterLayer()?
Earlier I use server map path function to set image:
Dim MAPA_FOTO As GeoTiffRasterLayer
MAPA_FOTO = New GeoTiffRasterLayer(Server.MapPath("~\App_Data\1.tif"))
Dim proj4 As Proj4Projection = New Proj4Projection()
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(32723)
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()
proj4.Open()
MAPA_FOTO.ImageSource.Projection = proj4
MAPA_FOTO.UpperThreshold = Double.MaxValue
MAPA_FOTO.LowerThreshold = 0
MAPA_FOTO.DrawingQuality = DrawingQuality.HighSpeed
MAPA_FOTO.IsGrayscale = False
dynamicOverlay.Layers.Add(MAPA_FOTO)
But now I take Direct image from database in Img variable.
So now how can I use GeoTiffRasterLayer() to load direct image from Img variable?
Load image object using GeoTiffRasterLayer
should it need a world file to position the image on background map?
this might be your answer: wiki.thinkgeo.com/wiki/Source_Code_DesktopEditionSample_ImageStreamLoading_CS_100701.zip
Hi Vivek,
I think GuangMing is right, you need read the images from database and convert it to stream first, then render it.
Regards,
Don
Thanks for reply…
But that example is for windows form, and my project is in Web.
I can not get any idea to convert it into windows form to web.
can you please give me the sample in web form??
Hi Vivek,
Before a deeper investigation, may I a make confirmation with you? If the image type is tif? If yes, then following fake code should provide a basic idea for you.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
,
GdiPlusRasterLayer worldImageLayer = new GdiPlusRasterLayer(@"world.tif");
((GdiPlusRasterSource)(worldImageLayer.ImageSource)).StreamLoading += new EventHandler<StreamLoadingEventArgs>(MainForm_StreamLoading);
,
}
}
void MainForm_StreamLoading(object sender, StreamLoadingEventArgs e)
{
if (e.StreamType == "Image File")
{
Stream stream = yourImageFileInDataBase.ToStream();
e.AlternateStream = stream;
}
if (e.StreamType == "World File")
{
Stream stream =yourWorldFileInDataBase.ToStream();
e.AlternateStream = stream;
}
}
If you have any more question please feel free to let us know.
Best Regards
Summer
Thanks Summer.
Yes my image is in .tif format.
So Can you give me the idea that how can I fetch this images from sql server and display on Think Geo map using GeoTiffRasterLayer?
If possible please give me sample in MVC 3.
Regards,
Vivek
Hi Vivek,
Attached codes are for MVC3 pattern, would you please try it?
One thing that needs your attention is that because your tif file is stored in the database, so we used
fake code yourImageFileInDataBase.ToStream() to point out that you need to get your tif image from database and then convert it into stream type.
fake code yourWorldFileInDataBase.ToStream() to point out that you need to get your world file from database and then convert it into stream type.
If you have any more questions, please let me know.
Best Regards,
Summer
Post11560.txt (1.73 KB)
Thanks Summer,
I get an error in one line which is shown in the below fig:
Also in above fig. their is a code like:
Dim rasterLayer As New GdiPlusRasterLayer(“world.tif”)
Their is a “world.tif” but my image is in database, so what I write instead of that?
Hi Vivek,
Would you please have a try like the below codes:
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
Map1.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.StandardColors.White)
Map1.CurrentExtent = New RectangleShape(-80.5, 68.9, 80, -60.43)
Map1.MapUnit = GeographyUnit.DecimalDegree
Dim gdiPlusImageLayer As New GdiPlusRasterLayer(“World.tif”)
AddHandler gdiPlusImageLayer.StreamLoading, AddressOf gdiPlusImageLayer_StreamLoading
gdiPlusImageLayer.UpperThreshold = Double.MaxValue
gdiPlusImageLayer.LowerThreshold = 0
Map1.StaticOverlay.Layers.Add(gdiPlusImageLayer)
End If
End Sub
Private Sub gdiPlusImageLayer_StreamLoading(sender As Object, e As StreamLoadingEventArgs)
If e.StreamType = “Image File” Then
Dim stream As Stream = yourImageFileInDataBase.ToStream() 'New FileStream(“D:\TestData\World.tif”, FileMode.Open, FileAccess.Read)
e.AlternateStream = stream
End If
If e.StreamType = “World File” Then
Dim stream As Stream = yourworldFileInDataBase.ToStream() 'New FileStream(“D:\TestData\World.tfw”, FileMode.Open, FileAccess.Read)
e.AlternateStream = stream
End If
End Sub
Please notice both image source file “tif” and world file “tfw” are required in your database.
Let us know if there is any issue.
Thanks,
Johnny