Using tidycensus data from R in GeoDa

35 views
Skip to first unread message

Sarah Tran

unread,
Dec 1, 2022, 4:37:02 AM12/1/22
to Openspace List
Hi friends,

I am new to GeoDa. I've been analyzing and visualizing Census data in R, using the tidycensus package. This package provides "geometry" coordinates for mapping the shape of the geometric unit in R. I would like to bring this data into GeoDa for further analysis and creating visualizations. What is the best way to do this? 

What I've tried: exporting my R data into csv, xlsx and then importing into GeoDa does not work because GeoDa doesn't recognize the geometry vector. 

Any suggestions would be greatly appreciated. Thank you!
Sarah  

Nicolas Cadieux

unread,
Dec 1, 2022, 7:52:37 AM12/1/22
to openspa...@googlegroups.com
Hi,

Don’t know much about the tidycensus package format.  If it exports to csv, then I imagine the WKT geometry format is used.  If you can send a small sample of that csv, I could look at it. The easy way is to try to export directly to a geopackage or shapefile format, the later being universally read by any spatial software (GIS).  If geoda can’t read the WKT geometries (i’am not a big geoda user so I am unsure here), then the easy way is to import the csv in QGIS, then to create the geometries from the WKT format, and save to a shapefile and feed that to geoda.

Google WKT geometries and wiki and you will see if this is the case.  I could help more if I had a few lines of your database.


Le 1 déc. 2022 à 04:37, Sarah Tran <st....@gmail.com> a écrit :

Hi friends,
--
You received this message because you are subscribed to the Google Groups "Openspace List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openspace-lis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openspace-list/59089930-1ac9-4d55-87e5-a04f7754cc56n%40googlegroups.com.

Frank M. Howell

unread,
Dec 1, 2022, 7:56:54 AM12/1/22
to openspa...@googlegroups.com
Hi Sarah,

Check out Kyle Walker’s work, here:

Looks like writing to a shapefile is possible.

Frank

On Dec 1, 2022, at 3:37 AM, Sarah Tran <st....@gmail.com> wrote:

Hi friends,
--

Nicolas Cadieux

unread,
Dec 1, 2022, 8:30:28 AM12/1/22
to openspa...@googlegroups.com
Hi,

Thanks looks simple enough!  R has a bunch of spatial packages to read and write spatial data.  Keep in mind the .shp format will  create between 3 to 6 identically named files with various extensions.  Only the .shp file is “imported” or opened by the GIS software but they all need to be kept in the same folder as they are interconnected.  So if you move one file, you need to move them all of you risk loosing important information (like the database! .dbf).


Le 1 déc. 2022 à 07:56, Frank M. Howell <frankm...@gmail.com> a écrit :


Hi Sarah,

Check out Kyle Walker’s work, here:

Roger Bivand

unread,
Dec 1, 2022, 8:46:09 AM12/1/22
to openspa...@googlegroups.com
An alternative format that the R sf package can write and Geoda can read
is GPKG, GeoPackage: http://geodacenter.github.io/formats.html; only one
file is used, and it does not limit column/field names to 10 characters
like the ESRI Shapefile format. Also consider using the rgeoda R package.

An example of a workflow is described in the appendix of
https://doi.org/10.1111/gean.12319, with code at
https://github.com/rsbivand/gaSI21.

Roger
--
Roger Bivand
Emeritus Professor
Department of Economics, Norwegian School of Economics,
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway.
e-mail: Roger....@nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

Nicolas Cadieux

unread,
Dec 1, 2022, 8:57:23 PM12/1/22
to openspa...@googlegroups.com
Hi,

Nice to know.  Geopackages are also much faster, have a built in spatial index, support splines and don’t die if the file is bigger than a few GB just to name a few extra perks… it’s nice to know that it’s supported.


Le 1 déc. 2022 à 08:46, Roger Bivand <Roger....@nhh.no> a écrit :

An alternative format that the R sf package can write and Geoda can read is GPKG, GeoPackage: http://geodacenter.github.io/formats.html; only one file is used, and it does not limit column/field names to 10 characters like the ESRI Shapefile format. Also consider using the rgeoda R package.

Sarah Tran

unread,
Dec 14, 2022, 4:41:56 PM12/14/22
to Openspace List
Thank you so much to all those who took time to answer my question. This group is awesome! It was a quick fix, after all-- the sf library in R worked perfectly by allowing me to write geocoded data into a shp file to be successfully uploaded into GeoDa. Thank you Roger Bivand for the tip and resources on GPKG as an alternative to sf. 

Really appreciate your help! Wishing you a warm and celebratory holiday season.
Sarah
 
Reply all
Reply to author
Forward
0 new messages