cgutteridge / geocraft

GNU General Public License v3.0
97 stars 23 forks source link

Set direction for "north" #12

Open amyworrall opened 8 years ago

amyworrall commented 8 years ago

I want to import something that has roads that are grid-aligned, but the grid is not north/south. If the whole thing were rotated, it would line up nicely with Minecraft blocks.

cgutteridge commented 8 years ago

I see... So you want to be able to specify a rotation to apply? It's probably possible but would require a lot of head scratching first.

There's 2 functions in Projection called grid_to_ll and ll_to_grid which convert between lat/long and UK grid OSGB36... I guess you could hack it so that it rotated there but I'm not 100% sure...

On 19/07/2016 18:00, amyworrall wrote:

I want to import something that has roads that are grid-aligned, but the grid is not north/south. If the whole thing were rotated, it would line up nicely with Minecraft blocks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cgutteridge/geocraft/issues/12, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfK62Eg0PrOgkyEj5dKUZUGqXomrO0Oks5qXQK6gaJpZM4JP8b3.

Christopher Gutteridge -- http://users.ecs.soton.ac.uk/cjg

University of Southampton Open Data Service: http://data.southampton.ac.uk/ You should read the ECS Web Team blog: http://blogs.ecs.soton.ac.uk/webteam/

amyworrall commented 8 years ago

Yeah, specifying a rotation would be ideal!

Is the grid value returned from ll_to_grid() what you use to derive the Minecraft coordinate?

cgutteridge commented 8 years ago

Yes. The projection object just has an offset for the difference between real-world 0,0 and Minecraft 0,0. You could probably get away with just tweaking the grid_to_ll function and see what happens... eg. apply a transformation to the $e and $n before they go into the scary maths I cut and pasted...

On 19/07/2016 18:21, amyworrall wrote:

Yeah, specifying a rotation would be ideal!

Is the grid value returned from |ll_to_grid()| what you use to derive the Minecraft coordinate?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cgutteridge/geocraft/issues/12#issuecomment-233704179, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfK60vk-8IojnNhxzjTP3vmzccZ58lmks5qXQeEgaJpZM4JP8b3.Web Bug from https://github.com/notifications/beacon/AAfK67YYYW068qwJHa7S4K4w7nGoMdZ0ks5qXQeEgaJpZM4JP8b3.gif

Christopher Gutteridge -- http://users.ecs.soton.ac.uk/cjg

University of Southampton Open Data Service: http://data.southampton.ac.uk/ You should read the ECS Web Team blog: http://blogs.ecs.soton.ac.uk/webteam/

amyworrall commented 8 years ago

It worked! As a quick hack, here's how I did it:

sub grid_to_ll
{
    my( $e, $n, $grid, $self ) = @_;

        # campus rotation
        my $eprime = ($e - $self->{offset_e}) * cos($CAMPUS_ANGLE) - ($n - $self->{offset_n}) * sin($CAMPUS_ANGLE) + $self->{offset_e};
        my $nprime = ($n - $self->{offset_n}) * cos($CAMPUS_ANGLE) + ($e - $self->{offset_e}) * sin($CAMPUS_ANGLE) + $self->{offset_n};

#       print "e: $e, n: $n, eprime: $eprime, nprime: $nprime\n";

    if( defined $grid && $grid eq "MERC" )
    {
        my $lat = rad2deg(atan(sinh( pi - (2 * pi * -$nprime / (2**$ZOOM * ($TILE_H * $M_PER_PIX))) )));
        my $long = (($eprime / ($TILE_W * $M_PER_PIX)) / 2**$ZOOM)*360-180;
        return( $lat, $long );
    }
    if( defined $grid && $grid eq "OSGB36" )
    {
        my( $x,$y)= Geo::Coordinates::OSTN02::OSGB36_to_ETRS89($eprime, $nprime );
        return Geo::Coordinates::OSGB::grid_to_ll($x, $y, 'ETRS89'); # or 'WGS84'
    }

    return Geo::Coordinates::OSGB::grid_to_ll( $e,$n, $grid );
}

The variable $CAMPUS_ROTATION supplied in radians.

It'd be great to get this as an optional command line argument. But for my purposes (making a map of Warwick University), it worked :)

cgutteridge commented 8 years ago

Wow!

Could I also recommend you consider trying it with --blocks blocks/blocks.hollow ? It takes longer but makes the buildings into shells rather than solid..

On 20/07/2016 10:54, amyworrall wrote:

It worked! As a quick hack, here's how I did it:

|sub grid_toll { my( $e, $n, $grid, $self ) = @; # campus rotation my $eprime = ($e - $self->{offset_e}) * cos($CAMPUS_ANGLE) - ($n - $self->{offset_n}) * sin($CAMPUS_ANGLE) + $self->{offset_e}; my $nprime = ($n - $self->{offset_n}) * cos($CAMPUS_ANGLE) + ($e - $self->{offset_e}) * sin($CAMPUS_ANGLE) + $self->{offset_n}; # print "e: $e, n: $n, eprime: $eprime, nprime: $nprime\n"; if( defined $grid && $grid eq "MERC" ) { my $lat = rad2deg(atan(sinh( pi - (2 * pi * -$nprime / (2$ZOOM * ($TILE_H * $M_PER_PIX))) ))); my $long = (($eprime / ($TILE_W * $M_PER_PIX)) / 2$ZOOM)*360-180; return( $lat, $long ); } if( defined $grid && $grid eq "OSGB36" ) { my( $x,$y)= Geo::Coordinates::OSTN02::OSGB36_to_ETRS89($eprime, $nprime ); return Geo::Coordinates::OSGB::grid_to_ll($x, $y, 'ETRS89'); # or 'WGS84' } return Geo::Coordinates::OSGB::grid_to_ll( $e,$n, $grid ); } |

The variable $CAMPUS_ROTATION supplied in radians.

It'd be great to get this as an optional command line argument. But for my purposes (making a map of Warwick University), it worked :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cgutteridge/geocraft/issues/12#issuecomment-233904882, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfK67qFRd4cbQuee6X9Qt27VznAJjJdks5qXfA8gaJpZM4JP8b3.

Christopher Gutteridge -- http://users.ecs.soton.ac.uk/cjg

University of Southampton Open Data Service: http://data.southampton.ac.uk/ You should read the ECS Web Team blog: http://blogs.ecs.soton.ac.uk/webteam/

amyworrall commented 8 years ago

Oooh, good idea! I'm currently trying to run it to do a 2500-square map — it keeps erroring out when the OpenStreetMap server returns a 404 instead of a tile. (I've got a workaround where I download the tile manually, but I have to restart the script.) If I need to restart it again, I'll do the hollow buildings version.

cgutteridge commented 8 years ago

Yes. I've seen that a couple of times but have not done a good work around yet.

Other pending ideas are to support alternate elevation sources and projections. Also I'd like it if it would generate maps by 512x512 region so it was easier to make a distributed option so you could set up the projection & options then generate a region file at a time, maybe shared between a community.

On 20/07/2016 11:33, amyworrall wrote:

Oooh, good idea! I'm currently trying to run it to do a 2500-square map — it keeps erroring out when the OpenStreetMap server returns a 404 instead of a tile. (I've got a workaround where I download the tile manually, but I have to restart the script.) If I need to restart it again, I'll do the hollow buildings version.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cgutteridge/geocraft/issues/12#issuecomment-233913343, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfK6_jJz-th_ecbNc0H0PEesvXJS-Qoks5qXfl5gaJpZM4JP8b3.

Christopher Gutteridge -- http://users.ecs.soton.ac.uk/cjg

University of Southampton Open Data Service: http://data.southampton.ac.uk/ You should read the ECS Web Team blog: http://blogs.ecs.soton.ac.uk/webteam/