# File lib/geo_ruby/shp4r/shp.rb, line 64
      def self.create(file,shp_type,fields,&proc)
        file_root = file.gsub(/.shp$/i,"")
        shx_io = File.open(file_root + ".shx","wb")
        shp_io = File.open(file_root + ".shp","wb")
        dbf_io = File.open(file_root + ".dbf","wb")
        str = [9994,0,0,0,0,0,50,1000,shp_type,0,0,0,0,0,0,0,0].pack("N7V2E8")
        shp_io << str
        shx_io << str
        rec_length = 1 + fields.inject(0) {|s,f| s + f.length} #+1 for the prefixed space (active record marker)

        dbf_io << [3,107,7,7,0,33 + 32 * fields.length,rec_length ].pack("c4Vv2x20") #32 bytes for first part of header

        fields.each do |field|
          dbf_io << [field.name,field.type,field.length,field.decimal].pack("a10xax4CCx14")
        end
        dbf_io << ['0d'].pack("H2")
        
        shx_io.close
        shp_io.close
        dbf_io.close

        open(file,&proc)

      end