<div dir="ltr"><div>Hi Benjamin,</div><div>please respond to the list as well. Other people may have similar issues and this way we can find the solutions online.</div><div><br></div><div>If you want to extract the data along with the geometries, here's how you could do it:</div><div><br></div><div>library(leaflet)<br>library(jsonlite)<br>library(sf)<br><br>url <- "<a href="http://www.georisques.gouv.fr/api/v1/sis?rayon=1000&latlon=4.854899%2C%2045.763079&page=1&page_size=10">http://www.georisques.gouv.fr/api/v1/sis?rayon=1000&latlon=4.854899%2C%2045.763079&page=1&page_size=10</a>"<br><br>geojson <- jsonlite::fromJSON(url)<br><br># convert coordinate arrays to matrices<br>geom = lapply(geojson$data$geom$coordinates, matrix, ncol = 2)<br># create multipolygon from coordinate matrices<br>geom = lapply(geom, function(i) st_polygon(list(i)))<br># overwrite the geom column of data in geojson<br>geojson$data$geom = st_sfc(geom, crs = 4326)<br># exract data from geojson and turn into an sf object<br>dat = st_as_sf(geojson$data)<br><br>leaflet() %>%<br>  addTiles()%>%<br>  setView(lng = 4.854899, lat = 45.763079, zoom = 14) %>%<br>  addMarkers(lng = 4.872536, lat = 45.758321)%>%<br>  addPolygons(data = dat, popup = ~nom)</div><div><br></div><div>This way, as you can see, you can use the tilde (~) notation to include popups referring to a column of the data.</div><div><br></div><div>I don't think that what you get using RSONIO is any closer to a valid geojson.</div><div><br></div><div>Best</div><div>Tim<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 9, 2019 at 3:28 PM Benjamin Pauget <<a href="mailto:benjamin.pauget@tesora.fr">benjamin.pauget@tesora.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="FR">
<div class="gmail-m_1072751641916935796WordSection1">
<p class="MsoNormal"><span>Dear Tim, <u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Tanks you soooo much for your response !<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">I am a beginner and working with geospatial is still unclear.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">I have tried to open my json file with “from_JSON” and I have another format of my data :<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">url <- "<a href="http://www.georisques.gouv.fr/api/v1/sis?rayon=5000&latlon=4.854899%2C%2045.763079&page=1&page_size=10" target="_blank">http://www.georisques.gouv.fr/api/v1/sis?rayon=5000&latlon=4.854899%2C%2045.763079&page=1&page_size=10</a>"<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">geojson4 <- RJSONIO::fromJSON(url)
<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Do you think this format is more relevant and will allow to display the pop’up info ?<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Thank you again for your code (I just pass the two last day on trying to display the polygons) !<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Best regards,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<table class="gmail-m_1072751641916935796MsoNormalTable" style="width:130.7pt;border-collapse:collapse" width="174" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td colspan="2" style="width:130.7pt;padding:0cm 5.4pt" width="174" valign="top">
<p class="MsoNormal"><b><span style="font-size:9pt;font-family:"Tahoma",sans-serif;color:rgb(0,59,106)">Benjamin PAUGET<u></u><u></u></span></b></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Tahoma",sans-serif;color:rgb(0,59,106)">Responsable R&D<u></u><u></u></span></p>
</td>
</tr>
<tr style="height:1.65pt">
<td colspan="2" style="width:130.7pt;padding:0cm 5.4pt;height:1.65pt" width="174" valign="bottom">
<p class="MsoNormal"><img style="width: 1.6666in; height: 0.4687in;" id="gmail-m_1072751641916935796Image_x0020_17" src="cid:16bd71a2a854cff311" alt="cid:image005.png@01D4F3BB.3531D840" width="160" height="45"><u></u><u></u></p>
</td>
</tr>
<tr style="height:2.85pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:2.85pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:2pt;font-family:"Tahoma",sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif">+33 (0)1 81 94 13 70<u></u><u></u></span></p>
</td>
<td rowspan="2" style="width:35.4pt;padding:0cm 5.4pt;height:2.85pt" width="47" valign="bottom">
</td>
</tr>
<tr style="height:1.4pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:1.4pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif">+33 (0)6 47 01 85 92</span><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif"><u></u><u></u></span></p>
</td>
</tr>
<tr style="height:1.4pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:1.4pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif">Le Visium<u></u><u></u></span></p>
</td>
<td rowspan="2" style="width:35.4pt;padding:0cm 5.4pt;height:1.4pt" width="47" valign="bottom">
</td>
</tr>
<tr style="height:1.4pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:1.4pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif">22 Av Aristide Briand</span><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif"><u></u><u></u></span></p>
</td>
</tr>
<tr style="height:1.4pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:1.4pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif">94110 ARCUEIL<u></u><u></u></span></p>
</td>
<td rowspan="2" style="width:35.4pt;padding:0cm 5.4pt;height:1.4pt" width="47" valign="bottom">
</td>
</tr>
<tr style="height:1.4pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:1.4pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:8.5pt"><a href="https://tesora.fr/" target="_blank"><span style="font-family:"Tahoma",sans-serif">https://tesora.fr/</span></a></span><span style="font-size:8.5pt"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif"><a href="https://www.linkedin.com/company/tesora-france" target="_blank">Linkedin</a><u></u><u></u></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><b>De :</b> Tim Salabim <<a href="mailto:tim.appelhans@gmail.com" target="_blank">tim.appelhans@gmail.com</a>> <br>
<b>Envoyé :</b> mardi 9 juillet 2019 15:14<br>
<b>À :</b> Benjamin Pauget <<a href="mailto:benjamin.pauget@tesora.fr" target="_blank">benjamin.pauget@tesora.fr</a>><br>
<b>Cc :</b> <a href="mailto:r-sig-geo@r-project.org" target="_blank">r-sig-geo@r-project.org</a><br>
<b>Objet :</b> Re: [R-sig-Geo] geoJSON and leaflet<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Hi Benjamin,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">What you get back from the jsonlite::fromJSON() call is a simplified list with the data (including the geometry information) as a data frame in one of the list slots. GeoJson is usually a character string. Therefore, if you open your map
 in the browser and open the console (Ctrl + i) you will see the error message: "Invalid GeoJson object".
