Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a shapefile British Columbia with postal codes. The attribute table gives the codes with no spaces, eg V6P2A8. I am trying to join a csv file by postal code (the key I am using). My csv file has postal codes with a consistent space, eg V6P 2A8. Naturally the join doesn't work because of that space. How can I either remove the space? Thanks Stephen

share|improve this question
1  
QGIS supports regexp_replace hub.qgis.org/wiki/quantum-gis/… stackoverflow.com/questions/16225848/… –  Mapperz Jul 16 '13 at 19:25
    
+1 for regex! Absolutely unbelievable what you can do with them. Should be easy to write a script that does the same for ArcMap... –  Paul Jul 16 '13 at 22:01

1 Answer 1

This is easy to remedy using Python. If you are in ArcGIS, you can simply use Python in a field calculator to strip the space from the field.

The code would look something like:

!post_code!.strip(" ")

which will remove the space in the postal code field. You can also do this in raw Python, but you would have to read in your csv file, make the change, and write a new one.

Alternatively, you could open your csv in Excel and use the Substitute function to replace the space with nothing. For example, to strip the space from a postal code in column A1, you would type =SUBSTITUTE(A1," ", "") in the output field. Then, just replace the original post code column with the new one.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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