で vs に for places, still confused

「図書館で勉強します」uses で but 「図書館に行きます」uses に. both are about 図書館 so why different particle? also saw で used for バス (バスで学校に行きます) so is で also about "method" separately from location?
Post
沐學 Mizuru