Skip to content

Commit

Permalink
Only strip file extension when it is '.shp'
Browse files Browse the repository at this point in the history
  • Loading branch information
fawick committed Nov 21, 2017
1 parent 047bdb8 commit 215a578
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
)

// Writer is the type that is used to write a new shapefile.
Expand Down Expand Up @@ -37,13 +38,17 @@ type writeSeekCloser interface {
// This also creates a corresponding SHX file. It is important to use Close()
// when done because that method writes all the headers for each file (SHP, SHX
// and DBF).
// If filename does not end on ".shp" already, it will be treated as the basename
// for the file and the ".shp" extension will be appended to that name.
func Create(filename string, t ShapeType) (*Writer, error) {
filename = filename[0 : len(filename)-3]
shp, err := os.Create(filename + "shp")
if strings.HasSuffix(strings.ToLower(filename), ".shp") {
filename = filename[0 : len(filename)-4]
}
shp, err := os.Create(filename + ".shp")
if err != nil {
return nil, err
}
shx, err := os.Create(filename + "shx")
shx, err := os.Create(filename + ".shx")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 215a578

Please sign in to comment.