Skip to content

Instantly share code, notes, and snippets.

@bengolder
Created October 18, 2011 15:35
Show Gist options
  • Save bengolder/1295730 to your computer and use it in GitHub Desktop.
Save bengolder/1295730 to your computer and use it in GitHub Desktop.
getSiteJson example
import postsites
# select a folder to load data from and create a dict for db stuff
my_data_folder = 'C:/tampaGIS'
dbinfo = {'user':'postgres', 'dbname':'postgis', 'password':'postgrespass'}
### If you haven't yet made a config XLS file, execute this block:
f = postsites.makeXlsConfigurationFile(my_data_folder)
# it looks like loadFromXlsConfigurationFile returns a tuple, of the datasource
# and then the results, so you can catch both separately
ds, results = postsites.loadFromXlsConfigurationFile( f, dbinfo )
################################################
### getting the site Json - You can do this from a fresh python session
### a separate script, after doing other thigns and turning off your computer
import postsites
dbinfo = {'user':'postgres', 'dbname':'postgis', 'password':'postgrespass'}
ds = postsites.DataSource(dbinfo)
# in a layer dictionary, the 'name' attribute is what you want to call the
# imported layer and does not depend on the database. the key before the name (in
# the case below where it says 'parcels' for example) is the name of the layer in
# the database. You can also designate which columns ('cols') you would like to import
# attribute data from.
myLayerDict = {
'parcels':{'name':'sites', 'cols':[
'ogc_fid',
'area',
'assess_code']},
'rivers':{'name':'rivers', 'cols':[
'river_name',
'depth',
'number_of_floating_plastic_bags']},
}
print ds.viewLayers() # calls the database and lists all the layers in it.
# https://github.com/localcode/postsites/blob/master/__init__.py#L302
print ds.config
print ds.config.layers
# ds has a ConfigurationInfo object that can be used to
# configure layers
ds.loadLayerDict(myLayerDict)
# loadLayerdict will user your dictionary to edit ds.config
print ds.config.layers
print ds.config.siteLayer
ds.config.setSiteLayer('sites')
ds.config.siteRadius = 400
mysiteJson = ds.getSiteJson(id=203)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment