Map projections and rotation, skewed shapes

270 views
Skip to first unread message

Daniel Patterson

unread,
Nov 5, 2013, 11:51:57 PM11/5/13
to map...@googlegroups.com
Hi all.

I've got a web map editor using Leaflet.draw where users draw some stuff in a EPSG:3857 view.
My data is then saved as lat/long to a PostGIS database in EPSG:4326.

I'm trying to rotate and then render (using Mapnik) this data, but when I do, things come out skewed.  I feel like I must be misunderstanding a piece of the projection pie.

For reference, here's what the users draw, and what I render if I do not rotate:


Here's what I would like to see (simply rotated in GIMP, proportions stay correct):


but here's what I get instead (code shown below):


(notice that some of the shapes are no longer square).

I'm using the Python Mapnik bindings and here's the relevant code snippet:

    m = mapnik2.Map(1000,1000)
    m.srs = "+init=epsg:3857"

    sql = '(SELECT ST_Rotate(geom,radians(%d),(select centroid from map where id=%d) as newgeom FROM polygons WHERE map_id =%d) as data' % (map.orientation,map.id,map.id)

    layer = mapnik2.Layer('Buildings')
    layer.srs = "+init=epsg:4326"
    layer.datasource = mapnik2.PostGIS(table=sql,geometry_field="newgeom",extent_from_subquery=True,st_prefix=True,srid=4326)

I'm operating at a fairly high latitude here (52 N), so I'm guessing that it has something to do with the fact that EPSG:3857 doesn't have the same scale N/S as it does E/W at that location, but I just can't seem to figure out how to go about getting the result I want.

Can anyone give me a hint in the right direction?

daniel

Daniel Patterson

unread,
Nov 6, 2013, 12:43:43 AM11/6/13
to map...@googlegroups.com
I believe I've solved it.  By performing the rotation *after* transforming the data to EPSG:3857, the horizontal and vertical scales are equalized:

  sql = '(SELECT ST_Rotate(ST_Transform(geom,3857),radians(%d),(select ST_Transform(centroid,3857) from map where id=%d) as newgeom FROM polygons WHERE map_id =%d) as data' % (map.orientation,map.id,map.id)

daniel

Rahkonen Jukka

unread,
Nov 6, 2013, 12:55:18 AM11/6/13
to map...@googlegroups.com
Hi,

Do the rotation in a system that has the same scales for E/W and N/W. If you convert into EPSG:3857 first with ST_Transform and rotate then the result should look good. But if you do not want to change your data nor your Mapnik code you shoud convert 4326>3857, rotate, and convert back 3857>4326 which feels complicated. It should still work.

-Jukka Rahkonen-



________________________________
--
You received this message because you are subscribed to the Google Groups "mapnik" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapnik+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages