-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from GeographicaGS/dev_raul_managing
Dev raul managing
- Loading branch information
Showing
133 changed files
with
6,476 additions
and
575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ venv/ | |
api/model/base/PostgreSQL/config.py | ||
tempimages/ | ||
images/ | ||
www/cdn/tmp/ | ||
www/src/node_modules/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## API usage | ||
|
||
- Create virtual environment: | ||
``` | ||
$ pip install virtualenv | ||
$ cd projectname/api | ||
$ virtualenv venv | ||
$ . venv/bin/activate | ||
$ pip install requirements.txt | ||
$ deactivate | ||
``` | ||
|
||
- Run API: | ||
``` | ||
$ . venv/bin/activate | ||
$ python run.py | ||
``` | ||
|
||
- Exit from virtual environment: | ||
``` | ||
$ deactivate | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
from flask import Flask, jsonify | ||
|
||
app = Flask(__name__) | ||
import os | ||
tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates') | ||
|
||
app = Flask(__name__, template_folder=tmpl_dir) | ||
|
||
import config | ||
import trans | ||
import home | ||
import proxy | ||
|
||
@app.route('/', methods = ['GET']) | ||
@app.route('/', methods = ['GET']) | ||
def alive(): | ||
return jsonify( { "status" : "running"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from geoserver.catalog import Catalog | ||
|
||
|
||
|
||
class GeoserverLayers(object): | ||
|
||
def __init__(self, gs_apirest, username, password): | ||
try: | ||
self.__catalog = Catalog(gs_apirest, username=username, password=password) | ||
|
||
except Exception as err: | ||
print("Geoserver API Rest Error: {0}".format(err)) | ||
|
||
def __createSldStyle(self, sldpath, stylename, ovwrt=False): | ||
try: | ||
styles_list = [st.name for st in self.__catalog.get_styles()] | ||
if ovwrt or not stylename in styles_list: | ||
with open(sldpath) as f: | ||
self.__catalog.create_style(stylename, f.read(), overwrite=ovwrt) | ||
else: | ||
print("This style already exists...") | ||
|
||
except Exception as err: | ||
print("Geoserver API Rest Error creating new style: {0}".format(err)) | ||
|
||
def __rmvResources(self, rsrc): | ||
""" | ||
Removing resources | ||
""" | ||
self.__catalog.delete(rsrc) | ||
self.__catalog.reload() | ||
|
||
def rmvStyle(self, stylename): | ||
""" | ||
Remove style | ||
""" | ||
try: | ||
|
||
style = self.__catalog.get_style(stylename) | ||
self.__rmvResources(style) | ||
|
||
except Exception as err: | ||
print("Geoserver API Rest Error removing style: {0}".format(err)) | ||
|
||
def rmvDataStore(self, ds_store): | ||
""" | ||
Remove DataStore (with his layer) | ||
""" | ||
try: | ||
|
||
lay_rm = self.__catalog.get_layer(ds_store) | ||
self.__rmvResources(lay_rm) | ||
|
||
str_rm = self.__catalog.get_store(ds_store) | ||
self.__rmvResources(str_rm) | ||
|
||
except Exception as err: | ||
print("Geoserver API Rest Error removing data store: {0}".format(err)) | ||
|
||
def createGeoserverWMSLayer(self, data, ws_name, ds_name, stylename, sldpath, debug=False): | ||
""" | ||
Create Geoserver WMS layer | ||
Status codes: | ||
2 : "Geoserver layer successfully created" | ||
-1 : "Workspace does not exist" | ||
-2 : "Datastore already exists" | ||
-3 : "Error creating Geoserver layer" | ||
-4 : "File missing" | ||
""" | ||
try: | ||
|
||
if not self.__catalog.get_workspace(ws_name): | ||
print("Workspace does not exist") | ||
return -1 | ||
|
||
ds_list = [i.name for i in self.__catalog.get_stores()] | ||
if ds_name in ds_list: | ||
print("Datastore already exists") | ||
return -2 | ||
|
||
ds = self.__catalog.create_datastore(ds_name, ws_name) | ||
ft = self.__catalog.create_featurestore(ds_name, workspace=ws_name,data=data) | ||
|
||
print("Geoserver layer successfully created...") | ||
|
||
self.__createSldStyle(sldpath, stylename) | ||
lyr = self.__catalog.get_layer(ds_name) | ||
lyr.enabled = True | ||
lyr.default_style = stylename | ||
self.__catalog.save(lyr) | ||
|
||
if debug: | ||
rsrc = self.__catalog.get_resource(ds_name, workspace=ws_name) | ||
print("Data Store XML: {}".format(rsrc.href)) | ||
|
||
return 2 | ||
|
||
except Exception as err: | ||
print("Geoserver API Rest Error creating new layer: {0}".format(err)) | ||
return -3 |
Oops, something went wrong.