Raster Layer is Clipped

View: New views
8 Messages — Rating Filter:   Alert me  

Raster Layer is Clipped

by ajayre :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've given up on trying to compile pgsql2sqlite for now and instead made
some progress on using a georeferenced layer using Gdal. However it
seems that Mapnik is clipping the image even though I have set the map
size to the size of the bitmap and used the bitmap envelope.

Here are my input files:

http://files.britishideas.com/public/mapping/osmgeoref.png
http://files.britishideas.com/public/mapping/osmgeoref.pgw

I run this script:

-------------------------------------------
from mapnik import *
m = Map(800,391,'+proj=latlong +datum=WGS84')
m.background = Color('red')
s = Style()
r=Rule()
r.symbols.append(RasterSymbolizer())
s.rules.append(r)
m.append_style('My Style',s)
lyr = Layer('world')
lyr.datasource = Gdal(file='osmgeoref.png')
lyr.styles.append('My Style')
m.layers.append(lyr)
m.zoom_to_box(lyr.envelope())
render_to_file(m, 'demo.png')
save_map(m, 'map.xml')
-------------------------------------------

And here is the output with the top and bottom of the input PNG missing:

http://files.britishideas.com/public/mapping/demo.png

For completeness here is the output XML file:

http://files.britishideas.com/public/mapping/map.xml

I used red as a background colour to highlight the issue. Any ideas what
  I am doing wrong? I'm sure I'm overlooking something silly.

Thanks!! Andy

--
Andy
PGP Key ID: 0xDC1B5864
_______________________________________________
Mapnik-users mailing list
Mapnik-users@...
https://lists.berlios.de/mailman/listinfo/mapnik-users

Re: Raster Layer is Clipped

by Jon Burgess-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, 2009-06-21 at 11:28 -0700, Andrew Ayre wrote:

> I've given up on trying to compile pgsql2sqlite for now and instead made
> some progress on using a georeferenced layer using Gdal. However it
> seems that Mapnik is clipping the image even though I have set the map
> size to the size of the bitmap and used the bitmap envelope.
>
> Here are my input files:
>
> http://files.britishideas.com/public/mapping/osmgeoref.png
> http://files.britishideas.com/public/mapping/osmgeoref.pgw
>
> I run this script:
>
> -------------------------------------------
> from mapnik import *
> m = Map(800,391,'+proj=latlong +datum=WGS84')
> m.background = Color('red')
> s = Style()
> r=Rule()
> r.symbols.append(RasterSymbolizer())
> s.rules.append(r)
> m.append_style('My Style',s)
> lyr = Layer('world')
> lyr.datasource = Gdal(file='osmgeoref.png')
> lyr.styles.append('My Style')
> m.layers.append(lyr)
> m.zoom_to_box(lyr.envelope())
> render_to_file(m, 'demo.png')
> save_map(m, 'map.xml')
> -------------------------------------------
>
> And here is the output with the top and bottom of the input PNG missing:
>
> http://files.britishideas.com/public/mapping/demo.png
>
> For completeness here is the output XML file:
>
> http://files.britishideas.com/public/mapping/map.xml
>
> I used red as a background colour to highlight the issue. Any ideas what
>   I am doing wrong? I'm sure I'm overlooking something silly.

I can not explain it particularly clearly, but I believe the problem is
that the original image was not created in latlong projection, hence the
800x361 pixels are not square:

$ gdalinfo osmgeoref.png
Driver: PNG/Portable Network Graphics
Files: osmgeoref.png
Size is 800, 391
Coordinate System is `'
Origin = (-110.812896694075803,32.220948081346208)
Pixel Size = (0.000037724479586,-0.000031870889024)

Notice how the pixel sizes are different in the two dimensions. If you
adjust the output bitmap to fit this ratio then you get:

800 * 0.000037724479586 / 0.000031870889024 = 947

Then resize the map to this dimension:

m = Map(947,391,'+proj=latlong +datum=WGS84')

The final output then looks like the original with no clipping.

        Jon


_______________________________________________
Mapnik-users mailing list
Mapnik-users@...
https://lists.berlios.de/mailman/listinfo/mapnik-users

Re: Raster Layer is Clipped

by ajayre :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jon Burgess wrote:

> On Sun, 2009-06-21 at 11:28 -0700, Andrew Ayre wrote:
>> I've given up on trying to compile pgsql2sqlite for now and instead made
>> some progress on using a georeferenced layer using Gdal. However it
>> seems that Mapnik is clipping the image even though I have set the map
>> size to the size of the bitmap and used the bitmap envelope.
>>
>> Here are my input files:
>>
>> http://files.britishideas.com/public/mapping/osmgeoref.png
>> http://files.britishideas.com/public/mapping/osmgeoref.pgw
>>
[snipped]

>>
>> And here is the output with the top and bottom of the input PNG missing:
>>
>> http://files.britishideas.com/public/mapping/demo.png
>>
>> For completeness here is the output XML file:
>>
>> http://files.britishideas.com/public/mapping/map.xml
>>
>> I used red as a background colour to highlight the issue. Any ideas what
>>   I am doing wrong? I'm sure I'm overlooking something silly.
>
> I can not explain it particularly clearly, but I believe the problem is
> that the original image was not created in latlong projection, hence the
> 800x361 pixels are not square:
>
> $ gdalinfo osmgeoref.png
> Driver: PNG/Portable Network Graphics
> Files: osmgeoref.png
> Size is 800, 391
> Coordinate System is `'
> Origin = (-110.812896694075803,32.220948081346208)
> Pixel Size = (0.000037724479586,-0.000031870889024)
>
> Notice how the pixel sizes are different in the two dimensions. If you
> adjust the output bitmap to fit this ratio then you get:
>
> 800 * 0.000037724479586 / 0.000031870889024 = 947
>
> Then resize the map to this dimension:
>
> m = Map(947,391,'+proj=latlong +datum=WGS84')
>
> The final output then looks like the original with no clipping.
>

Hi Jon,

I tried it and the output isn't quite the same as the input. The top of
the image now matches but the bottom doesn't. Notice the orange road at
the very bottom of the input image? It's chopped off the output image.

Andy

--
Andy
PGP Key ID: 0xDC1B5864
_______________________________________________
Mapnik-users mailing list
Mapnik-users@...
https://lists.berlios.de/mailman/listinfo/mapnik-users

Re: Raster Layer is Clipped

by Jon Burgess-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, 2009-06-21 at 17:00 -0700, Andrew Ayre wrote:

> Jon Burgess wrote:
> > On Sun, 2009-06-21 at 11:28 -0700, Andrew Ayre wrote:
> >> I've given up on trying to compile pgsql2sqlite for now and instead made
> >> some progress on using a georeferenced layer using Gdal. However it
> >> seems that Mapnik is clipping the image even though I have set the map
> >> size to the size of the bitmap and used the bitmap envelope.
> >>
> >> Here are my input files:
> >>
> >> http://files.britishideas.com/public/mapping/osmgeoref.png
> >> http://files.britishideas.com/public/mapping/osmgeoref.pgw
> >>
> [snipped]
> >>
> >> And here is the output with the top and bottom of the input PNG missing:
> >>
> >> http://files.britishideas.com/public/mapping/demo.png
> >>
> >> For completeness here is the output XML file:
> >>
> >> http://files.britishideas.com/public/mapping/map.xml
> >>
> >> I used red as a background colour to highlight the issue. Any ideas what
> >>   I am doing wrong? I'm sure I'm overlooking something silly.
> >
> > I can not explain it particularly clearly, but I believe the problem is
> > that the original image was not created in latlong projection, hence the
> > 800x361 pixels are not square:
> >
> > $ gdalinfo osmgeoref.png
> > Driver: PNG/Portable Network Graphics
> > Files: osmgeoref.png
> > Size is 800, 391
> > Coordinate System is `'
> > Origin = (-110.812896694075803,32.220948081346208)
> > Pixel Size = (0.000037724479586,-0.000031870889024)
> >
> > Notice how the pixel sizes are different in the two dimensions. If you
> > adjust the output bitmap to fit this ratio then you get:
> >
> > 800 * 0.000037724479586 / 0.000031870889024 = 947
> >
> > Then resize the map to this dimension:
> >
> > m = Map(947,391,'+proj=latlong +datum=WGS84')
> >
> > The final output then looks like the original with no clipping.
> >
>
> Hi Jon,
>
> I tried it and the output isn't quite the same as the input. The top of
> the image now matches but the bottom doesn't. Notice the orange road at
> the very bottom of the input image? It's chopped off the output image.
No, it looks the same as the input to me.

There will always be some slight distortion if you are using an image in
a different projection.

        Jon




_______________________________________________
Mapnik-users mailing list
Mapnik-users@...
https://lists.berlios.de/mailman/listinfo/mapnik-users

demo256.png (80K) Download Attachment

Re: Raster Layer is Clipped

by ajayre :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jon Burgess wrote:

> On Sun, 2009-06-21 at 17:00 -0700, Andrew Ayre wrote:
>> Jon Burgess wrote:
>>> On Sun, 2009-06-21 at 11:28 -0700, Andrew Ayre wrote:
>>>> I've given up on trying to compile pgsql2sqlite for now and instead made
>>>> some progress on using a georeferenced layer using Gdal. However it
>>>> seems that Mapnik is clipping the image even though I have set the map
>>>> size to the size of the bitmap and used the bitmap envelope.
>>>>
>>>> Here are my input files:
>>>>
>>>> http://files.britishideas.com/public/mapping/osmgeoref.png
>>>> http://files.britishideas.com/public/mapping/osmgeoref.pgw
>>>>
>> [snipped]
>>>> And here is the output with the top and bottom of the input PNG missing:
>>>>
>>>> http://files.britishideas.com/public/mapping/demo.png
>>>>
>>>> For completeness here is the output XML file:
>>>>
>>>> http://files.britishideas.com/public/mapping/map.xml
>>>>
>>>> I used red as a background colour to highlight the issue. Any ideas what
>>>>   I am doing wrong? I'm sure I'm overlooking something silly.
>>> I can not explain it particularly clearly, but I believe the problem is
>>> that the original image was not created in latlong projection, hence the
>>> 800x361 pixels are not square:
>>>
>>> $ gdalinfo osmgeoref.png
>>> Driver: PNG/Portable Network Graphics
>>> Files: osmgeoref.png
>>> Size is 800, 391
>>> Coordinate System is `'
>>> Origin = (-110.812896694075803,32.220948081346208)
>>> Pixel Size = (0.000037724479586,-0.000031870889024)
>>>
>>> Notice how the pixel sizes are different in the two dimensions. If you
>>> adjust the output bitmap to fit this ratio then you get:
>>>
>>> 800 * 0.000037724479586 / 0.000031870889024 = 947
>>>
>>> Then resize the map to this dimension:
>>>
>>> m = Map(947,391,'+proj=latlong +datum=WGS84')
>>>
>>> The final output then looks like the original with no clipping.
>>>
>> Hi Jon,
>>
>> I tried it and the output isn't quite the same as the input. The top of
>> the image now matches but the bottom doesn't. Notice the orange road at
>> the very bottom of the input image? It's chopped off the output image.
>
> No, it looks the same as the input to me.
>
> There will always be some slight distortion if you are using an image in
> a different projection.