<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I am no expert on geojson structure, but it seems that the data that you request is not in standard format. I tried a few different ways of parsing the data to a valid GeoJson string but did not have success. Maybe someone else with more
 insight has some helpful ideas how to achieve this.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">However, I found a workaround to get the polygons shown on the map using library(sf) - see code below. Note, this only visualises the geometry information only, so direct popup queries via "~" are not possible.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">library(leaflet)<br>
library(jsonlite)<br>
library(sf)<br>
<br>
url <- "<a href="http://www.georisques.gouv.fr/api/v1/sis?rayon=1000&latlon=4.854899%2C%2045.763079&page=1&page_size=10" target="_blank">http://www.georisques.gouv.fr/api/v1/sis?rayon=1000&latlon=4.854899%2C%2045.763079&page=1&page_size=10</a>"<br>
<br>
geojson <- jsonlite::fromJSON(url)<br>
<br>
# convert coordinate arrays to matrices<br>
geom = lapply(geojson$data$geom$coordinates, matrix, ncol = 2)<br>
# create multipolygon from coordinate matrices<br>
geom = st_cast(st_polygon(geom), "MULTIPOLYGON")<br>
<br>
leaflet() %>%<br>
  addTiles()%>%<br>
  setView(lng = 4.854899, lat = 45.763079, zoom = 14) %>%<br>
  addMarkers(lng = 4.872536, lat = 45.758321)%>%<br>
  addPolygons(data = geom)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">HTH,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Tim<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Tue, Jul 9, 2019 at 1:49 PM Benjamin Pauget <<a href="mailto:benjamin.pauget@tesora.fr" target="_blank">benjamin.pauget@tesora.fr</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-color:currentcolor currentcolor currentcolor rgb(204,204,204);border-style:none none none solid;border-width:medium medium medium 1pt;padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal">Hi,
