result = getNHDReachcodeAndMeasureForGageSourceFea(context.config, args.gageid) if result: reachcode = result[0] measure = result[1] else: reachcode = measure = "Gage not found" result = getLocationForStreamGageByGageSourceFea(context.config, args.gageid) if result: gage_lat = result[1] gage_lon = result[0] else: gage_lat = gage_lon = "Gage not found" # Write gage coordinates to a shapefile in the project directory shpFilename = writeCoordinatePairsToPointShapefile(context.projectDir, "gage", "gage_id", [args.gageid], [(gage_lon, gage_lat)]) # Write study area metadata GenericMetadata.writeStudyAreaEntry(context, 'gage_id_attr', 'gage_id') GenericMetadata.writeStudyAreaEntry(context, 'gage_id', args.gageid) GenericMetadata.writeStudyAreaEntry(context, 'nhd_gage_reachcode', reachcode) GenericMetadata.writeStudyAreaEntry(context, 'nhd_gage_measure_pct', measure) GenericMetadata.writeStudyAreaEntry(context, 'gage_lat_wgs84', gage_lat) GenericMetadata.writeStudyAreaEntry(context, 'gage_lon_wgs84', gage_lon) # Write provenance asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION) asset.name = 'gage' asset.dcIdentifier = shpFilename asset.dcSource = 'http://www.horizon-systems.com/NHDPlus/NHDPlusV2_home.php' asset.dcTitle = 'Streamflow gage'
sys.stdout.write('Importing streamflow gage...') sys.stdout.flush() gageIDs = [args.idValue] coords = getCoordinatesOfPointsFromShapefile(inGagePath, args.layerName, args.idAttribute, gageIDs) gage_lon = coords[0][0] gage_lat = coords[0][1] coordinates = (gage_lon, gage_lat) # Ensure gage coordinates are within bounding box if not isCoordinatePairInBoundingBox(bbox, coordinates): sys.exit("Gage coordinates %s, %s do not appear to lie within bounding box %s, %s, %s, %s" % ( str(gage_lon), str(gage_lat), str(bbox['minX']), str(bbox['minY']), str(bbox['maxX']), str(bbox['maxY']) ) ) shpFilename = writeCoordinatePairsToPointShapefile(context.projectDir, outfile, "gage_id", gageIDs, [coordinates]) sys.stdout.write('done\n') # Write metadata GenericMetadata.writeStudyAreaEntry(context, 'gage_id_attr', 'gage_id') GenericMetadata.writeStudyAreaEntry(context, 'gage_id', args.idValue) GenericMetadata.writeStudyAreaEntry(context, 'gage_lat_wgs84', gage_lat) GenericMetadata.writeStudyAreaEntry(context, 'gage_lon_wgs84', gage_lon) # Write provenance asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION) asset.name = 'gage' asset.dcIdentifier = shpFilename asset.dcSource = "file://%s" % (inGagePath,) asset.dcTitle = 'Streamflow gage'
sys.stdout.flush() (response, source) = locateStreamflowGage(context.config, args.gageid) if response['message'] != RESPONSE_OK: sys.exit("Failed to get gage identifiers/location for gage '%s', webservice response: %s" % \ (args.gageid, response['message']) ) else: reachcode = response['reachcode'] measure = response['measure'] gage_lat = response['gage_lat'] gage_lon = response['gage_lon'] sys.stdout.write('done\n') # Write gage coordinates to a shapefile in the project directory shpFilename = writeCoordinatePairsToPointShapefile(context.projectDir, "gage", "gage_id", [args.gageid], [(gage_lon, gage_lat)]) # Write study area metadata GenericMetadata.writeStudyAreaEntry(context, 'gage_id_attr', 'gage_id') GenericMetadata.writeStudyAreaEntry(context, 'gage_id', args.gageid) GenericMetadata.writeStudyAreaEntry(context, 'nhd_gage_reachcode', reachcode) GenericMetadata.writeStudyAreaEntry(context, 'nhd_gage_measure_pct', measure) GenericMetadata.writeStudyAreaEntry(context, 'gage_lat_wgs84', gage_lat) GenericMetadata.writeStudyAreaEntry(context, 'gage_lon_wgs84', gage_lon) # Write provenance asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION) asset.name = 'gage' asset.dcIdentifier = shpFilename asset.dcSource = source
gageIDs = [args.idValue] coords = getCoordinatesOfPointsFromShapefile(inGagePath, args.layerName, args.idAttribute, gageIDs) gage_lon = coords[0][0] gage_lat = coords[0][1] coordinates = (gage_lon, gage_lat) # Ensure gage coordinates are within bounding box if not isCoordinatePairInBoundingBox(bbox, coordinates): sys.exit( "Gage coordinates %s, %s do not appear to lie within bounding box %s, %s, %s, %s" % (str(gage_lon), str(gage_lat), str(bbox['minX']), str( bbox['minY']), str(bbox['maxX']), str(bbox['maxY']))) shpFilename = writeCoordinatePairsToPointShapefile(context.projectDir, outfile, "gage_id", gageIDs, [coordinates]) sys.stdout.write('done\n') # Write metadata GenericMetadata.writeStudyAreaEntry(context, 'gage_id_attr', 'gage_id') GenericMetadata.writeStudyAreaEntry(context, 'gage_id', args.idValue) GenericMetadata.writeStudyAreaEntry(context, 'gage_lat_wgs84', gage_lat) GenericMetadata.writeStudyAreaEntry(context, 'gage_lon_wgs84', gage_lon) # Write provenance asset = AssetProvenance(GenericMetadata.MANIFEST_SECTION) asset.name = 'gage' asset.dcIdentifier = shpFilename asset.dcSource = "file://%s" % (inGagePath, )
from ecohydrolib.spatialdata.utils import writeCoordinatePairsToPointShapefile out = "/Users/miles/Dropbox/EarthCube-Multilayered/RHESSys-workflow/scratchspace" layer = "DR5_gage" idAttr = "gage_id" coords = [ (-76.7443397486, 39.2955590994) ] ids = [ '01589312' ] writeCoordinatePairsToPointShapefile(out, layer, idAttr, ids, coords)
from ecohydrolib.spatialdata.utils import writeCoordinatePairsToPointShapefile out = "/Users/miles/Dropbox/EarthCube-Multilayered/RHESSys-workflow/scratchspace" layer = "DR5_gage" idAttr = "gage_id" coords = [(-76.7443397486, 39.2955590994)] ids = ['01589312'] writeCoordinatePairsToPointShapefile(out, layer, idAttr, ids, coords)