Interesting! So with the same input files and same script you get a
different output to me. Here is my output:

http://files.britishideas.com/public/mapping/output.png

Notice how it is the same dimensions as yours but missing quite a bit
off the bottom. Also there are lots of jagged lines because it looks
like the image has been stretched.

I am using Mapnik 0.6.0 on Windows XP. If you are not using Windows
perhaps this is a bug in the Windows version?

Andy

--
Andy
PGP Key ID: 0xDC1B5864
_______________________________________________
Mapnik-users mailing list
Mapnik-users@...
https://lists.berlios.de/mailman/listinfo/mapnik-users

Re: Raster Layer is Clipped

by Jon Burgess-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 2009-06-22 at 09:01 -0700, Andrew Ayre wrote:
> Interesting! So with the same input files and same script you get a
> different output to me. Here is my output:
>
> http://files.britishideas.com/public/mapping/output.png

Your image is definitely different to mine. The only thing I changed was
the Map() dimensions that I posted before.

> Notice how it is the same dimensions as yours but missing quite a bit
> off the bottom. Also there are lots of jagged lines because it looks
> like the image has been stretched.

Mine is stretched a little - it has to be given the way the dimensions
have changed. I guess the original image was in the OSM style 900913
projection. If you used this instead then you should avoid the
stretching. Alternatively, you could render the input image in latlong.

> I am using Mapnik 0.6.0 on Windows XP. If you are not using Windows
> perhaps this is a bug in the Windows version?

I'm using a fairly recent SVN mapnik build (r1179) on Fedora 10 x86_64
along with gdal-1.5.3-1.fc10.x86_64. I don't remember any specific fixes
to the projection since 0.6 though.

I think the best approach would be to use the same projection for the
raster and output map. This should avoid any issues with the image
changing dimensions and avoid any clipping issues.

        Jon




_______________________________________________
Mapnik-users mailing list
Mapnik-users@...
https://lists.berlios.de/mailman/listinfo/mapnik-users

Re: Raster Layer is Clipped

by ajayre :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jon Burgess wrote:

> On Mon, 2009-06-22 at 09:01 -0700, Andrew Ayre wrote:
>> I am using Mapnik 0.6.0 on Windows XP. If you are not using Windows
>> perhaps this is a bug in the Windows version?
>
> I'm using a fairly recent SVN mapnik build (r1179) on Fedora 10 x86_64
> along with gdal-1.5.3-1.fc10.x86_64. I don't remember any specific fixes
> to the projection since 0.6 though.
>
> I think the best approach would be to use the same projection for the
> raster and output map. This should avoid any issues with the image
> changing dimensions and avoid any clipping issues.

I don't have control over the image because it is produced by Kosmos. I
think that a bug has been fix between the 0.6.0 release and r1179. Any
idea when new Windows binaries will be released?

Andy

--
Andy
PGP Key ID: 0xDC1B5864
_______________________________________________
Mapnik-users mailing list
Mapnik-users@...
https://lists.berlios.de/mailman/listinfo/mapnik-users

Re: Raster Layer is Clipped

by Jon Burgess-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 2009-06-23 at 15:24 -0700, Andrew Ayre wrote:
>
> I don't have control over the image because it is produced by Kosmos.
> I
> think that a bug has been fix between the 0.6.0 release and r1179.
> Any
> idea when new Windows binaries will be released?
>

The current plan is to release 0.6.1 in about 2 weeks[1] and should
include new Windows binaries.

        Jon


1: http://trac.mapnik.org/milestone/0.6.1


_______________________________________________
Mapnik-users mailing list
Mapnik-users@...
https://lists.berlios.de/mailman/listinfo/mapnik-users