Here's my experience FWIW:
1) Anything that pre joins data to the shape would be welcome. It's the #1 problem i seem to see on this forum.
2) Re-project to EPSG:4326 for Tableau maps, assumes a PRJ file in the SHP schema.
3) Simplify vertices for those limited by 32-bit
4) Support for inner ring polygon
Shapetotab already does 2+3 but not polyline, and I'm unsure about 4).
If this can be called directly from R as a CF (Tableau integrates with R) as a run-time routine: that would be awesome; perhaps you could parameterize the path and the export name.
The attached code now contains 3 functions: TabShapeRLines, TabShapeRPoints, TabShapeRPolygons. Each function deals only with the shapefile type indicates by its name.
For example, the following workbook was created using the data from this link: Read and write ESRI Shapefiles with R | NCEAS
Is this the type of polylines shapefile you meant?
In response to common issues:
1) This exports as a single file, so I believe this resolves the issue?
2) Yes, that would be useful. I'll look into that.
3) An interesting problem. I'll look into what sorts of algorithms exist in R already, but otherwise I might have other priorities...
4) I would have to use custom geocoding to accomplish this, at which point it would lose the user-friendly benefits that this provides. I could just delete inner polygons from the data, but otherwise I think that would be unsupported.
5) Personally, I don't see the benefit of being able to call these functions from within Tableau. The R-integration feature is good for sending data from Tableau to R, and then manipulating it in R. This is not what is happening here; all that is happening is exporting data from R to Tableau. If instead you wanted to manipulate the shapefiles based on data from Tableau (for instance, create a cartogram, which is my next project), then it would make sense. For this, I don't think it does. However, if you want to anyways, copy the code from the TabShapeR.R file into a file called Rserv.cfg, put some 'execute' statements before each library call and function definition, and place it in the same file as Rserve.dll.
I'll see about implementing the modifying projections thing, and then reply again with better instructions. If you have any other feedback, let me know.
TabShapeR.R.zip 770 bytes
This is outstanding work and I am grateful for your contribution, especially the polyline work.
Thanks a lot for describing the process and sharing the R codes.
I am currently working on showing the Wards (or precinct) Map for Wisconsin. I used your R codes to get the latitude -longitudes in csv format from the shapefiles for polygon.
I had initially used the 2002 Wards data and your code worked perfectly. But when I tried replicating it for the new 2012's Wards data, I am facing problem with latitude longitudes. They aren't coming correctly. I am not sure whether there is some problem with the data or something needs to be changed in your R code (I am not much familiar with R programming so don't know where to edit).
Can you please help me a little on this?
I have attached 2012 Wards data here which is downloaded from the link:Census 2010 Data
Wards_111312.zip 13.1 MB
Thanks for trying the code! I'm glad it worked for the one file.
Looking at the data in the Wards file, it looks like the map is projected. This means that the coordinates that my code ends up spitting out are not latitude and longitude, but projected latitude and longitude. I'll work on having the next iteration also adjust for projection, which should resolve this issue.
I'm a bit surprised that similar data from the same department was given with different projections, but I guess they could be compiled by different people and such. Normally there is a text file that comes with the shapefile that explains exactly what the file contains, who made it, how the data was collected, etc, and what projection is used. Is that somewhere else on the site and I just missed it? Without that file though, one way to check whether the file will make sense before importing the csv into Tableau is to type, "bbox(ShapeFile)" into the R console. This will tell you the bounding box of the shapefile imported. In this case, the bounding box was 294822.8, 773288.3, 225108.6, 734398.1. These don't look like standard latitude/longitude coordinates at all, so you know that the current code will fail to produce anything that Tableau can read.
Thanks Mary for looking into this file. You are correct, these doesn't look like standard latitude/longitude at all and I agree that there should be a file with the information about the data which would guide you to change the R code.
But unfortunately, even I am unaware of its location. I just clicked Wards at Bottom right to download this data..
Are you aware of any other source from where we can get the latest (2010) Wards data with correct latitude/longitude which Tableau can read?
You can always get a trial copy of ArcGIS Desktop, and use it to re-project your shapefile.
I just did it with a shapefile of municipal wards I got form Ottawa's open data portal.
Once you get ArcGIS installed, run ArcMap, cancel the "New Map" dialog and do the following:
1. Go to "Geoprocessing" in the menu
2. Select "Arc toolbox"
3. Go to "Data Management Tools/Projections and Transformations/Project"
4. Select your shapefile (note that you may need to "connect" to a local folder on your machine)
5. Specify the output location (by default it will add it to the default.gdb)
6. Specify the desired projection (search for "NAD 1983")
7. Run it (it takes a bit of time and a pop-up will come-up in the bottom right corner of the screen when it's done
If you ended-up with the newly projected data frame in the default.gdb, you can get it out to a regular shapefile by adding the newly projected data to a blank map, and then exporting it to a file by right-clicking the data layer.
Let me know if you have any problems with the above instructions and I'll do what I can to help.
Or you can just use the "save as" dialogue box in QGIS.
1 of 1 people found this helpful
I have updated it to deal with projected data. I have attached the Wards data, exported into Tableau in a normal lat/long format, although you probably don't need that...
It now functions a bit more slowly (it's using a different R package), and now takes 3 parameters instead of just 2:
Functions: TabShapeRPolygons, TabShapeRPoints, TabShapeRLines
Parameters: Path, ImportName, ExportName
Path: Directory with .shp, .shx, .dbf, and .prj if applicatble. Also where .csv will be written.
InportName: Apparently I can't spell? Name of import file, without .shp/.shx/ etc. Example: "Wards_111312"
ExportName: What you would like the .csv to be called. Example: "Wards" will be written as "Wards.csv"
Nice work, Mary!
Now, let's see some amazing examples using this script!
This is seriously cool stuff.
Hey The specified item was not found. - if ESRI Shapfiles & R scripts are your thing, you should check this out.:)
So I just can't get this to work. I've downloaded all the necessary packages (you might want to add the package dependencies into your instructions). I tried using the latest version.
I have a polyline SHP that I need: please find attached. If I can get the CSV's back in response, that would be great.
I've pre-joined the Seattle Street Name dB with the addresses, and also with the traffic counts. I can of course style this as a background layer, but I'd like to do the analysis in Tableau. It's all projected in EPSG:4326, so no problem there.
Seattlestreetnetwork.zip 5.9 MB
You are right, I forgot to include the rgdal package
I was able to get this to work though as soon and I added that library. It took a while, I would guess about 2 min, but worked. See attached .csv in .zip. This can be plotted by:
1. Select Line in plot type drop down from Marks card
2. Drag Line ID to Detail shelf
3. Drag PlotOrder to Path
4. Deselect Analysis > Aggregate Measures
5. Double click Latitude
6. Double click Longitude
And this is definitely going to be much faster in 64 bit.
I've written up some instructions that should make this more clear, I just want to run them by some people before posting them. Some reasons I can think of off hand it might have failed:
1. If using a Windows machine, make sure the path uses / and not \. Windows paths are odd.
2. Make sure that the file name does not have .shp at the end
The exact code I used to run this:
directory <- "C:/Users/msolbrig/Desktop/Map Sources/Seattlestreetnetwork"
name <- "Seattlestreetnetwork"
endName <- "Output"
If this doesn't work, if you could send any error messages that appeared in R then I'll see if I can figure out what the issue is. Also, is this a Linux machine? I don't think it should work differently on Linux, except the formatting of the path.
Output.zip 6.1 MB