st_area / st_transform / crs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

st_area / st_transform / crs

Jean-Luc Dupouey-2
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.

Thank you advance for your help,

Jean-Luc Dupouey

--
INRA
Forest Ecology and Ecophysiology Unit
F-54280 Champenoux
France

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: st_area / st_transform / crs

edzer


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/


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

signature.asc (484 bytes) Download Attachment