R load shapefile: "Error in plot.window(...) : need finite 'ylim' values"

Philip

I've created the following script to get the coastline of Denmark

# Get Shapefiles for Coastline
shpurl <- "http://download.geofabrik.de/europe/denmark-latest.shp.zip"
tmp <- tempfile(fileext=".zip")
download.file(shpurl, destfile = tmp)
files <- unzip(tmp, exdir=getwd())

# Load & plot shapefile
library(maptools)
shp <- readShapePoly(files[grep(".shp$", shpurl)])
plot(shp)

This should give me the outline of Denmark, however, I keep getting the following error:

Error in plot.window(...) : need finite 'ylim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

Any help or directions is appreciated.

Konrad

Have a look at your files value:

> length(files)
[1] 41

The files you are downloading have number of shape files for various geographies. For instance the code:

require(rgdal)
shp <- readOGR(dsn = "whereIsavedyourStuff/Stacks", layer = "roads")

will execute properly. But you will need to specify, which of the sourced shape files you want to read.


As a side point, with respect to reading files from the net, I would suggest that you have a look at this code:

# Download an read US state shapefiles
tmp_shps <- tempfile(); tmp_dir <- tempdir()
download.file("http://www2.census.gov/geo/tiger/GENZ2014/shp/cb_2014_us_state_20m.zip",
              tmp_shps)
unzip(tmp_shps, exdir = tmp_dir)

# Libs
require(rgdal)

# Read
us_shps <- readOGR(dsn = tmp_dir, layer = "cb_2014_us_state_20m")

Irrespectively, of what method to read shape files you decide to use you have to specify path and file name. In terms of the provided code in readOGR this is fulfilled by dns and layer options. In your code you used files[grep(".shp$", shpurl)], file names within your 195MB archive, do not corresponds to the URL. You have a few options here:

  1. You can download this files and unpack as you did, list names of all the files that are *.shp, take the file names and pass them in the loop to a list where you would read all combinations (in effect you need a number of files to read each layer)

  2. Better, specify the layer you want to read similarly to the code provided above.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

R: Gradient plot on a shapefile

分類Dev

Overlap (or convert) a raster in shapefile with R software

分類Dev

How to extract the data in a netcdf file based on a shapefile in R?

分類Dev

Load() function in R with an input

分類Dev

Convert Tables in Postgresql to Shapefile

分類Dev

Vertical lines in a polygon shapefile

分類Dev

How to save and load spline interpolation functions in R?

分類Dev

Use R package "googledrive" to load in R a file from my googledrive

分類Dev

Using ggplot to plot shapefile and gganimate for animation

分類Dev

Plot shapefile city borders on top of cartopy map

分類Dev

Subsetting NYC shapefile to Manhattan using Geopandas

分類Dev

Java converter from kml/shapefile to Geojson

分類Dev

RのArea.poly:Shapefileが「gpc.poly」ではなく「list」クラスに変換されるのはなぜですか?

分類Dev

How can I use the command "pwd" in R to load data?

分類Dev

Atom editor r-language error - Failed to load snippets

分類Dev

Display shapefile map on web browser using angular2

分類Dev

NetLogo GIS extension: How to create turtles according to location information in shapefile

分類Dev

Drop Pandas dataframe rows if geocoordinates outside country shapefile

分類Dev

Creating a whole new world with shapefile format of different layers in one file

分類Dev

PysalでShapefileを使用する方法

分類Dev

入力を使用したRのLoad()関数

分類Dev

OSError: cannot load library 'C:\Program Files\R\R-4.0.2\bin\x64\R.dll': error 0x7e

分類Dev

Add a relief (GEOtiff, .tif) to a ggplot of the swiss country borders ((polygon) shapefile, .shp)

分類Dev

HDFを地理参照ファイル(geotiff、shapefile)に変換する

分類Dev

dbf(shapefile)からの不正なテキスト

分類Dev

kml / shapefileからGeojsonへのJavaコンバーター

分類Dev

NetworkX-ShapefileからMultiDiGraphを作成する方法は?

分類Dev

Snap svg load inside load

分類Dev

Rで関数の引数[すなわちfunction(x)]をload()およびview()する方法

Related 関連記事

  1. 1

    R: Gradient plot on a shapefile

  2. 2

    Overlap (or convert) a raster in shapefile with R software

  3. 3

    How to extract the data in a netcdf file based on a shapefile in R?

  4. 4

    Load() function in R with an input

  5. 5

    Convert Tables in Postgresql to Shapefile

  6. 6

    Vertical lines in a polygon shapefile

  7. 7

    How to save and load spline interpolation functions in R?

  8. 8

    Use R package "googledrive" to load in R a file from my googledrive

  9. 9

    Using ggplot to plot shapefile and gganimate for animation

  10. 10

    Plot shapefile city borders on top of cartopy map

  11. 11

    Subsetting NYC shapefile to Manhattan using Geopandas

  12. 12

    Java converter from kml/shapefile to Geojson

  13. 13

    RのArea.poly:Shapefileが「gpc.poly」ではなく「list」クラスに変換されるのはなぜですか?

  14. 14

    How can I use the command "pwd" in R to load data?

  15. 15

    Atom editor r-language error - Failed to load snippets

  16. 16

    Display shapefile map on web browser using angular2

  17. 17

    NetLogo GIS extension: How to create turtles according to location information in shapefile

  18. 18

    Drop Pandas dataframe rows if geocoordinates outside country shapefile

  19. 19

    Creating a whole new world with shapefile format of different layers in one file

  20. 20

    PysalでShapefileを使用する方法

  21. 21

    入力を使用したRのLoad()関数

  22. 22

    OSError: cannot load library 'C:\Program Files\R\R-4.0.2\bin\x64\R.dll': error 0x7e

  23. 23

    Add a relief (GEOtiff, .tif) to a ggplot of the swiss country borders ((polygon) shapefile, .shp)

  24. 24

    HDFを地理参照ファイル(geotiff、shapefile)に変換する

  25. 25

    dbf(shapefile)からの不正なテキスト

  26. 26

    kml / shapefileからGeojsonへのJavaコンバーター

  27. 27

    NetworkX-ShapefileからMultiDiGraphを作成する方法は?

  28. 28

    Snap svg load inside load

  29. 29

    Rで関数の引数[すなわちfunction(x)]をload()およびview()する方法

ホットタグ

アーカイブ