I was following a tutorial on how to download OSM data in R with osmar package, so the code is:
library(osmar)
src <- osmsource_api()
bb <- center_bbox(174.76778, -36.85056, 700, 700)
ua <- get_osm(bb, source = src)
When I run this last line, this error appears:
Space required after the Public Identifier
SystemLiteral " or ' expected
SYSTEM or PUBLIC, the URI is missing
Opening and ending tag mismatch: hr line 7 and body
Opening and ending tag mismatch: body line 4 and html
Premature end of data in tag html line 2
Error: 1: Space required after the Public Identifier
2: SystemLiteral " or ' expected
3: SYSTEM or PUBLIC, the URI is missing
4: Opening and ending tag mismatch: hr line 7 and body
5: Opening and ending tag mismatch: body line 4 and html
6: Premature end of data in tag html line 2
I am not sure what this means. When I google this error, I can only see stuff related to Bioconductor, and biomaRt, which has nothing to do with what I am working. However, I believe that this has something to do with the connection with R to OSM website (?). So I'm wondering if anyone knows some tips on how to fix it. Thanks!
The error message you're seeing refers to the following response from the server. It basically means that the osmar package is trying to download via HTTP, but the server redirects you to the HTTPS location instead. For some reason osmar doesn't follow this redirect and fails. You should probably report this issue to the package owner to have it fixed.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://www.openstreetmap.org/api/0.6/map/?bbox=174.763855598139,-36.8537138679267,174.771704401861,-36.8474061320733">here</a>.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at api.openstreetmap.org Port 80</address>
</body></html>
One easy fix would be to provide the proper URL with HTTPS:
src <- osmsource_api(url = "https://api.openstreetmap.org/api/0.6/")
Side note: the OSM API (that's the endpoint you're using) is only meant to edit the map. So after all this might be violating the terms of usage of that service. Better use some alternatives based on OSM mirrors, or Overpass API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With