Re: [R-sig-Geo] using mapview to plot raster with integer values

2021-11-12 Thread Tim Salabim
Hi Paolo,
I am assuming the raster is being warped/projected upon rendering. By
default we use 'bilinear' resampling.

2 possible solutions:

1) set the method for projecting with mapview(rst, method = "ngb") for
nearest-neighbor resampling
2) set mapview(rst, native.crs = TRUE) so that the raster does not get
projected and hence not resampled (though you'll lose the background
maps).

HTH
Tim

On Fri, Nov 12, 2021 at 2:10 PM Paulo Flores Ribeiro
 wrote:
>
> I'm trying to plot a raster where pixels can only assume integer values
> 1, 2 or 3, identifying 3 land use classes. The map does fine when
> plotted with the base r function: plot(rastername). However, I would
> like to use mapview (or another package for interactive maps) but it
> creates pixels with non-integer values on transition boundaries between
> classes (eg between classes 1 and 2 it creates a transition zone with
> some pixels assuming non-integer values 1.2033, 1.4221, 1.7119, etc.).
> Any way to avoid this? Thanks in advance, PauloFR
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] How to change scale labeling in spplot

2020-08-10 Thread Tim Salabim
Have you tried
colorkey=list(labels = list(labels = list("Af","Am","Aw")))
?



On Mon, Aug 10, 2020, 22:01 Thomas Adams  wrote:

> Hi all,
>
> I have searched for examples to change the labeling for raster data (two
> panels) consisting of integer values (1, 2, and 3). In the scale I want to
> label these as "Af", "Am", Aw".
>
> My code looks like:
>
> colp <- colorRampPalette(c("#96", "#FF", "#FF"))
> brks<-seq(0,3,1)
>
> spplot(KG_haiti,xlim=c(-8313027,-7959668),ylim=c(2017552,2297053),at=brks,col.regions=colp(length(brks)-1),ylab="Climate
> Class",main="Koppen-Geiger Climate Classification for\nClimate Years
> 1981-2010 and El Nino Years",names.attr=c("Climate Normal","El
> Nino"),colorkey=list(labels = list(labels = c("Af","Am","Aw"
>
> I'm getting just the 3 colors, but the labels "Af", "Am", Aw" are repeated
> across each color; I need to have each color associated with just one of
> the labels. Obviously, I'm doing something wrong...
>
> I just cannot figure out how to do this.
>
> Regards,
> Tom
>
> [[alternative HTML version deleted]]
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] New GDAL multi-dimensional array support?

2020-06-26 Thread Tim Salabim
Somewhat related , but Dirk Edelbüttel just released an R package to
interact with tiledb for storing spatiotemporal data as arrays (I believe
very similar in structure to what stars objects are). Tiledb also has a
gdal driver, so should play rather nicely with stars/sf/...

On Fri, Jun 26, 2020, 19:07 Edzer Pebesma 
wrote:

> Good thinking! I was thinking of making this available in the context of
> stars, which has multidimensional arrays (data cubes/hypercubes) as its
> target data type.
>
> Many regards,
>
> On 6/26/20 4:36 PM, H. Joe Lee wrote:
> >  Hi,
> >
> >
> >   My name is H. Joe Lee who maintains a rgdal website [0] to help rgdal
> > users to access NASA Earthdata easily.
> >
> >
> >   Recently, GDAL 3.1.0 added a multi-dimensional raster model [1] and two
> > new command line interface tools - gdalmdiminfo & gdalmdimtranslate. They
> > significantly increase the usability of NASA Earthdata in HDF like MOD35
> > product [2] by allowing users to subset and transpose data easily.
> >
> >
> >
> >   Thus, I'm wondering if rgdal development team can provide functions
> that
> > utilize new GDAL multi-dimensional APIs and tools that support [1] in the
> > future release.
> >
> >
> >   Sincerely,
> >
> >
> >
> > [0] https://hdfeos.org/software/r.php
> > 
> >
> > [1]
> >
> https://gdal.org/user/multidim_raster_data_model.html#multidim-raster-data-model
> >
> >
> > [2] https://hdfeos.org/zoo/LAADS_MOD_py.php
> >
> >
> > --
> > Datafy everything in HDF for faster AI.
> >
> >   [[alternative HTML version deleted]]
> >
> > ___
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
> --
> Edzer Pebesma
> Institute for Geoinformatics
> Heisenbergstrasse 2, 48149 Muenster, Germany
> Phone: +49 251 8333081
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Error when saving an sf (data) object to file as a shapefile

2020-06-20 Thread Tim Salabim
And for anyone looking for arguments:

