[R-sig-Geo] Match European cities to Coordinates/NUTS 2
I have a dataframe (more than 50,000 observations), where one of the variables is the city that unit is location. The units are all in Europe. My goal is to assign NUTS-2 code to each of these cities. However, I am not aware of any direct way of achieving this, so I wanted to first assign coordinates to the cities and then use the 'over' function to match with NUTS regions from EU shapefile. I have tried to use 'geocode' from the ggmap package but there is a 2,500 per day limit. Is there any other solution? Any help will be greatly appreciated. Sincerely, Milu [[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] Raster to rasterbrick does not preserve Date/Time
Thank you, Ben! This works well. Sincerely, Milu On Sun, Nov 4, 2018 at 11:08 PM Ben Tupper wrote: > Hi, > > I'm not sure about reading the datetime stamp directly form the file, but > you have enough info to convert the z-value which is well described in your > ncdf. I'm not familiar with the '%.f' format specifier, but it looks like > it is a fractional day. Something like this perhaps will work? > > z <- raster::getZ(rbick) > z0 <- floor(z) > zf <- z - z0 > dt <- as.POSIXct(as.character(z0), format = "%Y%m%d") + 24*60*60*zf > rbrick <- raster::setZ(rbrick, z, name = 'datetime') > > You'll need to think through the timezone issues that might arise. > as.POSIXct() has arguments that can help you with that. > > Cheers, > Ben > > > > On Nov 4, 2018, at 12:39 PM, Miluji Sb wrote: > > > > Dear all, > > > > I have a raster with multiple variables and date/time information; > > > > time Size:17164 *** is unlimited *** > >standard_name: time > >bounds: time_bnds > >units: day as %Y%m%d.%f > >calendar: proleptic_gregorian > >bnds Size:2 > > > > My goal is to convert the raster file to rasterbrick for extraction > > purposes; > > > > rbrick <- brick(r, values=TRUE, varname="var1") > > > > However, after conversion - the date/time information is not preserved. > How > > can I preserve this information? > > > > class : RasterBrick > > dimensions : 600, 1440, 864000, 17164 (nrow, ncol, ncell, nlayers) > > resolution : 0.25, 0.25 (x, y) > > extent : -180, 180, -60, 90 (xmin, xmax, ymin, ymax) > > coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 > > data source : /work/ncfile.nc4 > > names : X19700101.4375, X19700102.4375, X19700103.4375, > > X19700104.4375, X19700105.4375, X19700106.4375, X19700107.4375, > > X19700108.4375, X19700109.4375, X19700110.4375, X19700111.4375, > > X19700112.4375, X19700113.4375, X19700114.4375, X19700115.4375, ... > > z-value : 19700101.4375, 20161231.4375 (min, max) > > varname : var1 > > > > Any help will be greatly appreciated! > > > > Sincerely, > > > > Milu > > > > [[alternative HTML version deleted]] > > > > ___ > > R-sig-Geo mailing list > > R-sig-Geo@r-project.org > > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > Ben Tupper > Bigelow Laboratory for Ocean Sciences > 60 Bigelow Drive, P.O. Box 380 > East Boothbay, Maine 04544 > http://www.bigelow.org > > Ecological Forecasting: https://eco.bigelow.org/ > > > > > > [[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] Reordering geographical coordinates clockwise to make a polygon
alphahull or a hand-crafted "triangulate and cull long/large triangles" might be workable options (geometry and RTriangle have the fastest and most useful triangulation functions). It's not generally a tractable problem afaics. Some refs that came up in recent discussions: https://pdfs.semanticscholar.org/669b/1415cd64d39f1e44fd90c2b9d9453c42581b.pdf http://erikdemaine.org/polygonization/ Cheers, Mike. On Tue, 6 Nov 2018 at 05:26 Edzer Pebesma wrote: > Sorry for my previous answer, I didn't get the question fully. > > I'm afraid I still don't get the question fully, but functions that > might help are sf::st_line_merge (creates a LINESTRING from line pieces) > and sf::st_polygonize (creates a polygon from a LINESTRING that forms a > closed ring) > > On 11/5/18 5:35 PM, Patrick Giraudoux wrote: > > > > Apologize to answer to myself: the way described below would work only > > if there are no concave "peninsula" towards north or south inside the > > polygon. Even thinking about an alternate solution, e.g. the Traveling > > Salesman Problem (TSP), ie. the shortest route linking all points, one > > could get wrong since points of a narrowpeninsula could have points > > closest to the opposite border than from the next point on the border... > > > > Suppose we are stuck, and should redraw polygons by hand > > > > > > Le 05/11/2018 à 14:02, Patrick Giraudoux a écrit : > >> > >> Dear listers, > >> > >> There is an interesting post here: > >> > https://stackoverflow.com/questions/6989100/sort-points-in-clockwise-order > >> dealing on the issue. However, I would like to know if a function has > >> been already developped in a R package. > >> > >> I am coping with a young colleague's shapefile where borders of > >> polygons have been drawn as lines quite inconsistently. To change this > >> SpatialLinesDataFrame into a SpatialPoints object is easy. The idea is > >> to select the points bordering each polygon (delete the others), > >> define the point set as a Polygon, then rebuild step by step a > >> SpatialPolygonsDataFrame with all its (~25) polygons. It would be much > >> quicker than to redraw one by one the 5160 data points (two times on > >> borders shared by two polygons). > >> > >> The problem is that the points must be reordered clockwise (the way > >> lines making the borders is all except clockwise) before making them > >> a polygon. > >> > >> Any function already developped for that ? > >> > >> Cheers, > >> > >> Patrick > >> > >> > >> > > > > > > [[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, 48151 Muenster, Germany > Phone: +49 251 8333081 <+49%20251%208333081> > ___ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Dr. Michael Sumner Software and Database Engineer Australian Antarctic Division 203 Channel Highway Kingston Tasmania 7050 Australia [[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] Reordering geographical coordinates clockwise to make a polygon
Sorry for my previous answer, I didn't get the question fully. I'm afraid I still don't get the question fully, but functions that might help are sf::st_line_merge (creates a LINESTRING from line pieces) and sf::st_polygonize (creates a polygon from a LINESTRING that forms a closed ring) On 11/5/18 5:35 PM, Patrick Giraudoux wrote: > > Apologize to answer to myself: the way described below would work only > if there are no concave "peninsula" towards north or south inside the > polygon. Even thinking about an alternate solution, e.g. the Traveling > Salesman Problem (TSP), ie. the shortest route linking all points, one > could get wrong since points of a narrowpeninsula could have points > closest to the opposite border than from the next point on the border... > > Suppose we are stuck, and should redraw polygons by hand > > > Le 05/11/2018 à 14:02, Patrick Giraudoux a écrit : >> >> Dear listers, >> >> There is an interesting post here: >> https://stackoverflow.com/questions/6989100/sort-points-in-clockwise-order >> dealing on the issue. However, I would like to know if a function has >> been already developped in a R package. >> >> I am coping with a young colleague's shapefile where borders of >> polygons have been drawn as lines quite inconsistently. To change this >> SpatialLinesDataFrame into a SpatialPoints object is easy. The idea is >> to select the points bordering each polygon (delete the others), >> define the point set as a Polygon, then rebuild step by step a >> SpatialPolygonsDataFrame with all its (~25) polygons. It would be much >> quicker than to redraw one by one the 5160 data points (two times on >> borders shared by two polygons). >> >> The problem is that the points must be reordered clockwise (the way >> lines making the borders is all except clockwise) before making them >> a polygon. >> >> Any function already developped for that ? >> >> Cheers, >> >> Patrick >> >> >> > > > [[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, 48151 Muenster, Germany Phone: +49 251 8333081 pEpkey.asc Description: application/pgp-keys ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Re: [R-sig-Geo] Reordering geographical coordinates clockwise to make a polygon
Apologize to answer to myself: the way described below would work only if there are no concave "peninsula" towards north or south inside the polygon. Even thinking about an alternate solution, e.g. the Traveling Salesman Problem (TSP), ie. the shortest route linking all points, one could get wrong since points of a narrowpeninsula could have points closest to the opposite border than from the next point on the border... Suppose we are stuck, and should redraw polygons by hand Le 05/11/2018 à 14:02, Patrick Giraudoux a écrit : > > Dear listers, > > There is an interesting post here: > https://stackoverflow.com/questions/6989100/sort-points-in-clockwise-order > dealing on the issue. However, I would like to know if a function has > been already developped in a R package. > > I am coping with a young colleague's shapefile where borders of > polygons have been drawn as lines quite inconsistently. To change this > SpatialLinesDataFrame into a SpatialPoints object is easy. The idea is > to select the points bordering each polygon (delete the others), > define the point set as a Polygon, then rebuild step by step a > SpatialPolygonsDataFrame with all its (~25) polygons. It would be much > quicker than to redraw one by one the 5160 data points (two times on > borders shared by two polygons). > > The problem is that the points must be reordered clockwise (the way > lines making the borders is all except clockwise) before making them > a polygon. > > Any function already developped for that ? > > Cheers, > > Patrick > > > [[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] Reordering geographical coordinates clockwise to make a polygon
Look for argument check_ring_dir in the documentation of sf::st_read. On 11/5/18 2:02 PM, Patrick Giraudoux wrote: > Dear listers, > > There is an interesting post here: > https://stackoverflow.com/questions/6989100/sort-points-in-clockwise-order > dealing on the issue. However, I would like to know if a function has > been already developped in a R package. > > I am coping with a young colleague's shapefile where borders of polygons > have been drawn as lines quite inconsistently. To change this > SpatialLinesDataFrame into a SpatialPoints object is easy. The idea is > to select the points bordering each polygon (delete the others), > define the point set as a Polygon, then rebuild step by step a > SpatialPolygonsDataFrame with all its (~25) polygons. It would be much > quicker than to redraw one by one the 5160 data points (two times on > borders shared by two polygons). > > The problem is that the points must be reordered clockwise (the way > lines making the borders is all except clockwise) before making them a > polygon. > > Any function already developped for that ? > > Cheers, > > Patrick > > > > > [[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, 48151 Muenster, Germany Phone: +49 251 8333081 pEpkey.asc Description: application/pgp-keys ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[R-sig-Geo] Reordering geographical coordinates clockwise to make a polygon
Dear listers, There is an interesting post here: https://stackoverflow.com/questions/6989100/sort-points-in-clockwise-order dealing on the issue. However, I would like to know if a function has been already developped in a R package. I am coping with a young colleague's shapefile where borders of polygons have been drawn as lines quite inconsistently. To change this SpatialLinesDataFrame into a SpatialPoints object is easy. The idea is to select the points bordering each polygon (delete the others), define the point set as a Polygon, then rebuild step by step a SpatialPolygonsDataFrame with all its (~25) polygons. It would be much quicker than to redraw one by one the 5160 data points (two times on borders shared by two polygons). The problem is that the points must be reordered clockwise (the way lines making the borders is all except clockwise) before making them a polygon. Any function already developped for that ? Cheers, Patrick [[alternative HTML version deleted]] ___ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo