How add a jpg or png file on the map?

Topics: Algorithms, CompactFramework, Data Access, Español, General Topics, Italiano, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, Web Controls, WinForms Controls
Apr 26, 2011 at 10:18 AM

Hi everyone, i'm doing some thing about weather used sharpmap, now i have a question

i have the vector data for example: village,road ,river,town and country, and i add them to the map successfully. then i have another data, it's the satellite cloud picture(*.jpg), and i received them from the satellite every hours

now my problem is how can i add the image to the map, it just an image have no spatialreference ,or how can i set a spatialreference to the image

beg your reply, thank you!

Coordinator
Apr 26, 2011 at 1:54 PM

Hello TomSweet,

I suppose you know the coordinates of the corners of your satellite image. Since that will probably not change, all you need to do (once) is setup some world file. After that you can use GdalRasterLayer to use that image along with your vector data.

You might even get away with gdal_translate and -a_ullr parameter.

Hth FObermaier

Apr 26, 2011 at 2:09 PM
FObermaier wrote:

Hello TomSweet,

I suppose you know the coordinates of the corners of your satellite image. Since that will probably not change, all you need to do (once) is setup some world file. After that you can use GdalRasterLayer to use that image along with your vector data.

You might even get away with gdal_translate and -a_ullr parameter.

Hth FObermaier

Dear FObermaier :

would you mind give me some example or show me some code, i'm a new of sharpmap, and i'm a chinese, my english is a too bad,so some articles is too difficult for me , i can't understand at all. if you can give me

some code or example , i will be greatly appreciated!

Coordinator
Apr 26, 2011 at 4:03 PM

Please supply image metrics (width and height in pixels) and coordinates of the corners.

Apr 26, 2011 at 4:30 PM
FObermaier wrote:

Please supply image metrics (width and height in pixels) and coordinates of the corners.

Thank you very much

The image width=1024px,height=768px,and the dpi =96, the corner of the left top corresponding points on the map is 105.198526,31.321752, i only have this one point

thank you again!

Coordinator
Apr 26, 2011 at 5:57 PM

I suppose that is lat/long in WGS84? I need -at least a good guess- of lower right as well.

Apr 27, 2011 at 2:32 PM
FObermaier wrote:

I suppose that is lat/long in WGS84? I need -at least a good guess- of lower right as well.

Sorry for reply later, yes ,the at/long is in WGS84 and the coord of 105.198526,31.321752 corresponding to the image  is the "top left" of the image

Coordinator
Apr 27, 2011 at 3:45 PM

I need lower right as well

Apr 27, 2011 at 3:49 PM
FObermaier wrote:

I need lower right as well

the lower right is 109.014524,28.142369

Coordinator
Apr 28, 2011 at 8:12 AM

Hello TomSweet,

running

gdal_translate -of "JPEG" -a_ullr 105.198526 31.321752 109.014524 28.142369 -a_srs EPSG:4326 input.jpg output.jpg

in FWTools console, you'll get an output.aux.xml file that looks somewhat like this:

<PAMDataset>
  <GeoTransform> 1.0519852600000000e+002, 9.7656249999994449e-005, 0.0000000000000000e+000, 3.1321752000000000e+001, 0.0000000000000000e+000, 1.3020833333333517e-004</GeoTransform>
  <Metadata domain="IMAGE_STRUCTURE">
    <MDI key="SOURCE_COLOR_SPACE">YCbCr</MDI>
    <MDI key="INTERLEAVE">PIXEL</MDI>
    <MDI key="COMPRESSION">JPEG</MDI>
  </Metadata>
  <Metadata>
    <MDI key="EXIF_XResolution">(96)</MDI>
    <MDI key="EXIF_YResolution">(96)</MDI>
    <MDI key="EXIF_ResolutionUnit">2</MDI>
    <MDI key="EXIF_Software">Paint.NET v3.5.8</MDI>
  </Metadata>
  <PAMRasterBand band="1">
    <Metadata domain="IMAGE_STRUCTURE">
      <MDI key="COMPRESSION">JPEG</MDI>
    </Metadata>
  </PAMRasterBand>
  <PAMRasterBand band="2">
    <Metadata domain="IMAGE_STRUCTURE">
      <MDI key="COMPRESSION">JPEG</MDI>
    </Metadata>
  </PAMRasterBand>
  <PAMRasterBand band="3">
    <Metadata domain="IMAGE_STRUCTURE">
      <MDI key="COMPRESSION">JPEG</MDI>
    </Metadata>
  </PAMRasterBand>
</PAMDataset>

If you load output.jpg with GdalRasterLayer, the image shows up at the specified location.

Hth FObermaier

Apr 28, 2011 at 1:52 PM

Dear FObermaier , thank you very much! i'll try it later!

very very thank you