http://switchfromshapefile.org/


On Sat, Jun 20, 2020, 18:20 Edzer Pebesma 
wrote:

>
>
> On 6/20/20 12:28 PM, Lom Navanyo wrote:
> > Unknown field name `Act_Depthtwtr': updating a layer with improper field
> > name(s)?
>
> Shapefiles have funny restrictions as to the length and form of variable
> names, you probably ran into that, as the message suggests.
>
> A general advice is to not use shapefiles for writing; there are better
> alternatives, geopackage comes to mind. Shapefiles make life unnecessary
> complicated, you've now run into two of the many problems they have. The
> days of creating shapefiles are over. If someone asks you to create
> shapfiles, explain them it is a bad idea.
> --
> Edzer Pebesma
> Institute for Geoinformatics
> Heisenbergstrasse 2, 48149 Muenster, Germany
> Phone: +49 251 8333081
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Fwd: [Spatial-Ecology] Gecomputation web-seminars (GDAL, PKTOOLS, GRASS, HPC)

2020-04-30 Thread Tim Salabim
See below for a set of online courses that might be interesting for some of
this lists subscribers.

Best
Tim

-- Forwarded message -
From: Giuseppe Amatulli 
Date: Thu, Apr 30, 2020, 17:49
Subject: [Spatial-Ecology] Gecomputation web-seminars (GDAL, PKTOOLS,
GRASS, HPC)
To: 


Dear Colleagues,

During the second week of May (Eastern Daylight Time), I will be teaching 4
web-seminars for enhancing *gecomputation skills to process large
geographic data*.
Each of these seminars will be held in both *English* and *Spanish*.
Participants will be given access to a cloud-based Linux virtual machine
that can be reached via an SSH tunnel.
Online free registration is provided below or in this hyperlink

.
Please distribute the details of these seminars among your colleagues and
students.

Sincerely
Giuseppe Amatulli, Ph.D.

Research scientist at
School of Forestry & Environmental Studies
Center for Research Computing
Yale University
Teaching: http://spatial-ecology.net
Work:  https://environment.yale.edu/profile/giuseppe-amatulli/
To view this email as a web page, go here.

[image: Yale Center for Research Computing]

Raster/Vector Processing using GDAL/OGR

may 11, 2020
9:00 - 11:30 AM EDT (IN ENGLISH, via zoom)
1:00 - 3:30 PM EDT (En Español, via zoom)

The workshop covers geo-data processing tasks: cropping and re-projecting,
mosaicing, and filtering images, and how to script processes for complex
geo-functions.
REGISTER

[image: Globe with GDAL logo]
Image Processing using Pktools

may 12, 2020
9:00 - 11:30 AM EDT (IN ENGLISH, Via Zoom)
1:00 - 3:30 PM EDT (En español, Via Zoom)
This workshop will focus on Processing Kernel for geospatial data (Pktools)
to perform remote sensing image analysis. The workshop will include
examples of mosaicing, filtering, histogram, masking, and raster
re-classification.
REGISTER

[image: Globe with Pktools logo]
Introduction to GRASS GIS

may 13, 2020
9:00 - 11:30 AM EDT (IN ENGLISH, Zoom)
1:00 - 3:30 PM EDT (En español, Via Zoom)
This workshop introduces students to the powerful GRASS GIS software to
manipulate raster and vector data, and covers using the graphical user
interface and simple Bash scripts to automate many common geo-data
processing tasks such as cropping and re-projecting images, and how to
script processes for complex geo-functions.
REGISTER

[image: Globe with GRASS logo]
GeoComputation with High Performance Computing

may 14, 2020
9:00 - 11:30 AM EDT (IN ENGLISH, Zoom)
1:00 - 3:30 PM EDT (En español, Via Zoom)
This workshop introduces students to perform Geocomputation analysis in
High Performance Computing (HPC) that use the Slurm queuing system. Using
simple Bash scripts, we will show four main ways to tile an image, perform
a filter operation and reassemble back the image.
REGISTER

[image: Globe with Bash logo]

[image: Yale University]

Yale Center for Research Computing: research.comput...@yale.edu.
Copyright © 2020 Yale University • All rights reserved
[image: Twitter]

Twitter

Re: [R-sig-Geo] viewing locally hosted mbtiles vector tiles using leaflet.mapboxgl?

2020-03-11 Thread Tim Salabim
Hi Nevil,
while not being able to help with mbtiles, maybe you want to try
leafgl to view your polygons.

https://github.com/r-spatial/leafgl

It should have no problems with 40k polygons.

Regarding RStudio's leaflet.mapboxgl, I don't think it is intended for
local use (though I might be wrong). For using locally stored tiles, I
think we would need something like
https://gitlab.com/IvanSanchez/Leaflet.TileLayer.MBTiles.

Out of interest, are you using tippercanoe from your command line or
do you have some code invoking it from R?

HTH,
Tim

On Wed, Mar 11, 2020 at 3:00 AM nevil amos  wrote:
>
> I am working on a shiny/ leaflet map project which requires display of a
> large polygon dataset  (40,000 polygons ~92MB sf object).
> Needless to say it take quite a time to render the sf object and zoom in
> and out.
>
> Simplifying the polygons is not an option.
>
> leaflet.mapboxgl  https://github.com/rstudio/leaflet.mapboxgl package
> allows adding of Mapbox GL layers to a leaflet map.
>
> Since I am using my own local tiles  there should be no need for a maxbox
> access token.
>
> If possible I would like to make use of leaflet.mapboxgl: addMapboxGL() to
> display vector tiles ( as .mbtiles) of the polygons that have been pre-
> rendered from the polygon dataset using tippecanoe
> https://github.com/mapbox/tippecanoe and served using mbtileserver
> https://github.com/consbio/mbtileserver all on the same local machine.
> mbtileserver is running from the project directory, and the mbtiles are  in
> the path: /tilesets/mytiles.mbtiles
> I can vie the preview in the bowser a
> http://localhost:8000/services/myTiles/map
>
> however the polygons do not dispay in leaflet in r
>
> As this requires use of tippecanoe and mbtileserver I cannot post a repro,
> however below is a pared down version fo the code I am using :
>
>
> library(leaflet)
> library(leaflet.mapboxgl)
>
> options(mapbox.accessToken=NA)
>
> base_map <- leaflet() %>%
>  setView(lng = 145,lat = -37,zoom = 7)%>%
>  addProviderTiles("Esri.WorldTopoMap", group = "ESRI Topo") %>%
>   addMapox http://localhost:8000/services/myTiles ")
>
> have I simply got the wrong format/ incomplete URL fo the  addMapboxGL ? If
> so what should it be?
>
> thanks
>
> [[alternative HTML version deleted]]
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] geoJSON and leaflet

2019-07-09 Thread Tim Salabim
Hi Benjamin,
please respond to the list as well. Other people may have similar issues
and this way we can find the solutions online.

If you want to extract the data along with the geometries, here's how you
could do it:

library(leaflet)
library(jsonlite)
library(sf)

url <- "
http://www.georisques.gouv.fr/api/v1/sis?rayon=1000=4.854899%2C%2045.763079=1_size=10
"

geojson <- jsonlite::fromJSON(url)

# convert coordinate arrays to matrices
geom = lapply(geojson$data$geom$coordinates, matrix, ncol = 2)
# create multipolygon from coordinate matrices
geom = lapply(geom, function(i) st_polygon(list(i)))
# overwrite the geom column of data in geojson
geojson$data$geom = st_sfc(geom, crs = 4326)
# exract data from geojson and turn into an sf object
dat = st_as_sf(geojson$data)

leaflet() %>%
  addTiles()%>%
  setView(lng = 4.854899, lat = 45.763079, zoom = 14) %>%
  addMarkers(lng = 4.872536, lat = 45.758321)%>%
  addPolygons(data = dat, popup = ~nom)

This way, as you can see, you can use the tilde (~) notation to include
popups referring to a column of the data.

I don't think that what you get using RSONIO is any closer to a valid
geojson.

Best
Tim

On Tue, Jul 9, 2019 at 3:28 PM Benjamin Pauget 
wrote:

> Dear Tim,
>
> Tanks you s much for your response !
>
> I am a beginner and working with geospatial is still unclear.
>
>
>
> I have tried to open my json file with “from_JSON” and I have another
> format of my data :
>
> url <- "
> http://www.georisques.gouv.fr/api/v1/sis?rayon=5000=4.854899%2C%2045.763079=1_size=10
> "
>
> geojson4 <- RJSONIO::fromJSON(url)
>
>
>
> Do you think this format is more relevant and will allow to display the
> pop’up info ?
>
>
>
> Thank you again for your code (I just pass the two last day on trying to
> display the polygons) !
>
>
>
> Best regards,
>
>
>
>
>
>
>
> *Benjamin PAUGET*
>
> Responsable R
>
> [image: cid:image005.png@01D4F3BB.3531D840]
>
>
>
> +33 (0)1 81 94 13 70
>
> +33 (0)6 47 01 85 92
>
> Le Visium
>
> 22 Av Aristide Briand
>
> 94110 ARCUEIL
>
> https://tesora.fr/
>
> Linkedin <https://www.linkedin.com/company/tesora-france>
>
>
>
>
>
> *De :* Tim Salabim 
> *Envoyé :* mardi 9 juillet 2019 15:14
> *À :* Benjamin Pauget 
> *Cc :* r-sig-geo@r-project.org
> *Objet :* Re: [R-sig-Geo] geoJSON and leaflet
>
>
>
> Hi Benjamin,
>
> 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".
>
>
>
> 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.
>
>
>
> 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.
>
>
>
> library(leaflet)
> library(jsonlite)
> library(sf)
>
> url <- "
> http://www.georisques.gouv.fr/api/v1/sis?rayon=1000=4.854899%2C%2045.763079=1_size=10
> "
>
> geojson <- jsonlite::fromJSON(url)
>
> # convert coordinate arrays to matrices
> geom = lapply(geojson$data$geom$coordinates, matrix, ncol = 2)
> # create multipolygon from coordinate matrices
> geom = st_cast(st_polygon(geom), "MULTIPOLYGON")
>
> leaflet() %>%
>   addTiles()%>%
>   setView(lng = 4.854899, lat = 45.763079, zoom = 14) %>%
>   addMarkers(lng = 4.872536, lat = 45.758321)%>%
>   addPolygons(data = geom)
>
>
>
> HTH,
>
> Tim
>
>
>
>
>
>
>
> On Tue, Jul 9, 2019 at 1:49 PM Benjamin Pauget 
> wrote:
>
> Hi,
>
> I’m writting because I have some trouble with a geoJSON file and a leaflet.
>
> I’m trying to display polygon on a leaflet map, but nothing append ☹
>
> I have no error message.
>
> Do you have some advice/ideas?
>
>
>
> Best regards
>
>
>
>
>
> Here is my code :
>
> library(leaflet)
>
> library(jsonlite)
>
> url <- "
> http://www.georisques.gouv.fr/api/v1/sis?rayon=1000=4.854899%2C%2045.763079=1_size=10
> "
>
> geojson <- jsonlite::fromJSON(url)
>
> leaflet() %>%
>
>   addTiles()%>%
&

Re: [R-sig-Geo] geoJSON and leaflet

2019-07-09 Thread Tim Salabim
Hi Benjamin,
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".

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.

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.

library(leaflet)
library(jsonlite)
library(sf)

url <- "
http://www.georisques.gouv.fr/api/v1/sis?rayon=1000=4.854899%2C%2045.763079=1_size=10
"

geojson <- jsonlite::fromJSON(url)

# convert coordinate arrays to matrices
geom = lapply(geojson$data$geom$coordinates, matrix, ncol = 2)
# create multipolygon from coordinate matrices
geom = st_cast(st_polygon(geom), "MULTIPOLYGON")

leaflet() %>%
  addTiles()%>%
  setView(lng = 4.854899, lat = 45.763079, zoom = 14) %>%
  addMarkers(lng = 4.872536, lat = 45.758321)%>%
  addPolygons(data = geom)

HTH,
Tim



On Tue, Jul 9, 2019 at 1:49 PM Benjamin Pauget 
wrote:

> Hi,
>
> I’m writting because I have some trouble with a geoJSON file and a leaflet.
>
> I’m trying to display polygon on a leaflet map, but nothing append ☹
>
> I have no error message.
>
> Do you have some advice/ideas?
>
>
>
> Best regards
>
>
>
>
>
> Here is my code :
>
> library(leaflet)
>
> library(jsonlite)
>
> url <- "
> http://www.georisques.gouv.fr/api/v1/sis?rayon=1000=4.854899%2C%2045.763079=1_size=10
> "
>
> geojson <- jsonlite::fromJSON(url)
>
> leaflet() %>%
>
>   addTiles()%>%
>
>   setView(lng = 4.854899, lat = 45.763079, zoom = 14) %>%
>
>   addMarkers(lng = 4.872536, lat = 45.758321)%>%
>
>   addGeoJSON(geojson) # doesn’t work by using geojson$data or
> geojson$data$geom
>
>
>
>
>
>
>
>
>
> *Benjamin PAUGET*
>
> Responsable R
>
> [image: cid:image005.png@01D4F3BB.3531D840]
>
>
>
> +33 (0)1 81 94 13 70
>
> +33 (0)6 47 01 85 92
>
> Le Visium
>
> 22 Av Aristide Briand
>
> 94110 ARCUEIL
>
> https://tesora.fr/
>
> Linkedin 
>
>
>
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo