NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

2
2

Heyho!

I want to render a map.png in UTM-Projection. But I didn't find anything useful on the internet.. :(

Can anyone tell me, what I have to do to simply render in UTM-Projection??

I only want to render small maps so the different zones should not be a problem, I think.

I imported my schleswig-holstein.osm via osm2pgsql to my PostgreSQL/PostGIS database and now I want to render using Python/Mapnik.

I'm very thankful for any little hint or idea! Please help me!

Greetz Matze

asked 09 May '12, 09:14

MHein's gravatar image

MHein
141111116
accept rate: 0%


-1

the map's srs is the dest srs, while your datasource's srs are the source srs. since you use osm data, so the datasource's is under wgs84(i.e.lat/long). To project to utm, you should set your map's srs to the desired utm zone.

permanent link

answered 24 May '12, 13:26

feverzsj's gravatar image

feverzsj
101
accept rate: 0%

No, this is not correct, since he used
: osm2pgsql --slim -d gis -C 1024 -E 32632
to import the data. Pay attention to the -E switch. So his data in PostGIS is actually UTM 32N

(24 May '12, 13:42) frabron

then no projection is needed for mapnik, just set all to same srs

(24 May '12, 13:50) feverzsj

as far as I know, I set all the srs..

In which files do I have to set the srs?

(30 May '12, 10:02) MHein
2

The possibly quickest way would be to add a new projection definition to inc/entities.xml.inc

<!ENTITY utm32 "+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs">

just below the other two (srs900913 and srs4326) and in inc/settings.xml.inc set

<!ENTITY osm2pgsql_projection "&srs900913;">

to

<!ENTITY osm2pgsql_projection "&utm32;">

There's probably no need to adjust the dwithin parameters, I'd give it a try like I described it.

HTH Frank

(31 May '12, 13:27) frabron

Thank you! I had added the projection in entities yet. But the change in settings was not made yet. now it looks this way:

<!-- use the '&srs900913;' entity if you have called osm2pgsql without special flags (or with -m); use '&srs4326;' if you have used -l -->
<!-- <!ENTITY osm2pgsql_projection "&srs900913;"> -->
<!ENTITY osm2pgsql_projection "&srs_UTM;">

I will try the next few days if it works ;)

(31 May '12, 15:40) MHein
1

it doesn't work :(

(17 Aug '12, 10:11) MHein
showing 5 of 6 show 1 more comments

Just to make this a little bit clearer and to give you an "answer":
If you define an UTM projection in your XML, you simply need to (for mapnik2)

bounds = (000000, -8100000, 3700000 , 8100000)
mapfile = '/your/path/to/osm.xml'
map_ = mapnik.Map(500, 500)
mapnik.load_map(map_, mapfile)
bbox = mapnik.Envelope(*bounds)
map_.zoom_to_box(bbox)
image = mapnik.Image(width, height)
mapnik.render(map_, image)
image.save(image_name, 'png')

and that should give you an image in UTM. You may verify this by printing some metadata

print map_.srs
print map_.scale_denominator()

HTH Frank

permanent link

answered 21 May '12, 08:53

frabron's gravatar image

frabron
3611411
accept rate: 16%

Heyho!

I tried rendering in UTM but when I had eliminated all errors and saw the map, I recognized that the map was still rendered in standard (google?)-projection (where Greenland is as big as Africa).

I changed the -- Map background-color="#fff" srs="+init=epsg:3857" -- into -- Map background-color="#b5d0d0" srs="&srs_UTM;" --

and defined srs_UTM in entities.xml.inc this way:

<!ENTITY srs_UTM "+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs">

In my generate_imgage.py I used:

bounds = (000000, -8100000, 3700000 , 8100000)
# utm in meters 
    utm = mapnik.Projection('+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs')
transform = mapnik.ProjTransform(utm,merc)

I don't know what I did wrong or maybe what I forgot to change.. e.g. I found

# ensure the target map projection is mercator
m.srs = merc.params()

and I don't know If I should change it or anything else..

this is my entities.xcl.inc: http://dpaste.org/cuJW3/

this is my osm.xml: http://dpaste.org/xLqJA/

this is my generate_image.py: http://dpaste.org/0WEQw/

I hope that anyone can help me.. please!!!

Greetings Matze

(14 May '12, 07:48) MHein
1

Well, apparently you are transforming your desired UTM to Mercator in your Python script. Just skip the transformation steps and you should be fine

(21 May '12, 08:43) frabron

Unfortunately it doesn't work.. I will describe the problems in another answer.

(23 May '12, 11:39) MHein

First of all, thank you, Frank!

I deleted all the transformation-things etc. und put the things as you wrote it.

The rendering doesn't produce any errors but the maps I get are not like I want them.

This happens, when I try to render my hometown Kiel in Schleswig-Holstein, Germany: http://imgur.com/CIPJ5
( bounds = (565124, 6014024, 579888 , 6026499) #Kiel UTM )

This looks as if just the coastlines are used to create this image. Why is the osm-content of my schleswig-holstein.osm.pbf not displayed? I imported it like this: osm2pgsql --slim -d gis -C 1024 -E 32632 ~/schleswig-holstein.osm.pbf

When I try to render the whole world, the image looks like this: http://imgur.com/f2gNa

( bounds = (000000, -8100000, 3700000 , 8100000) )

This looks as if the coastlines have not been used.. Is it because of the fact that the coastlines are not in the right projection?

I'll post my new_generate_image.py: http://dpaste.org/RScJO/

Maybe you, Frank or anybody else can can give me some useful advice, info or hint! That would make me really glad!

Thank you in advance! Greetings, Matze

(23 May '12, 12:08) MHein
1

I know Kiel, there's definetely more to see there ;-)
I guess that there's a problem with your data from the database. Did you configure your datasource and settings files correctly, e.g. paths to shapefiles and EPSG codes? Look in the "inc" Folder for those ...

(23 May '12, 15:11) frabron

Yes, much more!

As a test, I imported (by osm2pgsql) my schleswig-holstein.osm.pbf with standard projection and rendered with the standard generate_image.py and it all worked out fine.. and I was using the same "inc"-files.

Anyway, it's surprising that Kiel has the coastline and for the whole world they seem to be missing..

any other idea?

(24 May '12, 08:45) MHein
showing 5 of 6 show 1 more comments

Well you should have an XML style file that gives the desired map projection at the top, like this:

<Map background-color="#fff" srs="+init=epsg:3857">

If you change that to the EPSG code for the UTM projection you want to use (or even, instead of using one of the existing definitions, just write your own projection definition there in proj4 style) then the map is generated in that projection. Be careful when specifying the render extent; you'll have to give that in UTM coordinates then as well.

If you use nik2img.py (recommended), you can even specify the projection on the command line.

In the <Layer> defintions that reference your database, make sure to stick to the projection you imported your data in; so if you ran osm2pgsql without -E or -l (ell), the <Layer> bits will continue to have to use EPSG:3857 no matter what your output projection.

permanent link

answered 09 May '12, 09:25

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

edited 09 May '12, 09:26

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×440
×341
×20
×7

question asked: 09 May '12, 09:14

question was seen: 10,304 times

last updated: 17 Aug '12, 10:11

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum