Eurostat shapefiles & google maps offset

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Eurostat shapefiles & google maps offset

Martin Zuba
Dear list,

I would like to plot shaded shapefiles with static google maps background
images.

I obtain the shapefiles from Eurostat, via the eurostat R package.

I obtain the static google background images from using the get_map wrapper
from the R package ggmap.

My problem is that there seems to be an offset between those two coordinate
systems. I know that the Eurostat files uss the coordinate reference system
ETRS89 and google maps uses WSG84, which should be (almost) identical.

However, google images and the shapefiles are somwhat off; and that offset
is not constant, which indicates that there might be a problem related to
projections.


illustration:
https://www.dropbox.com/s/34k2ace42ubjjek/eurostatVSgoogle.png?dl=0

replication:
https://www.dropbox.com/s/hhoc84lrmo42imf/niceEurostat.R?dl=0


I welcome any suggestions.

Best Regards,

Martin Zuba

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Eurostat shapefiles & google maps offset

Patrick Brown
Hello, you'll need to reproject either your shapefiles or the background
images.  The mapmisc package can get you background images in a specified
projection
https://journal.r-project.org/archive/2016-1/brown.pdf

p


> Message: 1
> Date: Wed, 22 Mar 2017 18:19:01 +0100
> From: Martin Zuba <[hidden email]>
> To: [hidden email]
> Subject: [R-sig-Geo] Eurostat shapefiles & google maps offset
> Message-ID:
>         <CAG3rrX6XbtNo8B9oTa=5=Yu7pN3WAA9m+BNC=dXKssA2D_un6Q@
> mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>
> Dear list,
>
> I would like to plot shaded shapefiles with static google maps background
> images.
>
> I obtain the shapefiles from Eurostat, via the eurostat R package.
>
> I obtain the static google background images from using the get_map wrapper
> from the R package ggmap.
>
> My problem is that there seems to be an offset between those two coordinate
> systems. I know that the Eurostat files uss the coordinate reference system
> ETRS89 and google maps uses WSG84, which should be (almost) identical.
>
> However, google images and the shapefiles are somwhat off; and that offset
> is not constant, which indicates that there might be a problem related to
> projections.
>
>
> illustration:
> https://www.dropbox.com/s/34k2ace42ubjjek/eurostatVSgoogle.png?dl=0
>
> replication:
> https://www.dropbox.com/s/hhoc84lrmo42imf/niceEurostat.R?dl=0
>
>
> I welcome any suggestions.
>
> Best Regards,
>
> Martin Zuba
>
>         [[alternative HTML version deleted]]
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> ------------------------------
>
> End of R-sig-Geo Digest, Vol 163, Issue 20
> ******************************************
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Eurostat shapefiles & google maps offset

Julian M. Burgos
In reply to this post by Martin Zuba
Martin, as far as I know Google images are in EPSG:3857, which is an
spherical Mercator projection, and not in WSG84.  The solution is to use
the spTransform function to project your polygons to EPSG:3857.

Julian

Martin Zuba writes:

> Dear list,
>
> I would like to plot shaded shapefiles with static google maps background
> images.
>
> I obtain the shapefiles from Eurostat, via the eurostat R package.
>
> I obtain the static google background images from using the get_map wrapper
> from the R package ggmap.
>
> My problem is that there seems to be an offset between those two coordinate
> systems. I know that the Eurostat files uss the coordinate reference system
> ETRS89 and google maps uses WSG84, which should be (almost) identical.
>
> However, google images and the shapefiles are somwhat off; and that offset
> is not constant, which indicates that there might be a problem related to
> projections.
>
>
> illustration:
> https://www.dropbox.com/s/34k2ace42ubjjek/eurostatVSgoogle.png?dl=0
>
> replication:
> https://www.dropbox.com/s/hhoc84lrmo42imf/niceEurostat.R?dl=0
>
>
> I welcome any suggestions.
>
> Best Regards,
>
> Martin Zuba
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


--
Julian Mariano Burgos, PhD
Hafrannsóknastofnun, rannsókna- og ráðgjafarstofnun hafs og vatna/
Marine and Freshwater Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Eurostat shapefiles & google maps offset

Patricia J. Hawkins
In reply to this post by Martin Zuba
Hi, when I run your example code, I get the following warnings from your
get_map calls:

"Warning: bounding box given to google - spatial extent only approximate.
converting bounding box to center/zoom specification. (experimental)
Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=47.474661,16.578517&zoom=7&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false"

"Warning: bounding box given to google - spatial extent only approximate.
converting bounding box to center/zoom specification. (experimental)
Map from URL :
http://maps.googleapis.com/maps/api/staticmap?center=47.925583,15.807816&zoom=6&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false"

Seems Google maps is giving you images with an exact center, but
approximate bounds, which are not quite the same as the limits you gave it.  

And you are calculating your clipping boxes from your limits, not from
the center, so the difference between your limits and google's
approximation shows up in your overlays.  And you're getting a different
approximation in the second call, hence the different offset.

Don't ignore warnings; understand them.

May I say, the reason you've gotten slow help on this is that this
*isn't* a minimal demonstration of the problem?   Also, your coding
style makes your code difficult to read, and is a big potential source
of bugs.

* For a minimal example, you need to cut out all other transforms and
  massaging, so far as possible.  Your massaging of the eurostat data
  could be a source of the problem, and your readers have to spend time
  looking at it and understanding it.

  Cutting down to a truly minimal example is also a good way to find
  the problem for yourself.  And it will make you a better programmer.

* You calculate the same value repeatedly: Doing this is potentially
  inefficient, a big source of errors, and a tax on anyone who reads your code.

  For instance,  you could do:
  center.lat <- mean(range(map.dat$lat,na.rm=TRUE))
  center.lon <- mean(range(map.dat$lon,na.rm=TRUE))

  and just reuse that, with much greater clarity.

* Don't include raw constants in your code -- for instance, 1.1, 5.
  This is always a bad practice, and here it's another tax on your
  reader: what does "5" mean?  

  Better to use a variable, which a) documents your code and b) only
  needs to be changed in one place, not throughout your code.  Just try
  "query replace 5" sometime, in a big piece of code.
 
  For example:

  large_scaling_factor <- 5
  small_scaling_factor <- 1.1

I hope you find this useful -- these are some simple practices that can
save you many, many hours of confusion and debugging.

And just as an aside, I was amused to see that the center of your first
bounding box is between Kleinmutschen and Großmutschen.  Have courage --
at least a little!

--
Patricia J. Hawkins

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Loading...