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 am making a MapInfo program in MapBasic. I am calling OGR2OGR in order to convert some files. To do this I am generating a batch file and then running it. My code looks something like this:

RunStr = "OGR2OGR -f ""ESRI Shapefile"" """ & ExportFolder & "SHP\"" """ & TableFileName & """ -overwrite -skiperrors"
SHPMaker = ExportFolder & "SHPMaker.bat"

Open File SHPMaker
  For Output
  Access Write
  As #1
Print #1, RunStr
Close File #1

Run Program SHPMaker

My problem is that ExportFolder and TableFileName can potentially include spaces. My questions is how should I go about escaping spaces? I have tried both adding carets (^) before the spaces and putting double quotes around the paths -neither works.

The error I am getting is "Unable to open datasource 'GIS' with the following drivers", followed by a list of available drivers. Obviously it is picking up the "GIS" part from mid-way through the paths and treating it as the data source as you can see below.

The generated BAT file looks something like this:

OGR2OGR -f "ESRI Shapefile" "S:\000 GIS Files\TEST WORKSPACE 2\convert test\Converted\SHP\" "S:\000 GIS Files\TEST WORKSPACE\SiteForm.TAB" -overwrite -skiperrors
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

I wonder if it's because the output.shp hasn't been constructed properly?

Check to see that the output is formatted fully - ie; ends in output.shp

Try changing:

OGR2OGR -f "ESRI Shapefile" "S:\000 GIS Files\TEST WORKSPACE 2\convert test\Converted\SHP\" "S:\000 GIS Files\TEST WORKSPACE\SiteForm.TAB" -overwrite -skiperrors

to...

OGR2OGR -f "ESRI Shapefile" "S:\000 GIS Files\TEST WORKSPACE 2\convert test\Converted\SHP\output.shp" "S:\000 GIS Files\TEST WORKSPACE\SiteForm.TAB" -overwrite -skiperrors
share|improve this answer
    
That works! It's odd though. I could swear it was giving me errors when I had it that way before. –  Mr_Chimp Jan 17 '12 at 9:47
add comment

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.