Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUpClass(cls):
cls.indicator = Indicator()
cls.indicator.load_config(r'C:\Users\jeff8977\Desktop\SOTD\config_no_urls.ini')
cls.indicator.set_grid_sdf()
cls.indicator.set_features()
cls.indicator.gis_conn = GIS(
'http://www.arcgis.com/home',
'test',
'test'
)
def test_poac(self):
res = self.indicator.run_poac('ZI001_SDP')
self.assertIsInstance(res[0], SpatialDataFrame)
self.assertIsInstance(res[1], str)
def test_curr(self):
res = self.indicator.run_curr('ZI001_SDV')
self.assertIsInstance(res[0], SpatialDataFrame)
self.assertEqual(res[1][0]['success'], True)
def test_count(self):
states = ArcGIS("http://tigerweb.geo.census.gov/arcgis/rest/services/Basemaps/CommunityTIGER/MapServer")
count = states.get(28, count_only=True)
self.assertEqual(count, 56)
count = states.get(28, where="NAME = 'Florida'", count_only=True)
# Only one Florida.
self.assertEqual(count, 1)
def test_field_filter(self):
districts = ArcGIS("http://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Congressional_Districts/FeatureServer")
# How many fields are there in the layer?
num_fields = districts.enumerate_layer_fields(0)
self.assertEqual(len(num_fields), 12)
# We should only have one property, OBJECTID.
features = districts.get(0, where="STATE_ABBR = 'IN'", fields=['OBJECTID'])
self.assertEqual(len(features.get('features')[0].get('properties')), 1)
def test_multiple(self):
districts = ArcGIS("http://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/Legislative/MapServer")
# Gets 114th and 113th congressional districts for hawaii.
features = districts.getMultiple([0, 12], where="STATE = 15")
self.assertEqual(len(features.get('features')), 4)
def test_features(self):
districts = ArcGIS("http://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Congressional_Districts/FeatureServer")
features = districts.get(0, "STATE_ABBR = 'IN'")
# Make sure we have all of the actual congressional
# district shapes for Indiana.
self.assertEqual(len(features.get('features')), 9)
# Make sure they're polygons
self.assertEqual(features.get('features')[0].get('geometry').get('type'), "Polygon")
# Make sure it's valid json when we dump it
self.assertTrue(features == json.loads(json.dumps(features)))
# Make sure a value that should be there is ther.
self.assertEqual(features.get('features')[0].get('properties').get('STATE_ABBR'), 'IN')
def main(configuration_file):
try:
with open(configuration_file) as configfile:
cfg = json.load(configfile)
gis = GIS(cfg['organization url'], cfg['username'], cfg['password'])
# Get general id settings
global id_settings
id_settings = {}
for option in cfg['id sequences']:
id_settings[option['name']] = {'interval': int(option['interval']),
'next value': int(option['next value']),
'pattern': option['pattern']}
# Get general moderation settings
global modlists
modlists = {}
subs = cfg['moderation settings']['substitutions']
for modlist in cfg['moderation settings']['lists']:
words = [str(word).upper().strip() for word in modlist['words'].split(',')]
modlists[modlist['filter name']] = build_expression(words, modlist['filter type'], subs)
else:
print("Spatial reference not defined")
raise Exception("Spatial reference not defined")
# get problem types
prob_types = get_problem_types()
if prob_types == "error":
if log_to_file:
log.write("Problem types not defined\n")
else:
print("Problem types not defined")
raise Exception("Problem types not defined")
for layer in layers:
lyr = FeatureLayer(layer, gis=gis)
oid_fld = lyr.properties.objectIdField
lyrname = lyr.properties["name"]
# Get related table URL
reltable = ""
for relate in lyr.properties.relationships:
url_pieces = layer.split("/")
url_pieces[-1] = str(relate["relatedTableId"])
table_url = "/".join(url_pieces)
if table_url in tables:
reltable = table_url
break
# query reports
sql = "{}='{}'".format(fc_flag, flag_values[0])
def temporal_accuracy(c_features, curr_url, output_workspace, output_features, years, curr_gis):
import zipfile
import arcpy
fl = FeatureLayer(url=curr_url, gis=curr_gis)
item = curr_gis.content.get(fl.properties.serviceItemId)
export_item = item.export(export_format='File Geodatabase', title='CURRENCY')
result = export_item.download(save_path=output_workspace)
folder = os.path.dirname(result)
with zipfile.ZipFile(result, "r") as zip_ref:
zip_ref.extractall(folder)
gdbs = []
for file in zip_ref.namelist():
gdbs.append(os.path.split(file)[0])