<u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">I’m writting because I have some trouble with a geoJSON file and a leaflet.</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">I’m trying to display polygon on a leaflet map, but nothing append
</span><span style="font-family:"Segoe UI Emoji",sans-serif" lang="EN-US">☹</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">I have no error message.</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">Do you have some advice/ideas?</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">Best regards</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">Here is my code :</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">library(leaflet)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">library(jsonlite)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">url <- "<a href="http://www.georisques.gouv.fr/api/v1/sis?rayon=1000&latlon=4.854899%2C%2045.763079&page=1&page_size=10" target="_blank">http://www.georisques.gouv.fr/api/v1/sis?rayon=1000&latlon=4.854899%2C%2045.763079&page=1&page_size=10</a>"</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">geojson <- jsonlite::fromJSON(url)</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">leaflet() %>%
</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">  addTiles()%>%</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">  setView(lng = 4.854899, lat = 45.763079, zoom = 14) %>%</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">  addMarkers(lng = 4.872536, lat = 45.758321)%>%</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">  addGeoJSON(geojson) # doesn’t work by using geojson$data or geojson$data$geom</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p>
<table class="gmail-m_1072751641916935796MsoNormalTable" style="width:130.7pt;border-collapse:collapse" width="174" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td colspan="2" style="width:130.7pt;padding:0cm 5.4pt" width="174" valign="top">
<p class="MsoNormal"><b><span style="font-size:9pt;font-family:"Tahoma",sans-serif;color:rgb(0,59,106)">Benjamin PAUGET</span></b><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:9pt;font-family:"Tahoma",sans-serif;color:rgb(0,59,106)">Responsable R&D</span><u></u><u></u></p>
</td>
</tr>
<tr style="height:1.65pt">
<td colspan="2" style="width:130.7pt;padding:0cm 5.4pt;height:1.65pt" width="174" valign="bottom">
<p class="MsoNormal"><img style="width: 1.6666in; height: 0.4687in;" id="gmail-m_1072751641916935796gmail-m_6642306663767855667Image_x0020_17" src="cid:16bd71a2a854cff311" alt="cid:image005.png@01D4F3BB.3531D840" width="160" height="45" border="0"><u></u><u></u></p>
</td>
</tr>
<tr style="height:2.85pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:2.85pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:2pt;font-family:"Tahoma",sans-serif"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif">+33 (0)1 81 94 13 70</span><u></u><u></u></p>
</td>
<td rowspan="2" style="width:35.4pt;padding:0cm 5.4pt;height:2.85pt" width="47" valign="bottom">
</td>
</tr>
<tr style="height:1.4pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:1.4pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif">+33 (0)6 47 01 85 92</span><u></u><u></u></p>
</td>
</tr>
<tr style="height:1.4pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:1.4pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif">Le Visium</span><u></u><u></u></p>
</td>
<td rowspan="2" style="width:35.4pt;padding:0cm 5.4pt;height:1.4pt" width="47" valign="bottom">
</td>
</tr>
<tr style="height:1.4pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:1.4pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif">22 Av Aristide Briand</span><u></u><u></u></p>
</td>
</tr>
<tr style="height:1.4pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:1.4pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif">94110 ARCUEIL</span><u></u><u></u></p>
</td>
<td rowspan="2" style="width:35.4pt;padding:0cm 5.4pt;height:1.4pt" width="47" valign="bottom">
</td>
</tr>
<tr style="height:1.4pt">
<td style="width:95.3pt;padding:0cm 5.4pt;height:1.4pt" width="127" valign="top">
<p class="MsoNormal"><span style="font-size:8.5pt"><a href="https://tesora.fr/" target="_blank"><span style="font-family:"Tahoma",sans-serif">https://tesora.fr/</span></a></span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:8.5pt;font-family:"Tahoma",sans-serif"><a href="https://www.linkedin.com/company/tesora-france" target="_blank">Linkedin</a></span><u></u><u></u></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
R-sig-Geo mailing list<br>
<a href="mailto:R-sig-Geo@r-project.org" target="_blank">R-sig-Geo@r-project.org</a><br>
<a href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo" target="_blank">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>

</blockquote></div>