Skip to content

tpk files

5 messages · Roger Bivand, Marta Rufino, Barry Rowlingson

#
Hi Barry,

Thank you so much for your quik reply!
Yep, I tried that... after downloading, changing the name and decompressing
(it becomes 27GB), then I was not able to read it with r.
I will try again then.

Cheers,
M.

PS: now, it is giving me an error:

Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet,  :
  std::bad_alloc
In addition: Warning message:
In CPL_read_ogr(dsn, layer, query, as.character(options), quiet,  :
  GDAL Error 1: In GetNextRawFeature(): sqlite3_step() : disk I/O error
Barry Rowlingson <b.rowlingson at lancaster.ac.uk> escreveu no dia quinta,
11/04/2019 ?(s) 16:39:

  
    
#
Briefly, could you use the proxy interface in stars and subset without reading the whole object? I'm not able to check now, but if the data are raster layers, perhaps temporal, stars may be helpful.

Roger

Roger Bivand
Norwegian School of Economics
Bergen, Norway



Fra: Marta Rufino
Sendt: torsdag 11. april, 17.58
Emne: Re: [R-sig-Geo] tpk files
Til: Barry Rowlingson
Kopi: r-sig-geo


Hi Barry, Thank you so much for your quik reply! Yep, I tried that... after downloading, changing the name and decompressing (it becomes 27GB), then I was not able to read it with r. I will try again then. Cheers, M. PS: now, it is giving me an error: Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, : std::bad_alloc In addition: Warning message: In CPL_read_ogr(dsn, layer, query, as.character(options), quiet, : GDAL Error 1: In GetNextRawFeature(): sqlite3_step() : disk I/O error > Barry Rowlingson escreveu no dia quinta, 11/04/2019 ?(s) 16:39: > What did you try? The instructions at the top say: > > "Download 3.3GB tile package and rename extension from .tpk to .zip. > Extract to get EMU.gpkg" > > If that's a valid GeoPackage then `sf` should be able to read it. Not sure > what might be in the geopackage though, "tile package" sounds like rasters, > but GeoPackages are generally vector... > > I'll try in five minutes when all 3.3Gb have downloaded.... > > Barry > > > > > On Thu, Apr 11, 2019 at 3:37 PM Marta Rufino > wrote: > >> Hi, >> >> I would like to open (and use) a 'tpk' file from arcgis in r. >> For example: >> >> https://esri.maps.arcgis.com/home/item.html?id=24885cd6bd9544f5a8e15d0bf40f67d6 >> >> I tried raster and sf package, but no luck. >> >> Any ideia if we can do this in r? >> >> Thank you very much in advance, >> >> Best wishes, >> M. >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> R-sig-Geo mailing list >> R-sig-Geo at r-project.org >> https://stat.ethz.ch/mailman/listinfo/r-sig-geo >> > -- Marta M. Rufino (auxiliary researcher) *____________________________________________________*MARE - Marine and Environmental Sciences Centre Faculty of Sciences, University of Lisbon Campo Grande, 1749-016 Lisboa, Portugal Tel: + 351 21 750 00 00, extension: 22576 [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
1 day later
#
Hi,

Thank you all very much!
This list is amazing.

Barry proposed a way to do it using "SQLite3" (which I did not knew) and
then kindly send me the top layer as a cvs file. After, it is ok to open it
directly, either as a raster or sf (points). I managed that alright.
If anyone else is interested, please send me an email I can forward his
code (with his permission, of course).
Edzer, I will try that on Monday with a pc with available space, although
my smaller experiences already gave error working in the Mac.

Once I manage, I will add it to the rpub file after (
https://rpubs.com/MRufino/485396).

Now, the next issue will be how to transform the huge world wide sf points
(that are actually 32 classes) into a 'multipolygons' sf. Maybe I should do
a new post with a reproducible example for this new challenge, if I don't
manage (tried st_cast to LINESTRING and POLYGON and rasterToPolygons but no
luck).

So, thank you once again,
Good weekend,
Cheers,
M.
#
On Fri, Apr 12, 2019 at 6:16 PM Marta Rufino <marta.m.rufino at gmail.com>
wrote:
You might be able to polygonize the raster version of the data using
rasterToPolygons (it returns sp class polygons but they can be converted).

...yup - starting with the raster I constructed previously:

takes a couple of minutes....
Loading required namespace: rgeos
class       : SpatialPolygonsDataFrame
features    : 32
extent      : -180, 180, -78.5, 90  (xmin, xmax, ymin, ymax)
coord. ref. : NA
variables   : 1
names       : layer
min values  :     1
max values  :    32
and you'll have to run it yourself to see the results!

 Feel free to share my SQL scripts and other bits of code.

Barry

  
  
2 days later
#
Hi,

Finally, the full code that works
Thanks to everybody once again,

Cheers,
M.

# From Edzer Pebesma (thank you) - see also the alternative from Barry
using sqlite3
library(sf)
#open subset the file depth=1
system.time(r.d1 <- st_read("D:/EMU_Z_Opendata/EMU.gpkg", query = "select *
from EMU_Master where depth_lvl = 1"))

# Code chunks copied from below (adapted with the help of Barry Rowlingson):
require(dplyr)
dr <- r.d1 %>%
  dplyr::rename("x"=POINT_X,"y"=POINT_Y) %>%
  dplyr::mutate(NameEMUn = as.numeric(NameEMU)) %>%
  dplyr::select(x,y, NameEMUn) %>%
  st_set_geometry(NULL)

drz <- rasterFromXYZ(dr)
system.time(drzp <- rasterToPolygons(drz,dissolve=TRUE))
# spplot(drzp,"layer")

emu <- st_as_sf(drzp)
st_crs(emu)=4326
emu$NameEMU = levels(d$NameEMU)
plot(emu)
## Allright!!!
# Export as a shape file:
# write_sf(emu, "emu.shp")