2

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

1 Answer 1

4

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
1
  • That works! It's odd though. I could swear it was giving me errors when I had it that way before.
    – Mr_Chimp
    Commented Jan 17, 2012 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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