[R-sig-Geo] Eurostat shapefiles & google maps offset
Patricia J. Hawkins
phawkins at connact.com
Thu Mar 30 16:10:12 CEST 2017
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
More information about the R-sig-Geo
mailing list