コード例 #1
0
# $Id: network_centrality.py 118 2010-04-26 04:33:39Z bbest $

import sys, os, time, tempfile, csv, cm, networkx as NX

# Running script network_centrality...
# <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'getframe'
# Failed to execute (Network Centrality Metrics).
# E:\Ryman\scratch\cm_net01\network_trunc_lc.txt

# setup geoprocessor
GP = cm.gp_init()

# G: = \\nicknet.env.duke.edu\network\research\lel\GraphGroup
# G:\chapel_hill\network\full_lc\network_lc.txt
# easy_install -U networkx # got networkx-0.35.1
# E:\code\connmod\branches\ch\data\net2010\network_euc_na.txt

# get arguments
in_network_txt = sys.argv[1]

# initialize logging
log = '%s/log_centrality.txt' % os.path.dirname(in_network_txt)
cm.log_init(log)

cm.log('Reading network configuration')
F = cm.read_network(in_network_txt)  # read in full network
nodes_shp = F.config[('shapefile', 'nodes')]
lcpaths_txt = F.config[('leastcostpaths', 'txt')]
G = NX.Graph()  # create fresh graph

cm.log('Reading least-cost paths into fresh graph with only centroids')
コード例 #2
0
# expecting non-zero integer Patch ID field
#
# TODO:
#  # z tolerance and artifacts?
#  * grow corridors out from paths using rstr_costdist.  see corridor arcgis fxn.
#  * handle patches ID field already using PatchID.' % patches_idfld
#  * tweak edge weights

# C:\temp\connectivity\GoC_connectivity.gdb\portfolio_era54 POTAFOLIO C:\temp\connectivity\tin\costdist_tin # C:\temp\connectivity\GoC_connectivity.gdb\nodes C:\temp\connectivity\GoC_connectivity.gdb\edges C:\temp\connectivity\network\network.txt
# C:\temp\connectivity\cost\cost C:\temp\connectivity\GoC_connectivity.gdb\portfolio_era54 PortfolioID # C:\temp\connectivity\network_cost

import sys, os, time, tempfile, string, shutil, cm, traceback
import networkx as NX

# setup geoprocessor
GP = cm.gp_init(9.3)

# arguments
rstr_cost     = sys.argv[1]
patches_in    = sys.argv[2]  # poly_height = habitat quality?
patches_idfld = sys.argv[3]  # problem: if patches_idfld in nodes fields when doing intersect, join
                             # TODO: so far using numeric.  Limit to LONG,OBJECTID or allow any numeric and TEXT?
z_tolerance   = sys.argv[4]
wd            = sys.argv[5]

# paths
gdb           = '%s/geodb.gdb' % wd
patches       = '%s/patches' % gdb
rstr_costdist = '%s/costdist' % wd
rstr_costdist1= '%s/costdist1' % wd
poly_costdist1= '%s/costdist1' % gdb