[R-sig-Geo] st_area / st_transform / crs

Edzer Pebesma edzer.pebesma at uni-muenster.de
Sat Sep 16 14:19:38 CEST 2017



On 16/09/17 13:52, Jean-Luc Dupouey wrote:
> Dear all,
> 
> I am a new user of sf. I have the following error:
> 
> "lay" is an sf object, composed of POLYGONS and MULTIPOLYGONS in a
> projected coordinates system.
> 
>> st_area(lay)  # works well and returns the area of polygons
> 
>> # convert to WGS
>> laywgs = st_transform(lay, 4326)
> 
>> st_area(laywgs)
> Error in as_Spatial(from) :
>   conversion from feature type sfc_GEOMETRY to sp is not supported
> 
> Why st_area works on the projected layer and not on the
> latitude/longitude layer? I read carefully the manual and did not find
> any clue. It is just told that for unprojected geometries, st_area uses
> areaPolygon. Well... it means that some conversion probably takes place,
> but there is no information about this conversion.

If you then would read the documentation of geosphere::areaPolygon, you
can read that it needs sp objects as its input; sf converts to Spatial
(sp), then calls areaPolygon on that object.

try

laywgs = st_transform(st_cast(lay, "MULTIPOLYGON"), 4326)

to make this conversion less painful.

> 
> Thank you advance for your help,

Thanks for bringing this up - I understand it is confusing, and we might
be able to make this simpler from the sf side.

> 
> Jean-Luc Dupouey
> 

-- 
Edzer Pebesma
Institute for Geoinformatics  (ifgi),  University of Münster
Heisenbergstraße 2, 48149 Münster, Germany; +49 251 83 33081
Journal of Statistical Software:   http://www.jstatsoft.org/
Computers & Geosciences:   http://elsevier.com/locate/cageo/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20170916/b0ffbe37/attachment.sig>


More information about the R-sig-Geo mailing list