-
Notifications
You must be signed in to change notification settings - Fork 301
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
Problem with MULTISURFACE sf object retrieved from geonode #748
Comments
Could you share at least a single sfg? I've never seen this type and don't know how to find examples. I've had good results with multipatch though, and guess this is similar but with triangulations rather than just flat patches? |
See 8162d66 ; example code: library(sf)
demo(nc)
pol = st_geometry(nc)[1:2]
class(pol) = c("XY", "MULTISURFACE", "sfg")
pol
try(st_cast(pol, "MULTIPOLYGON")) # fails!
st_cast(st_sfc(pol), "MULTIPOLYGON")
st_cast(st_sf(a = 1, st_sfc(pol)), "MULTIPOLYGON") library(sf)
# Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 4.9.3
demo(nc)
# demo(nc)
# ---- ~~
## this object was created as follows:
library(sf)
# nc = st_read(system.file("shapes/", package="maptools"), "sids")
# st_crs(nc) = 4267 # "+proj=longlat +ellps=clrk66" or "+proj=longlat +datum=NAD27"
# print(nc, n = 3)
# st_write(nc, "nc.gpkg", "nc.gpkg", driver = "GPKG")
# description of the dataset, see vignette in package spdep:
# https://cran.r-project.org/web/packages/spdep/vignettes/sids.pdf
datasource = { if ("GPKG" %in% st_drivers()$name)
system.file("gpkg/nc.gpkg", package="sf")
else
system.file("shape/nc.shp", package="sf")
}
agr = c(AREA = "aggregate", PERIMETER = "aggregate", CNTY_ = "identity",
CNTY_ID = "identity", NAME = "identity", FIPS = "identity", FIPSNO = "identity",
CRESS_ID = "identity", BIR74 = "aggregate", SID74 = "aggregate", NWBIR74 = "aggregate",
BIR79 = "aggregate", SID79 = "aggregate", NWBIR79 = "aggregate")
nc = st_read(datasource, agr = agr)
# Reading layer `nc.gpkg' from data source `/home/edzer/R/x86_64-pc-linux-gnu-library/3.4/sf/gpkg/nc.gpkg' using driver `GPKG'
# Simple feature collection with 100 features and 14 fields
# Attribute-geometry relationship: 0 constant, 8 aggregate, 6 identity
# geometry type: MULTIPOLYGON
# dimension: XY
# bbox: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
# epsg (SRID): 4267
# proj4string: +proj=longlat +datum=NAD27 +no_defs
pol = st_geometry(nc)[1:2]
class(pol) = c("XY", "MULTISURFACE", "sfg")
pol
# MULTISURFACE (MULTIPOLYGON (((-81.47276 36.23436, -81.54084 36.27251, -81.56198 36.27359, -81.63306 36.34069, -81.74107 36.39178, -81.69828 36.47178, -81.7028 36.51934, -81.67 36.58965, -81.3453 36.57286, -81.34754 36.53791, -81.32478 36.51368, -81.31332 36.4807, -81.26624 36.43721, -81.26284 36.40504, -81.24069 36.37942, -81.23989 36.36536, -81.26424 36.35241, -81.32899 36.3635, -81.36137 36.35316, -81.36569 36.33905, -81.35413 36.29972, -81.36745 36.2787, -81.40639 36.28505, -81.41233 36.26729, -81.43104 36.26072, -81.45289 36.23959, -81.47276 36.23436))), MULTIPOLYGON (((-81.23989 36.36536, -81.24069 36.37942, -81.26284 36.40504, -81.26624 36.43721, -81.31332 36.4807, -81.32478 36.51368, -81.34754 36.53791, -81.3453 36.57286, -80.90344 36.56521, -80.93355 36.49831, -80.96577 36.46722, -80.94967 36.41473, -80.95639 36.4038, -80.97795 36.39138, -80.98284 36.37183, -81.00278 36.36668, -81.02464 36.37783, -81.0428 36.41034, -81.08425 36.42992, -81.09856 36.43115, -81.11331 36.42285, -81.12938 36.42633, -81.1384 36.41763, -81.15337 36.42474, -81.17667 36.41544, -81.23989 36.36536))))
try(st_cast(pol, "MULTIPOLYGON")) # fails!
# OGR: Corrupt data
# Error in CPL_multisurface_to_multipolygon(structure(list(x), crs = NA_crs_, :
# OGR error
st_cast(st_sfc(pol), "MULTIPOLYGON")
# Geometry set for 2 features
# geometry type: MULTIPOLYGON
# dimension: XY
# bbox: xmin: -81.74107 ymin: 36.23436 xmax: -80.90344 ymax: 36.58965
# epsg (SRID): NA
# proj4string: NA
# MULTIPOLYGON (((-81.47276 36.23436, -81.54084 3...
# MULTIPOLYGON (((-81.23989 36.36536, -81.24069 3...
st_cast(st_sf(a = 1, st_sfc(pol)), "MULTIPOLYGON")
# Simple feature collection with 2 features and 1 field
# geometry type: MULTIPOLYGON
# dimension: XY
# bbox: xmin: -81.74107 ymin: 36.23436 xmax: -80.90344 ymax: 36.58965
# epsg (SRID): NA
# proj4string: NA
# a geometry
# 1 1 MULTIPOLYGON (((-81.47276 3...
# 2 1 MULTIPOLYGON (((-81.23989 3...
# Warning message:
# In st_cast.sf(st_sf(a = 1, st_sfc(pol)), "MULTIPOLYGON") :
# repeating attributes for all sub-geometries for which they may not be constant |
I will have to ask if I can share it.... "privacy" reasons, sorry. Do not know if this can help, but the WKT seems quite straightforward:
seems like a "regular" POLYGON, just with an additional "MULTISURFACE" prefix... |
Ah, this seems a bit more work: |
thanks for the reply. I will try that ASAP. |
So, many of these "exotics" are just special case GCs, any plain explanation anywhere? I'll revisit the docs to see, this is good information. Was it apparent already to others? |
unfortunately, the fix does not work, I figure due to the fact that my MULTISURFACE is a POLYGON. Line 28 in 8162d66
to: MULTISURFACE = 3 and using:
seems to work, though I fear it may break if the MULTISURFACE is a MULTIPOLYGON . BTW: here is a single geometry for testing:
|
Using the fact that st_cast(geom, "GEOMETRYCOLLECTION") %>% st_collection_extract("POLYGON") |
Indeed it works like a charm, both on Many thanks! |
@mdsumner : other exotics |
Understood, I just didn't realize about the GC analogs. Thanks! |
I've got something similar I guess:
This last line returns Error in which_sfc_col(from_cls) : st_cast for MULTISURFACE not supported. What I'm doing wrong? Should I change this line in |
This is a closed issue. However, look at |
Thanks! You've lead me to the trails. I used:
and
|
Hi,
I am currently trying to retrieve a POLYGON spatial object served by a geonode server, using something like:
(sorry, but I can not share the "real " address).
The problem is that the object is apparently retrieved correctly, but with a "MULTISURFACE" geometry type (in origin, before upload to geonode, it is a POLYGON):
, and many sf functions do not appear to work properly on MULTISURFACE (e.g.,
plot
, conversion tosp
).I tried to re-cast to POLYGON, but I got the following error:
, although the help of the function seems to suggest the existence of a method for that, and indeed it appears that the method exists here:
sf/R/cast_sfg.R
Line 202 in cd9acec
Is there an alternative way to easily convert the MULTISURFACE object to a geometry type more easily managed by
sf
?The text was updated successfully, but these errors were encountered: