2

I am having a trouble of encoding at writing shapefile by maptools (0.8-34) of R by MacOSX and reading that by ArcMap 10.2.1 in Windows 8.1 through parallels desktop. Using an original shapefile, I wrote an edited file by writeLinesShape as follows:

library(maptools)
original <- readShapeLines("original.shp") 
writeLinesShape(original, "edit.shp")

After this, I try to read "edit.shp" with ArcMap but cannot read Japanese strings properly in "dbf" file, which I could read in the original file. (Of course I did some edit before writing "edit.shp" but I have the trouble even in this simplest code.)

The original shapefile seems utf-8 because

iconv(original$japanese,from='utf-8',to='shift_jis')

worked in R. Also, I tried the following suspecting that ArcGIS can read shift_jis or cp932,

iconv(original$japanese,from='utf-8',to='shift_jis')

and

iconv(original$japanese,from='utf-8',to='cp932')

before writing the file, but Japanese strings were not shown properly in ArcMAP again.

Is there any way to solve this problem? I suspect that maptools is not writing utf-8 file because ArcMap is able to read utf-8.

migrated from stackoverflow.com Apr 22 '15 at 12:45

This question came from our site for professional and enthusiast programmers.

  • @Pascal is probably correct that this is a gis question. If it saves you migrating/asking a new question try writeOGR in the rgdal library. Instructions: inside-r.org/packages/cran/rgdal/docs/writeOGR – Phil Apr 22 '15 at 9:47
  • @Pascal Thanks! I will migrate. @Phil I also try the library to read the file, but I had an error while reading, so I want to stick to maptools. – user3467565 Apr 22 '15 at 9:56
  • Hi again. Can you provide the shapefiles so we can test them? Thanks – Phil Apr 22 '15 at 13:53
  • Thank you for taking your time. Could you download it from my dropbox link? – user3467565 Apr 22 '15 at 14:45
  • Ok, this isn't an answer (yet), but I've been able to load your uploaded shp file in to R with maptools, export it again with maptools, and load it in to QGIS with Japanese characters intact. This suggests it might be a problem with ArcGis. I will look tomorrow on my Windows system with ArcGIS. – Phil Apr 23 '15 at 15:08
1

I have been able to replicate your problem using the provided shapefile (original).

I've opened original.shp in R using both maptools and rgdal and have successfully plotted it. I've also been able to open this unedited file in QGIS 2.8 and ArcMap 10.1. In all cases the Japanese characters in the attribute table displayed correctly.

However, when I edited the shapefile using edit <- writeLinesShape(original, "edit.shp") with maptools I received the following error message when trying to load the edited file in to ArcMap 10:

screen capture of error message

The file plots, but the attribute table no longer displays the Japanese characters.

The writeLinesShape() doesn't have an encoding option, so I suggest this may be a bug with the maptools package that you might want to raise.

In the meantime can you remove the characters to see if the writeLinesShape() file opens in ArcMap?

  • Thank you so much for your replication. Yes, I might want to raise a bug of writeLinesShape. About your suggestion, what does "remove the characters" mean exactly? Do you mean that I should remove string data in original dbf and write out a new shapefile by writeLinesShape() to check if we can open the new file by ArcMap? – user3467565 Apr 28 '15 at 16:34
  • Erm, I'll be honest I'd try taking the Japanese characters out to see if a Latin characterset works. Clearly not ideal, but it might get it working. – Phil Apr 28 '15 at 19:42
  • Sorry for late reply. I tried to write the file by removing columns using Japanese, but I had the same error message as yours when I read it by ArcMap. Of course, I could read the attribute table in ArcMap without any problem since there is no Japanese in the table, but the information written in Japanese is crucially important for my work, so I have to find a way to handle Japanese characters somehow. – user3467565 May 3 '15 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.