-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error Reading Shapefile with st_read since version 1.09... #2046
Comments
The features seem to be line strings, which for the sp class drops any Z-dimension. There is no Which of these oddities in the very broken shapefile causes problems is unknown. terra says:
so does not try to access the Z dimension. My guess would be that sf is now trying harder (or GDAL is trying harder, I'm using GDAL 3.6.0, the GDAL version you are using should be reported) to pick up inconsistencies. Please convert to GPKG and add a relevant CRS. |
Hi Roger, I'm using "3.5.2" of GDAL - have updated original message to make my set-up visible. These files were not generated by me and I'm no expert with Shapefiles. Any advice on tools to convert this shapefile to a geopackage, preferably with R? |
|
Thanks for the pointers Roger - will investigate and get back to you. |
In this case the shapefile is declared as
So I guess that the Z dimension is non-operative. In the attribute data, I see DocType is DXF for all features, suggesting that the spurious Z is coming from the example file having been converted at some point from AutoCAD. So If the indications in the attribute data "Bishop's Stortford" indicate a site close to Stanstead airport, the CRS might be EPSG:27700, but that ends up in a field, so maybe a local surveying CRS was used. terra can read the file and can save it as a 2D GPKG, but a valid CRS would be very useful to be able to place the lines on a contextual map. |
Roger, You are correct - the shapefile was generated from aAutoCAD . When I read the Shapefile via terra and then write to a new Shapefile - the resulting shapefile can then be readin via the sf:st_read function:
This will serve as a temporary fix for me - but I will look in to this in more detail to avoid such issues arising again in the future,. |
@WayneGitShell, you can also try to write these files without Z dimension using gdal_utils(util = "vectortranslate",
source = "GWSDATex2.shp",
destination = "test.shp",
options = c("-dim", "XY")) |
I tried using QGIS to export the shapefile to GeoPackage (.gpkg) and then imported it, and it worked perfectly fine. At least a temporary solution, I guess. |
I ran into this issue today too, for a .shp file that I previously had no trouble reading with |
@aaronschiff Did |
@rsbivand yes, I did get those messages from |
We have the same issue. Would be happy with a workaround that didn't involve deprecated libraries. Do indeed receive "Z-dimension discarded" for the shapefile at https://github.com/IMERSS/maxwell/tree/main/spatial_data/vectors/Shp_files/Watershed_CRD which was exported from QGIS. |
@amb26, did you try to save geometry without Z dimension (#2046 (comment))? |
Thanks, that is fine, but not an effective workaround - we need to work with the shapefiles as provided, so I would appreciate a scheme to handle this within R without the use of deprecated libraries or hitting the filesystem again. |
So read with Tell your upstream data provider to leave ESRI Shapefile in the last century where it belongs. GeoPackage is the choice for this century. Their malformed files state that three dimensions are provided then fail to provide them. In rgdal the workaround was to read all the geometries checking each for the correct # dimensions, go for 2D if some were 2D, and re-read all the geometries. With larger data sets now, re-reading the geometries is a waste of time, but because the format itself doesn't enforce 3D if declared 3D, we are stuck for this driver.
Type 15 is |
This also happens in GeoJSON files, see #1592; this fix should close the problem, read the mixes, then library(sf)
# Linking to GEOS 3.11.1, GDAL 3.6.1, PROJ 9.1.1; sf_use_s2() is TRUE
read_sf("Wastersheds_CRD.shp")
# Simple feature collection with 136 features and 30 fields
# Geometry type: MULTIPOLYGON
# Dimension: XY, XYZ
# Bounding box: xmin: 455935 ymin: 5395725 xmax: 473082.9 ymax: 5421613
# z_range: zmin: 0 zmax: 0
# Projected CRS: NAD83 / UTM zone 10N
# # A tibble: 136 × 31
# fid OBJECTID Subtype LifeCycleS Name AliasNa…¹ Alias…² Strea…³ ID CRDID
# <dbl> <dbl> <dbl> <chr> <chr> <chr> <chr> <dbl> <chr> <chr>
# 1 1 1 1 ACT <NA> <NA> <NA> NA TEMP… 11693
# 2 2 2 3 ACT <NA> <NA> <NA> NA TEMP… 11701
# 3 3 724 1 ACT <NA> <NA> <NA> NA TEMP… 11508
# 4 4 1021 3 ACT <NA> <NA> <NA> NA TEMP… 11780
# 5 5 1042 3 ACT <NA> <NA> <NA> NA TEMP… 11776
# 6 6 1074 3 ACT <NA> <NA> <NA> NA TEMP… 11716
# 7 7 1076 3 ACT <NA> <NA> <NA> NA 8369 11719
# 8 8 1112 3 ACT <NA> <NA> <NA> NA TEMP… 11507
# 9 9 1128 3 ACT <NA> <NA> <NA> NA TEMP… 11468
# 10 10 1139 3 ACT <NA> <NA> <NA> NA TEMP… 11545
# # … with 126 more rows, 21 more variables: MgmtUnit <chr>, Comments <chr>,
# # DataSource <chr>, DataProjec <chr>, DataDate <chr>, DataSuppli <chr>,
# # DataAccura <chr>, DataCustod <chr>, MetadataCo <chr>, last_edite <chr>,
# # last_edi_1 <chr>, created_da <chr>, created_us <chr>, Text1 <chr>,
# # Text2 <chr>, Num1 <dbl>, Num2 <dbl>, CRDDischag <chr>, Shape.area <dbl>,
# # Shape.len <dbl>, geometry <MULTIPOLYGON [m]>, and abbreviated variable
# # names ¹AliasName1, ²AliasName2, ³StreamOrde
read_sf("Wastersheds_CRD.shp") |> st_zm()
# Simple feature collection with 136 features and 30 fields
# Geometry type: MULTIPOLYGON
# Dimension: XY
# Bounding box: xmin: 455935 ymin: 5395725 xmax: 473082.9 ymax: 5421613
# Projected CRS: NAD83 / UTM zone 10N
# # A tibble: 136 × 31
# fid OBJECTID Subtype LifeCycleS Name AliasNa…¹ Alias…² Strea…³ ID CRDID
# * <dbl> <dbl> <dbl> <chr> <chr> <chr> <chr> <dbl> <chr> <chr>
# 1 1 1 1 ACT <NA> <NA> <NA> NA TEMP… 11693
# 2 2 2 3 ACT <NA> <NA> <NA> NA TEMP… 11701
# 3 3 724 1 ACT <NA> <NA> <NA> NA TEMP… 11508
# 4 4 1021 3 ACT <NA> <NA> <NA> NA TEMP… 11780
# 5 5 1042 3 ACT <NA> <NA> <NA> NA TEMP… 11776
# 6 6 1074 3 ACT <NA> <NA> <NA> NA TEMP… 11716
# 7 7 1076 3 ACT <NA> <NA> <NA> NA 8369 11719
# 8 8 1112 3 ACT <NA> <NA> <NA> NA TEMP… 11507
# 9 9 1128 3 ACT <NA> <NA> <NA> NA TEMP… 11468
# 10 10 1139 3 ACT <NA> <NA> <NA> NA TEMP… 11545
# # … with 126 more rows, 21 more variables: MgmtUnit <chr>, Comments <chr>,
# # DataSource <chr>, DataProjec <chr>, DataDate <chr>, DataSuppli <chr>,
# # DataAccura <chr>, DataCustod <chr>, MetadataCo <chr>, last_edite <chr>,
# # last_edi_1 <chr>, created_da <chr>, created_us <chr>, Text1 <chr>,
# # Text2 <chr>, Num1 <dbl>, Num2 <dbl>, CRDDischag <chr>, Shape.area <dbl>,
# # Shape.len <dbl>, geometry <MULTIPOLYGON [m]>, and abbreviated variable
# # names ¹AliasName1, ²AliasName2, ³StreamOrde |
Description
As part of the GWSDAT R package - see www.gwsdat.net we ship out an example data set with a shapefile located here:
https://github.com/WayneGitShell/GWSDAT/tree/master/data/GIS_Files
To Reproduce
Has been working fine for all previous versions. Nothing in the news to suggest this change of behaviour.
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8 LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.utf8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] sf_1.0-9
loaded via a namespace (and not attached):
[1] compiler_4.2.2 magrittr_2.0.3 class_7.3-20 tools_4.2.2 DBI_1.1.3 units_0.8-0 proxy_0.4-27 Rcpp_1.0.9 KernSmooth_2.23-20
[10] grid_4.2.2 e1071_1.7-12 classInt_0.4-8
Paste the output of your
sessionInfo()
andsf::sf_extSoftVersion()
sf::sf_extSoftVersion()
GEOS GDAL proj.4 GDAL_with_GEOS USE_PROJ_H PROJ
"3.9.3" "3.5.2" "8.2.1" "true" "true" "8.2.1"
The text was updated successfully, but these errors were encountered: