Publish Your GIS Data(Vector Data) to PostGIS and Geoserver

Go Report Card GitHub license GitHub issues Coverage Status Build Status Documentation GitHub forks GitHub stars Twitter

GISManager

Publish Your GIS Data(Vector Data) to PostGIS and Geoserver

  • How to install:
    • go get -v github.com/hishamkaram/gismanager
  • Usage:
    • testdata folder content:
      ./testdata/
      ├── neighborhood_names_gis.geojson
      ├── nested
      │   └── nyc_wi-fi_hotspot_locations.geojson
      ├── sample.gpkg
      
    • create ManagerConfig instance:
      manager:= gismanager.ManagerConfig{
        Geoserver: gismanager.GeoserverConfig{WorkspaceName: "golang", Username: "admin", Password: "geoserver", ServerURL: "http://localhost:8080/geoserver"},
        Datastore: gismanager.DatastoreConfig{Host: "localhost", Port: 5432, DBName: "gis", DBUser: "golang", DBPass: "golang", Name: "gismanager_data"},
        Source:    gismanager.SourceConfig{Path: "./testdata"},
        logger:    gismanager.GetLogger(),
      }
      
    • get Supported GIS Files:
      files, _ := gismanager.GetGISFiles(manager.Source.Path)
      for _, file := range files {
        fmt.Println(file)
      }
      
      • output:
        <full_path>/testdata/neighborhood_names_gis.geojson
        <full_path>/testdata/nested/nyc_wi-fi_hotspot_locations.geojson
        <full_path>/testdata/sample.gpkg
        
    • read files and get layers Schema:
        for _, file := range files {
          source, ok := manager.OpenSource(file, 0)
          if ok {
            for index := 0; index < source.LayerCount(); index++ {
              layer := source.LayerByIndex(index)
              gLayer := gismanager.GdalLayer{
                Layer: &layer,
              }
              fmt.Println(layer.Name())
              for _, f := range gLayer.GetLayerSchema() {
                fmt.Printf("\n%+v\n", *f)
              }
            }
          }
        }
      
      • output sample:
        neighborhood_names_gis
        
        {Name:geom Type:POINT}
        
        {Name:stacked Type:String}
        
        {Name:name Type:String}
        
        {Name:annoline1 Type:String}
        
        {Name:annoline3 Type:String}
        
        {Name:objectid Type:String}
        
        {Name:annoangle Type:String}
        
        {Name:annoline2 Type:String}
        
        {Name:borough Type:String}
        ...
        
    • add your gis data to your database:
        for _, file := range files {
            source, ok := manager.OpenSource(file, 0)
            targetSource, targetOK := manager.OpenSource(manager.Datastore.BuildConnectionString(), 1)
            if ok && targetOK {
              for index := 0; index < source.LayerCount(); index++ {
                layer := source.LayerByIndex(index)
                gLayer := gismanager.GdalLayer{
                  Layer: &layer,
                }
                newLayer, postgisErr := gLayer.LayerToPostgis(targetSource, manager, true)
                if postgisErr != nil {
                  panic(postgisErr)
                }
                logger.Infof("Layer: %s added to you database", newLayer.Name())
              }
            }
        }
      
      • output:
        INFO[14-10-2018 17:28:37] Layer: neighborhood_names_gis added to you database 
        INFO[14-10-2018 17:28:38] Layer: nyc_wi_fi_hotspot_locations added to you database 
        INFO[14-10-2018 17:28:38] Layer: hwy_patrol added to you database
        
    • update the previous code to publish your postgis layers to geoserver
       for _, file := range files {
         source, ok := manager.OpenSource(file, 0)
         targetSource, targetOK := manager.OpenSource(manager.Datastore.BuildConnectionString(), 1)
         if ok && targetOK {
           for index := 0; index < source.LayerCount(); index++ {
             layer := source.LayerByIndex(index)
             gLayer := gismanager.GdalLayer{
               Layer: &layer,
             }
             if newLayer, postgisErr := gLayer.LayerToPostgis(targetSource, manager, true); newLayer.Layer != nil || postgisErr != nil {
               ok, pubErr := manager.PublishGeoserverLayer(newLayer)
               if pubErr != nil {
                 logger.Error(pubErr)
               }
               if !ok {
                 logger.Error("Failed to Publish")
               } else {
                 logger.Info("published")
               }
             }
      
           }
         }
       }
      
      • output:
       INFO[14-10-2018 17:37:07] url:http://localhost:8080/geoserver/rest/workspaces/golang  Status=404  
       ERRO[14-10-2018 17:37:07] No such workspace: 'golang' found            
       INFO[14-10-2018 17:37:07] url:http://localhost:8080/geoserver/rest/workspaces  Status=201  
       INFO[14-10-2018 17:37:07] url:http://localhost:8080/geoserver/rest/workspaces/golang/datastores/gis?quietOnNotFound=true  Status=404  
       INFO[14-10-2018 17:37:07] url:http://localhost:8080/geoserver/rest/workspaces/golang/datastores  Status=201  
       ERRO[14-10-2018 17:37:07] {"featureType":{"name":"neighborhood_names_gis","nativeName":"neighborhood_names_gis"}} 
       INFO[14-10-2018 17:37:07] url:http://localhost:8080/geoserver/rest/workspaces/golang/datastores/gis/featuretypes  Status=201  
       INFO[14-10-2018 17:37:07] published                                    
       INFO[14-10-2018 17:37:08] url:http://localhost:8080/geoserver/rest/workspaces/golang  Status=200  
       INFO[14-10-2018 17:37:08] url:http://localhost:8080/geoserver/rest/workspaces/golang/datastores/gis?quietOnNotFound=true  Status=200  
       ERRO[14-10-2018 17:37:08] {"featureType":{"name":"nyc_wi_fi_hotspot_locations","nativeName":"nyc_wi_fi_hotspot_locations"}} 
       INFO[14-10-2018 17:37:08] url:http://localhost:8080/geoserver/rest/workspaces/golang/datastores/gis/featuretypes  Status=201  
       INFO[14-10-2018 17:37:08] published                                    
       INFO[14-10-2018 17:37:08] url:http://localhost:8080/geoserver/rest/workspaces/golang  Status=200  
       INFO[14-10-2018 17:37:08] url:http://localhost:8080/geoserver/rest/workspaces/golang/datastores/gis?quietOnNotFound=true  Status=200  
       ERRO[14-10-2018 17:37:08] {"featureType":{"name":"hwy_patrol","nativeName":"hwy_patrol"}} 
       INFO[14-10-2018 17:37:08] url:http://localhost:8080/geoserver/rest/workspaces/golang/datastores/gis/featuretypes  Status=201  
       INFO[14-10-2018 17:37:08] published 
      
      • done check you geoserver or via geoserver rest api url http://localhost:8080/geoserver/rest/layers.json :
         {
           "layers": {
             "layer": [..., {
               "name": "golang:hwy_patrol",
               "href": "http:\/\/localhost:8080\/geoserver\/rest\/layers\/golang%3Ahwy_patrol.json"
             }, {
               "name": "golang:neighborhood_names_gis",
               "href": "http:\/\/localhost:8080\/geoserver\/rest\/layers\/golang%3Aneighborhood_names_gis.json"
             }, {
               "name": "golang:nyc_wi_fi_hotspot_locations",
               "href": "http:\/\/localhost:8080\/geoserver\/rest\/layers\/golang%3Anyc_wi_fi_hotspot_locations.json"
             }]
           }
         }
        

Todo:

  • backup postgis as geopackage
Owner
Hisham waleed karam
A highly focused software developer. Organised, methodical and a keen eye for detail results in solid coding and trustworthy software programmes.
Hisham waleed karam
Similar Resources

A repository for plotting and visualizing data

Gonum Plot gonum/plot is the new, official fork of code.google.com/p/plotinum. It provides an API for building and drawing plots in Go. Note that this

Dec 27, 2022

An API which allows you to upload an image and responds with the same image, stripped of EXIF data

strip-metadata This is an API which allows you to upload an image and responds with the same image, stripped of EXIF data. How to run You need to have

Nov 25, 2021

Decode embedded EXIF meta data from image files.

goexif Provides decoding of basic exif and tiff encoded data. Still in alpha - no guarantees. Suggestions and pull requests are welcome. Functionality

Dec 17, 2022

Efficient moving window for high-speed data processing.

Moving Window Data Structure Copyright (c) 2012. Jake Brukhman. ([email protected]). All rights reserved. See the LICENSE file for BSD-style license. I

Sep 4, 2022

Super fast static photo and video gallery generator (written in Go and HTML/CSS/native JS)

fastgallery Fast static photo and video gallery generator Super fast (written in Go and C, concurrent, uses fastest image/video libraries, 4-8 times f

Dec 4, 2022

Go bindings for audio capture and playback with ALSA and libasound

Go ALSA bindings These bindings allow capture and playback of audio via ALSA using the alsa-lib library. Installation go get github.com/cocoonlife/goa

Nov 26, 2022

This is old and unmaintained code, ignore it. starfish is a simple, SDL based, 2D graphics and user input library for Go. If you intend to work on it, please fork from the 'devel' branch, not 'master'. Current release: 0.12.0

What is starfish? What starfish is: starfish is a simple 2D graphics and user input library for Go built on SDL. What starfish is not: While it is bui

Jun 4, 2019

darkroom - An image proxy with changeable storage backends and image processing engines with focus on speed and resiliency.

darkroom - An image proxy with changeable storage backends and image processing engines with focus on speed and resiliency.

Darkroom - Yet Another Image Proxy Introduction Darkroom combines the storage backend and the image processor and acts as an Image Proxy on your image

Dec 6, 2022

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Package captcha ⚠️ Warning: this captcha can be broken by advanced OCR captcha breaking algorithms. import "github.com/dchest/captcha" Package captch

Dec 30, 2022
Comments
  • Compile Issues

    Compile Issues

    go get -v github.com/hishamkaram/gismanager

    ../../../../pkg/mod/github.com/hishamkaram/[email protected]/layer.go:131:29: cannot use index (type int) as type int64 in argument to layer.Layer.Feature ../../../../pkg/mod/github.com/hishamkaram/[email protected]/utils.go:104:20: invalid method expression archiver.Zip.Open (needs pointer receiver: (*archiver.Zip).Open)

    go version go version go1.17.1 darwin/amd64

    Thanks, Migael

Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.
Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

rasterx Rasterx is a golang rasterizer that implements path stroking functions capable of SVG 2.0 compliant 'arc' joins and explicit loop closing. Pat

Nov 1, 2022
Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.
Cairo in Go: vector to SVG, PDF, EPS, raster, HTML Canvas, etc.

Canvas is a common vector drawing target that can output SVG, PDF, EPS, raster images (PNG, JPG, GIF, ...), HTML Canvas through WASM, and OpenGL. It h

Dec 25, 2022
A Go package converting a monochrome 1-bit bitmap image into a set of vector paths.
A Go package converting a monochrome 1-bit bitmap image into a set of vector paths.

go-bmppath Overview Package bmppath converts a monochrome 1-bit bitmap image into a set of vector paths. Note that this package is by no means a sophi

Mar 22, 2022
:football: Generate your own O'RLY animal book cover to troll your colleagues | 生成你自己的O'RLY动物书封面,让你的同事惊掉下巴

English | 中文 O'RLY Cover Generator O'RLY Cover Generator is a parody book cover generator, implemented in Golang and Vue.js, supporting a wide range o

Dec 24, 2022
📸 Clean your image folder using perceptual hashing and BK-trees using Go!
📸 Clean your image folder using perceptual hashing and BK-trees using Go!

Image Cleaner ?? ?? ➡ ?? This tool can take your image gallery and create a new folder with image-alike-cluster folders. It uses a perceptual image ha

Oct 8, 2022
A function tracer to boost your debugging

tgo: a function tracer to boost your debugging Examples In this example, the functions called between tracer.Start() and tracer.Stop() are traced. pac

Jan 8, 2022
Generate a TwitterCard(OGP) image for your Hugo posts.
Generate a TwitterCard(OGP) image for your Hugo posts.

Twitter Card Image Generator Generate Twitter card (OGP) images for your blog posts. Supported front-matters are title, author, categories, tags, and

Dec 17, 2022
🛰️ Clone all your starred GitHub repos

solar ??️ Clone all your starred GitHub repos solar ❓ What is solar? ?? Install ?? macOS ??️ Linux and Windows ?? Commands ??️ solar download ?? Contr

Dec 23, 2022
Radius parsing in golang using gopacket. You can parse from either live traffic or from pcap of your choice.

go-radius Radius parsing in golang using gopacket. You can parse from either live traffic or from pcap of your choice. RADIUS RADIUS is an AAA (authen

Dec 1, 2022
General purpose library for reading, writing and working with OpenStreetMap data

osm This package is a general purpose library for reading, writing and working with OpenStreetMap data in Go (golang). It has the ability to read OSM

Dec 30, 2022