I am working on the project where we are giving the user to upload GIS layers and it should not be duplicate. what I got to know that user can upload same file multiple time just rename these file (map.dbf map.prj map.shp map.shx).
So I want to know, there is any way that I can know the layer name by extracting the data from any one of file.
I tried to extract the data from .shp file but I got only attribute not actual layer name.
package main
import (
"log"
"os"
"github.com/jonas-p/go-shp"
)
func main() {
// Create a log file
logFile, err := os.OpenFile("shapefile.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer logFile.Close()
// Set the output of the logger to the log file
log.SetOutput(logFile)
// Open a shapefile for reading
shapeReader, err := shp.Open("map.shp")
if err != nil {
log.Fatal(err)
}
defer shapeReader.Close()
// Loop through all features in the shapefile
for i := 0; shapeReader.Next(); i++ {
// Print all fields for each feature
for k, f := range shapeReader.Fields() {
val := shapeReader.ReadAttribute(i, k)
log.Printf("%v: %v\n", f, val)
}
}
}
ShapeFiles don't have a name other than the name of the file. I suspect that you need to keep track of layer names and add a new suffix to the layer name if they upload the file a second time.
To be honest, you'll face the same issue no matter what data format you use as users often add a table twice.